diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-04-21 09:35:25 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-04-21 09:35:25 +0300 |
commit | e311e0b7cb26437118e565674bffdfc0723492f7 (patch) | |
tree | 02196cf99d5317e74877c0193913d6fe7add73b4 /index.js | |
parent | 6085dc79c577ceab5f9f5f305748af5a7d5b33e7 (diff) |
fix duplicate client.add handling and re-enable test
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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 () { |