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

Commit 836dcf3

Browse files
authored
fix: emit peer:connect events from mock connection manager (#399)
Updates mock to behave similarly to the actual connection manager.
1 parent 283e81c commit 836dcf3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/interface-mocks/src/connection-manager.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ class MockConnectionManager implements ConnectionManager, Startable {
140140
}
141141
}
142142

143+
this.components.events.safeDispatchEvent('peer:connect', { detail: componentsB.peerId })
144+
143145
componentsB.events.safeDispatchEvent('connection:open', {
144146
detail: bToA
145147
})
@@ -150,6 +152,8 @@ class MockConnectionManager implements ConnectionManager, Startable {
150152
}
151153
}
152154

155+
componentsB.events.safeDispatchEvent('peer:connect', { detail: this.components.peerId })
156+
153157
return aToB
154158
}
155159

@@ -178,7 +182,15 @@ class MockConnectionManager implements ConnectionManager, Startable {
178182

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

185+
if (this.connections.filter(c => !c.remotePeer.equals(peerId)).length === 0) {
186+
componentsB.events.safeDispatchEvent('peer:disconnect', { detail: peerId })
187+
}
188+
181189
await componentsB.connectionManager?.closeConnections(this.components.peerId)
190+
191+
if (componentsB.connectionManager?.getConnectionsMap().get(this.components.peerId) == null) {
192+
componentsB.events.safeDispatchEvent('peer:disconnect', { detail: this.components.peerId })
193+
}
182194
}
183195

184196
async acceptIncomingConnection (): Promise<boolean> {

0 commit comments

Comments
 (0)