Skip to content

Commit

Permalink
attach listeners in natural order
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Nov 1, 2023
1 parent b4473e7 commit 26eed0e
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -171,6 +171,25 @@ module.exports = class Hyperswarm extends EventEmitter {
this._clientConnections++
let opened = false

conn.on('open', () => {
opened = true
this._connectDone()
this.connections.add(conn)
conn.removeListener('error', noop)
peerInfo._connected()
peerInfo.client = true
this.emit('connection', conn, peerInfo)
this._flushMaybe(peerInfo)

this.emit('update')
})
conn.on('error', err => {
if (this.relayThrough && shouldForceRelaying(err.code)) {
peerInfo.forceRelaying = true
// Reset the attempts in order to fast connect to relay
peerInfo.attempts = 0
}
})
conn.on('close', () => {
if (!opened) this._connectDone()
this.connections.delete(conn)
@@ -187,25 +206,6 @@ module.exports = class Hyperswarm extends EventEmitter {

this.emit('update')
})
conn.on('error', err => {
if (this.relayThrough && shouldForceRelaying(err.code)) {
peerInfo.forceRelaying = true
// Reset the attempts in order to fast connect to relay
peerInfo.attempts = 0
}
})
conn.on('open', () => {
opened = true
this._connectDone()
this.connections.add(conn)
conn.removeListener('error', noop)
peerInfo._connected()
peerInfo.client = true
this.emit('connection', conn, peerInfo)
this._flushMaybe(peerInfo)

this.emit('update')
})

this.emit('update')
}

0 comments on commit 26eed0e

Please sign in to comment.