forked from snxraven/sshChat-CLI
fixing the peer removal on chat only sesssions
This commit is contained in:
parent
8a13dd8e07
commit
da9f17117a
17
sshChat.mjs
17
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}`)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user