fix: if websocket closed, don't produce a response

This commit is contained in:
Diego Rodríguez Baquero 2021-07-21 20:07:06 -05:00
parent 4699cc2da7
commit ca88435617
No known key found for this signature in database
GPG Key ID: 57828AD77A819E32
3 changed files with 4 additions and 3 deletions

View File

@ -42,6 +42,7 @@ class Swarm {
self._onAnnounceStarted(params, peer, id)
} else if (params.event === 'stopped') {
self._onAnnounceStopped(params, peer, id)
if (!cb) return // when websocket is closed
} else if (params.event === 'completed') {
self._onAnnounceCompleted(params, peer, id)
} else if (params.event === 'update') {

View File

@ -588,7 +588,7 @@ class Server extends EventEmitter {
event: 'stopped',
numwant: 0,
peer_id: socket.peerId
}, noop)
})
}
})
}

View File

@ -14,10 +14,10 @@ function testRequestHandler (t, serverType) {
class Swarm extends Server.Swarm {
announce (params, cb) {
super.announce(params, (err, response) => {
if (err) return cb(response)
if (cb && err) return cb(response)
response.complete = 246
response.extraData = 'hi'
cb(null, response)
if (cb) cb(null, response)
})
}
}