From e56cbecbcf6641ea12059868829b9428a3c327c2 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 22 Jul 2023 09:53:02 -0400 Subject: [PATCH] feat: add socketListeners api call --- src/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/index.ts b/src/index.ts index d03e2b5..aff3b50 100644 --- a/src/index.ts +++ b/src/index.ts @@ -79,6 +79,7 @@ addHandler("socketExists", handleSocketExists); addHandler("socketListenEvent", handleSocketListenEvent, { receiveUpdates: true, }); +addHandler("socketListeners", handleSocketListenersEvent); addHandler("socketWrite", handleWriteSocketEvent); addHandler("socketClose", handleCloseSocketEvent); addHandler("createProtomuxChannel", handleCreateProtomuxChannel, { @@ -191,6 +192,18 @@ function handleSocketListenEvent(aq: ActiveQuery) { conn.listeners.add(aq.domain); } +async function handleSocketListenersEvent(aq: ActiveQuery) { + const socket = validateConnection(aq); + + if (!socket) { + return; + } + + const conn = connections.get(aq.callerInput.id) as SwarmConnection; + + aq.respond([...conn.listeners.values()]); +} + async function handleSocketExists(aq: ActiveQuery) { const { id = null } = aq.callerInput;