Add err handlers to swarm connections (#70)

This commit is contained in:
HDegroote
2024-02-23 12:02:21 +01:00
committed by GitHub
parent 8f60cde71d
commit adfe9fc51b
3 changed files with 3 additions and 0 deletions

View File

@@ -203,6 +203,7 @@ swarm.on('connection', (peer) => {
// name incoming peers after first 6 chars of its public key as hex
const name = b4a.toString(peer.remotePublicKey, 'hex').substr(0, 6)
peer.on('data', message => onMessageAdded(name, message))
peer.on('error', e => console.log(`Connection error: ${e}`))
})
// When there's updates to the swarm, update the peers count

View File

@@ -41,6 +41,7 @@ swarm.on('connection', peer => {
const name = b4a.toString(peer.remotePublicKey, 'hex').substr(0, 6)
console.log(`[info] New peer joined, ${name}`)
peer.on('data', message => appendMessage({ name, message }))
peer.on('error', e => console.log(`Connection error: ${e}`))
})
swarm.on('update', () => {
console.log(`[info] Number of connections is now ${swarm.connections.size}`)

View File

@@ -37,6 +37,7 @@ swarm.on('connection', conn => {
conns.push(conn)
conn.once('close', () => conns.splice(conns.indexOf(conn), 1))
conn.on('data', data => console.log(`${name}: ${data}`))
conn.on('error', e => console.log(`Connection error: ${e}`))
})
// Broadcast stdin to all connections