From 836dcf3d0fbdd00686f662260940c5600db25c09 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 10 May 2023 08:27:51 +0100 Subject: [PATCH] fix: emit peer:connect events from mock connection manager (#399) Updates mock to behave similarly to the actual connection manager. --- packages/interface-mocks/src/connection-manager.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/interface-mocks/src/connection-manager.ts b/packages/interface-mocks/src/connection-manager.ts index e3e5b21d3..d91f0e738 100644 --- a/packages/interface-mocks/src/connection-manager.ts +++ b/packages/interface-mocks/src/connection-manager.ts @@ -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 }) @@ -150,6 +152,8 @@ class MockConnectionManager implements ConnectionManager, Startable { } } + componentsB.events.safeDispatchEvent('peer:connect', { detail: this.components.peerId }) + return aToB } @@ -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 {