From c0b99e8146d546a49cbedbad20efd12a6526f62b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 4 Apr 2023 08:07:02 -0400 Subject: [PATCH] *When listening for connections, send over any existing connections to the requester as if they are new --- src/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index dcfcaa5..35263e6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -332,14 +332,13 @@ async function handleReady(aq: ActiveQuery) { } async function handleListenConnections(aq: ActiveQuery) { const swarm = await getSwarm(aq); + const swarmId = getSwarmToSwarmId(swarm); const listener = (peer: any) => { aq.sendUpdate(getSwarmToSocketConnectionId(peer)); }; - const swarmEvent = swarmEvents.get( - getSwarmToSwarmId(swarm) as number - )?.events; + const swarmEvent = swarmEvents.get(swarmId as number)?.events; if (!swarmEvent) { logErr("swarm event object is missing"); @@ -367,6 +366,12 @@ async function handleListenConnections(aq: ActiveQuery) { return; } swarm.onceSelf("ready", hookClose); + + for (const conn of connections) { + if (conn[1].swarm === swarmId) { + listener(conn[1].conn); + } + } } async function handleGetSocketInfo(aq: ActiveQuery) {