Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
fix: emit peer:connect events from mock connection manager (#399)
Browse files Browse the repository at this point in the history
Updates mock to behave similarly to the actual connection manager.
  • Loading branch information
achingbrain committed May 10, 2023
1 parent 283e81c commit 836dcf3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/interface-mocks/src/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class MockConnectionManager implements ConnectionManager, Startable {
}
}

this.components.events.safeDispatchEvent('peer:connect', { detail: componentsB.peerId })

componentsB.events.safeDispatchEvent('connection:open', {
detail: bToA
})
Expand All @@ -150,6 +152,8 @@ class MockConnectionManager implements ConnectionManager, Startable {
}
}

componentsB.events.safeDispatchEvent('peer:connect', { detail: this.components.peerId })

return aToB
}

Expand Down Expand Up @@ -178,7 +182,15 @@ class MockConnectionManager implements ConnectionManager, Startable {

this.connections = this.connections.filter(c => !c.remotePeer.equals(peerId))

if (this.connections.filter(c => !c.remotePeer.equals(peerId)).length === 0) {
componentsB.events.safeDispatchEvent('peer:disconnect', { detail: peerId })
}

await componentsB.connectionManager?.closeConnections(this.components.peerId)

if (componentsB.connectionManager?.getConnectionsMap().get(this.components.peerId) == null) {
componentsB.events.safeDispatchEvent('peer:disconnect', { detail: this.components.peerId })
}
}

async acceptIncomingConnection (): Promise<boolean> {
Expand Down

0 comments on commit 836dcf3

Please sign in to comment.