mirror of
https://github.com/aljazceru/pear-docs.git
synced 2025-12-18 06:54:22 +01:00
Add err handlers to swarm connections (#70)
This commit is contained in:
@@ -203,6 +203,7 @@ swarm.on('connection', (peer) => {
|
|||||||
// name incoming peers after first 6 chars of its public key as hex
|
// name incoming peers after first 6 chars of its public key as hex
|
||||||
const name = b4a.toString(peer.remotePublicKey, 'hex').substr(0, 6)
|
const name = b4a.toString(peer.remotePublicKey, 'hex').substr(0, 6)
|
||||||
peer.on('data', message => onMessageAdded(name, message))
|
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
|
// When there's updates to the swarm, update the peers count
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ swarm.on('connection', peer => {
|
|||||||
const name = b4a.toString(peer.remotePublicKey, 'hex').substr(0, 6)
|
const name = b4a.toString(peer.remotePublicKey, 'hex').substr(0, 6)
|
||||||
console.log(`[info] New peer joined, ${name}`)
|
console.log(`[info] New peer joined, ${name}`)
|
||||||
peer.on('data', message => appendMessage({ name, message }))
|
peer.on('data', message => appendMessage({ name, message }))
|
||||||
|
peer.on('error', e => console.log(`Connection error: ${e}`))
|
||||||
})
|
})
|
||||||
swarm.on('update', () => {
|
swarm.on('update', () => {
|
||||||
console.log(`[info] Number of connections is now ${swarm.connections.size}`)
|
console.log(`[info] Number of connections is now ${swarm.connections.size}`)
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ swarm.on('connection', conn => {
|
|||||||
conns.push(conn)
|
conns.push(conn)
|
||||||
conn.once('close', () => conns.splice(conns.indexOf(conn), 1))
|
conn.once('close', () => conns.splice(conns.indexOf(conn), 1))
|
||||||
conn.on('data', data => console.log(`${name}: ${data}`))
|
conn.on('data', data => console.log(`${name}: ${data}`))
|
||||||
|
conn.on('error', e => console.log(`Connection error: ${e}`))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Broadcast stdin to all connections
|
// Broadcast stdin to all connections
|
||||||
|
|||||||
Reference in New Issue
Block a user