diff --git a/lib/server/swarm.js b/lib/server/swarm.js index e1229c9..8194270 100644 --- a/lib/server/swarm.js +++ b/lib/server/swarm.js @@ -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') { diff --git a/server.js b/server.js index a72b339..3bdbea7 100644 --- a/server.js +++ b/server.js @@ -588,7 +588,7 @@ class Server extends EventEmitter { event: 'stopped', numwant: 0, peer_id: socket.peerId - }, noop) + }) } }) } diff --git a/test/request-handler.js b/test/request-handler.js index 7e5e967..b60f967 100644 --- a/test/request-handler.js +++ b/test/request-handler.js @@ -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) }) } }