*Wrap connection event in an init call event to survive the relay being recreated

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

View File

@ -80,7 +80,8 @@ 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", () => {
swarmInstance.on("connection", (peer: any) => {
const socketId = getSocketId(); const socketId = getSocketId();
connections.set(socketId, { swarm: id, conn: peer }); connections.set(socketId, { swarm: id, conn: peer });
@ -88,6 +89,7 @@ async function createSwarm(): Promise<number> {
connections.delete(socketId); connections.delete(socketId);
}); });
}); });
});
return id; return id;
} }
@ -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));
}; };