This commit is contained in:
raven 2023-01-12 20:24:24 -05:00
parent 41959d0962
commit 7ed15be770
2 changed files with 3 additions and 3 deletions

0
node Normal file
View File

View File

@ -35,13 +35,13 @@ function sleep(ms) {
function addUser(user, peerId) { function addUser(user, peerId) {
connectedUsers.push({ name: user, peerId: peerId }); connectedUsers.push({ name: user, peerId: peerId });
sidebarBox.setContent(connectedUsers.map(user => `${user.name} - ${user.peerId}`).join("\n")); sidebarBox.setContent(connectedUsers.map(user => `${user.peerId}`).join("\n"));
screen.render(); screen.render();
} }
function removeUser(peerId) { function removeUser(peerId) {
connectedUsers = connectedUsers.filter(user => user.peerId !== peerId); connectedUsers = connectedUsers.filter(user => user.peerId !== peerId);
sidebarBox.setContent("Connected Peers: \n" + connectedUsers.map(user => `${user.name} - ${user.peerId}`).join("\n")); sidebarBox.setContent("Peers since connection: \n" + connectedUsers.map(user => `${user.peerId}`).join("\n"));
screen.render(); screen.render();
} }
@ -218,7 +218,7 @@ swarm.on('connection', conn => {
const name = b4a.toString(conn.remotePublicKey, 'hex') const name = b4a.toString(conn.remotePublicKey, 'hex')
console.log(`* got a connection from ${name} (${USERNAME[0]}) *`) console.log(`* got a connection from ${name} (${USERNAME[0]}) *`)
addUser(USERNAME[0], name) addUser(USERNAME[0], name)
sidebarBox.setLabel("Connected Peers: " + connectedUsers.length) sidebarBox.setLabel("Peers since connection: " + connectedUsers.length)
screen.render() screen.render()
conns.push(conn) conns.push(conn)
conn.once('close', () => conns.splice(conns.indexOf(conn), 1)) conn.once('close', () => conns.splice(conns.indexOf(conn), 1))