fixing the peer removal on chat only sesssions

This commit is contained in:
raven 2023-01-11 01:31:27 -05:00
parent 8a13dd8e07
commit da9f17117a
1 changed files with 9 additions and 8 deletions

View File

@ -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}`)
}