Safely send disconnected peers

This commit is contained in:
Abdussamed 2024-04-05 10:57:16 +03:00
parent eeee824b20
commit 912f32e7ab
1 changed files with 7 additions and 1 deletions

View File

@ -2,7 +2,7 @@ const { Client } = require("../Client.js");
let {addService, addListener} = require("../WebSocket.js"); let {addService, addListener} = require("../WebSocket.js");
addListener('disconnect',(global, xclient)=>{ addListener('disconnect',(global, xclient)=>{
const {intersection} = xclient.getSucureClients(); const {intersection, pairs} = xclient.getSucureClients();
for (const [clientid, client] of intersection) for (const [clientid, client] of intersection)
{ {
client.send([ client.send([
@ -12,6 +12,12 @@ addListener('disconnect',(global, xclient)=>{
"peer/disconnect" "peer/disconnect"
]) ])
} }
for (const [id, peer] of pairs)
{
peer.pairs.delete(xclient.id);
xclient.pairs.delete(id);
}
}); });
addService(({ addService(({