*When listening for connections, send over any existing connections to the requester as if they are new

This commit is contained in:
Derrick Hammer 2023-04-04 08:07:02 -04:00
parent dd3d4948d4
commit c0b99e8146
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 3 deletions

View File

@ -332,14 +332,13 @@ async function handleReady(aq: ActiveQuery) {
} }
async function handleListenConnections(aq: ActiveQuery) { async function handleListenConnections(aq: ActiveQuery) {
const swarm = await getSwarm(aq); const swarm = await getSwarm(aq);
const swarmId = getSwarmToSwarmId(swarm);
const listener = (peer: any) => { const listener = (peer: any) => {
aq.sendUpdate(getSwarmToSocketConnectionId(peer)); aq.sendUpdate(getSwarmToSocketConnectionId(peer));
}; };
const swarmEvent = swarmEvents.get( const swarmEvent = swarmEvents.get(swarmId as number)?.events;
getSwarmToSwarmId(swarm) as number
)?.events;
if (!swarmEvent) { if (!swarmEvent) {
logErr("swarm event object is missing"); logErr("swarm event object is missing");
@ -367,6 +366,12 @@ async function handleListenConnections(aq: ActiveQuery) {
return; return;
} }
swarm.onceSelf("ready", hookClose); swarm.onceSelf("ready", hookClose);
for (const conn of connections) {
if (conn[1].swarm === swarmId) {
listener(conn[1].conn);
}
}
} }
async function handleGetSocketInfo(aq: ActiveQuery) { async function handleGetSocketInfo(aq: ActiveQuery) {