feat: track what modules are listening on a socket connection by their module id
This commit is contained in:
parent
9d2b64d510
commit
39a91144de
|
@ -24,6 +24,7 @@ interface SwarmConnection {
|
||||||
swarm: number;
|
swarm: number;
|
||||||
conn: any;
|
conn: any;
|
||||||
channels: Map<number, Protomux>;
|
channels: Map<number, Protomux>;
|
||||||
|
listeners: Set<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SwarmEvents {
|
interface SwarmEvents {
|
||||||
|
@ -122,6 +123,7 @@ async function createSwarm(): Promise<number> {
|
||||||
swarm: id,
|
swarm: id,
|
||||||
conn: peer,
|
conn: peer,
|
||||||
channels: new Map<number, Protomux>(),
|
channels: new Map<number, Protomux>(),
|
||||||
|
listeners: new Set<string>(),
|
||||||
});
|
});
|
||||||
|
|
||||||
peer.once("close", () => {
|
peer.once("close", () => {
|
||||||
|
@ -155,6 +157,8 @@ function handleSocketListenEvent(aq: ActiveQuery) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const conn = connections.get(aq.callerInput.id) as SwarmConnection;
|
||||||
|
|
||||||
let responded = false;
|
let responded = false;
|
||||||
const respond = () => {
|
const respond = () => {
|
||||||
if (responded) {
|
if (responded) {
|
||||||
|
@ -162,6 +166,7 @@ function handleSocketListenEvent(aq: ActiveQuery) {
|
||||||
}
|
}
|
||||||
|
|
||||||
responded = true;
|
responded = true;
|
||||||
|
conn.listeners.delete(aq.domain);
|
||||||
aq.respond();
|
aq.respond();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -182,6 +187,8 @@ function handleSocketListenEvent(aq: ActiveQuery) {
|
||||||
socket.off(event, cb);
|
socket.off(event, cb);
|
||||||
respond();
|
respond();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
conn.listeners.add(aq.domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSocketExists(aq: ActiveQuery) {
|
async function handleSocketExists(aq: ActiveQuery) {
|
||||||
|
|
Loading…
Reference in New Issue