From da9f17117aee10900acfce56974e56431aa8ad15 Mon Sep 17 00:00:00 2001 From: raven Date: Wed, 11 Jan 2023 01:31:27 -0500 Subject: [PATCH] fixing the peer removal on chat only sesssions --- sshChat.mjs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sshChat.mjs b/sshChat.mjs index ce53ff0..e36dc78 100644 --- a/sshChat.mjs +++ b/sshChat.mjs @@ -24,7 +24,7 @@ const swarm = new Hyperswarm() // } // }); // Keep track of all connections and USERNAMEs -const conns = [] +let conns = [] let USERPWD = "/" let DAPI_KEY = {} let USERNAME = "anon" + rand @@ -124,13 +124,14 @@ swarm.on('connection', conn => { if (data.toString().startsWith('CLOSED:')) { // Extract the key from the message string const key = data.toString().split(':')[1].trim(); - // Iterate through the conns array and remove the client with the matching key - for (let i = 0; i < conns.length; i++) { - if (conns[i].key === key) { - conns.splice(i, 1); - break; - } - } + console.log(`Removing peer ${key}`); + (async () => { + + await sleep(5000) + conns = conns.filter(c => c !== conn); + conn.destroy(); + })(); + } else { console.log(`${data}`) }