From 39a91144de1641ec17ba02888409009310aca67a Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 22 Jul 2023 09:49:31 -0400 Subject: [PATCH] feat: track what modules are listening on a socket connection by their module id --- src/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/index.ts b/src/index.ts index 564176d..d03e2b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,7 @@ interface SwarmConnection { swarm: number; conn: any; channels: Map; + listeners: Set; } interface SwarmEvents { @@ -122,6 +123,7 @@ async function createSwarm(): Promise { swarm: id, conn: peer, channels: new Map(), + listeners: new Set(), }); peer.once("close", () => { @@ -155,6 +157,8 @@ function handleSocketListenEvent(aq: ActiveQuery) { return; } + const conn = connections.get(aq.callerInput.id) as SwarmConnection; + let responded = false; const respond = () => { if (responded) { @@ -162,6 +166,7 @@ function handleSocketListenEvent(aq: ActiveQuery) { } responded = true; + conn.listeners.delete(aq.domain); aq.respond(); }; @@ -182,6 +187,8 @@ function handleSocketListenEvent(aq: ActiveQuery) { socket.off(event, cb); respond(); }); + + conn.listeners.add(aq.domain); } async function handleSocketExists(aq: ActiveQuery) {