mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-31 16:32:01 +00:00
fix: emit peer:connect after all (#1171)
**Motivation** In lodestar, when we handle "peer:connect" event, we dial the peer which gives another "peer:connect" event and it causes other issues **Motivation** In `onConnect` function, "peer:connect" event should be emitted after we add connection to the `connections` map so that when app dial the peer in "peer:connect" event handler, it uses the same/existing connection
This commit is contained in:
@@ -267,8 +267,6 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
||||
const peerIdStr = peerId.toString()
|
||||
const storedConns = this.connections.get(peerIdStr)
|
||||
|
||||
this.dispatchEvent(new CustomEvent<Connection>('peer:connect', { detail: connection }))
|
||||
|
||||
if (storedConns != null) {
|
||||
storedConns.push(connection)
|
||||
} else {
|
||||
@@ -284,6 +282,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
||||
}
|
||||
|
||||
await this._checkMaxLimit('maxConnections', this.getConnectionList().length)
|
||||
this.dispatchEvent(new CustomEvent<Connection>('peer:connect', { detail: connection }))
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user