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
|
// Keep track of all connections and USERNAMEs
|
||||||
const conns = []
|
let conns = []
|
||||||
let USERPWD = "/"
|
let USERPWD = "/"
|
||||||
let DAPI_KEY = {}
|
let DAPI_KEY = {}
|
||||||
let USERNAME = "anon" + rand
|
let USERNAME = "anon" + rand
|
||||||
@ -124,13 +124,14 @@ swarm.on('connection', conn => {
|
|||||||
if (data.toString().startsWith('CLOSED:')) {
|
if (data.toString().startsWith('CLOSED:')) {
|
||||||
// Extract the key from the message string
|
// Extract the key from the message string
|
||||||
const key = data.toString().split(':')[1].trim();
|
const key = data.toString().split(':')[1].trim();
|
||||||
// Iterate through the conns array and remove the client with the matching key
|
console.log(`Removing peer ${key}`);
|
||||||
for (let i = 0; i < conns.length; i++) {
|
(async () => {
|
||||||
if (conns[i].key === key) {
|
|
||||||
conns.splice(i, 1);
|
await sleep(5000)
|
||||||
break;
|
conns = conns.filter(c => c !== conn);
|
||||||
}
|
conn.destroy();
|
||||||
}
|
})();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log(`${data}`)
|
console.log(`${data}`)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user