*If we have an active relay, add close hook, else queue on ready hook to add close hook
This commit is contained in:
parent
a84ea18680
commit
db079ce214
14
src/index.ts
14
src/index.ts
|
@ -318,11 +318,21 @@ async function handleListenConnections(aq: ActiveQuery) {
|
||||||
aq.respond();
|
aq.respond();
|
||||||
});
|
});
|
||||||
|
|
||||||
swarm.activeRelay.dht.once("close", () => {
|
const closeCb = () => {
|
||||||
swarm.off("connection", listener);
|
swarm.off("connection", listener);
|
||||||
swarm.emit("close");
|
swarm.emit("close");
|
||||||
aq.respond();
|
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) {
|
async function handleGetSocketInfo(aq: ActiveQuery) {
|
||||||
|
|
Loading…
Reference in New Issue