diff --git a/lib/client/websocket-tracker.js b/lib/client/websocket-tracker.js index 0cd4fdf..6481aa0 100644 --- a/lib/client/websocket-tracker.js +++ b/lib/client/websocket-tracker.js @@ -45,21 +45,26 @@ WebSocketTracker.prototype.announce = function (opts) { return self.socket.once('connect', self.announce.bind(self, opts)) } - // Limit the number of offers that are generated, since it can be slow - var numwant = Math.min(opts.numwant, 10) - - self._generateOffers(numwant, function (offers) { - var params = extend(opts, { - action: 'announce', - numwant: numwant, - info_hash: self.client._infoHashBinary, - peer_id: self.client._peerIdBinary, - offers: offers - }) - if (self._trackerId) params.trackerid = self._trackerId - - self._send(params) + var params = extend(opts, { + action: 'announce', + info_hash: self.client._infoHashBinary, + peer_id: self.client._peerIdBinary }) + if (self._trackerId) params.trackerid = self._trackerId + + if (opts.event === 'stopped') { + // Don't include offers with 'stopped' event + self._send(params) + } else { + // Limit the number of offers that are generated, since it can be slow + var numwant = Math.min(opts.numwant, 10) + + self._generateOffers(numwant, function (offers) { + params.numwant = numwant + params.offers = offers + self._send(params) + }) + } } WebSocketTracker.prototype.scrape = function (opts) { @@ -337,6 +342,7 @@ WebSocketTracker.prototype._generateOffers = function (numwant, cb) { for (var i = 0; i < numwant; ++i) { generateOffer() } + checkDone() function generateOffer () { var offerId = hat(160)