Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2016-05-11 19:30:39 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-05-11 19:30:39 +0300
commit5ebba786d50077365b55c193df2d570bf5498b6e (patch)
tree61caef5bb43b6171405649f9fe88a09edcd26341 /lib
parentd144dfcb3622761f661a9a2628ef8f07f6bf5f87 (diff)
On duplicate torrent add, don't emit 'infoHash'
Private 'infoHash' event allows client.add to check for duplicate torrents and destroy them before the normal 'infoHash' event is emitted. Prevents user applications from needing to deal with duplicate 'infoHash' events.
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index a765ef8..2e082b9 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -253,8 +253,14 @@ Torrent.prototype._onParsedTorrent = function (parsedTorrent) {
}, RECHOKE_INTERVAL)
if (self._rechokeIntervalId.unref) self._rechokeIntervalId.unref()
+ // Private 'infoHash' event allows client.add to check for duplicate torrents and
+ // destroy them before the normal 'infoHash' event is emitted. Prevents user
+ // applications from needing to deal with duplicate 'infoHash' events.
+ self.emit('_infoHash', self.infoHash)
+ if (self.destroyed) return
+
self.emit('infoHash', self.infoHash)
- if (self.destroyed) return // user might destroy torrent in `infoHash` event handler
+ if (self.destroyed) return // user might destroy torrent in event handler
if (self.client.listening) {
self._onListening()