feat: add socketListeners api call

This commit is contained in:
Derrick Hammer 2023-07-22 09:53:02 -04:00
parent 39a91144de
commit e56cbecbcf
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 13 additions and 0 deletions

View File

@ -79,6 +79,7 @@ addHandler("socketExists", handleSocketExists);
addHandler("socketListenEvent", handleSocketListenEvent, { addHandler("socketListenEvent", handleSocketListenEvent, {
receiveUpdates: true, receiveUpdates: true,
}); });
addHandler("socketListeners", handleSocketListenersEvent);
addHandler("socketWrite", handleWriteSocketEvent); addHandler("socketWrite", handleWriteSocketEvent);
addHandler("socketClose", handleCloseSocketEvent); addHandler("socketClose", handleCloseSocketEvent);
addHandler("createProtomuxChannel", handleCreateProtomuxChannel, { addHandler("createProtomuxChannel", handleCreateProtomuxChannel, {
@ -191,6 +192,18 @@ function handleSocketListenEvent(aq: ActiveQuery) {
conn.listeners.add(aq.domain); 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) { async function handleSocketExists(aq: ActiveQuery) {
const { id = null } = aq.callerInput; const { id = null } = aq.callerInput;