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
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2016-04-21 09:35:25 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-04-21 09:35:25 +0300
commite311e0b7cb26437118e565674bffdfc0723492f7 (patch)
tree02196cf99d5317e74877c0193913d6fe7add73b4 /index.js
parent6085dc79c577ceab5f9f5f305748af5a7d5b33e7 (diff)
fix duplicate client.add handling and re-enable test
Diffstat (limited to 'index.js')
-rw-r--r--index.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/index.js b/index.js
index dc6bedf..f5adda3 100644
--- a/index.js
+++ b/index.js
@@ -208,6 +208,16 @@ WebTorrent.prototype.add = function (torrentId, opts, ontorrent) {
var torrent = new Torrent(torrentId, self, opts)
self.torrents.push(torrent)
+ torrent.once('infoHash', function () {
+ for (var i = 0, len = self.torrents.length; i < len; i++) {
+ var t = self.torrents[i]
+ if (t.infoHash === torrent.infoHash && t !== torrent) {
+ torrent.removeListener('ready', onReady)
+ torrent._destroy(new Error('Cannot add duplicate torrent ' + torrent.infoHash))
+ return
+ }
+ }
+ })
torrent.once('ready', onReady)
function onReady () {