*If we have an active relay, add close hook, else queue on ready hook to add close hook

This commit is contained in:
Derrick Hammer 2023-02-17 19:16:22 -05:00
parent a84ea18680
commit db079ce214
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 12 additions and 2 deletions

View File

@ -318,11 +318,21 @@ async function handleListenConnections(aq: ActiveQuery) {
aq.respond();
});
swarm.activeRelay.dht.once("close", () => {
const closeCb = () => {
swarm.off("connection", listener);
swarm.emit("close");
aq.respond();
});
};
const hookClose = () => {
swarm.activeRelay.dht._protocol._stream.once("close", closeCb);
};
if (swarm.activeRelay) {
hookClose();
return;
}
swarm.once("ready", hookClose);
}
async function handleGetSocketInfo(aq: ActiveQuery) {