*Wrap connection event in an init call event to survive the relay being recreated
This commit is contained in:
parent
db079ce214
commit
2ad6b1fd5d
13
src/index.ts
13
src/index.ts
|
@ -80,12 +80,14 @@ async function createSwarm(): Promise<number> {
|
||||||
const id = getSwarmId();
|
const id = getSwarmId();
|
||||||
swarmInstances.set(id, swarmInstance);
|
swarmInstances.set(id, swarmInstance);
|
||||||
|
|
||||||
swarmInstance.on("connection", (peer) => {
|
swarmInstance.onSelf("init", () => {
|
||||||
const socketId = getSocketId();
|
swarmInstance.on("connection", (peer: any) => {
|
||||||
connections.set(socketId, { swarm: id, conn: peer });
|
const socketId = getSocketId();
|
||||||
|
connections.set(socketId, { swarm: id, conn: peer });
|
||||||
|
|
||||||
peer.on("close", () => {
|
peer.on("close", () => {
|
||||||
connections.delete(socketId);
|
connections.delete(socketId);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -308,6 +310,7 @@ async function handleListenConnections(aq: ActiveQuery) {
|
||||||
const swarm = await getSwarm(aq);
|
const swarm = await getSwarm(aq);
|
||||||
|
|
||||||
const listener = (peer: any) => {
|
const listener = (peer: any) => {
|
||||||
|
debugger;
|
||||||
aq.sendUpdate(getSwarmToSocketConnectionId(peer));
|
aq.sendUpdate(getSwarmToSocketConnectionId(peer));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue