From b923ae71a5d1977486e576b907f4f5d2847c1055 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Mon, 14 Mar 2016 11:30:22 +0100 Subject: [PATCH 1/3] add default webrtc trackers when there is webrtc support and global.WEBTORRENT_ANNOUNCE is not defined fix #672 --- lib/torrent.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/torrent.js b/lib/torrent.js index 51b005c8..3c498656 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -30,6 +30,8 @@ var Swarm = require('bittorrent-swarm') var uniq = require('uniq') var ut_metadata = require('ut_metadata') var ut_pex = require('ut_pex') // browser exclude +var Peer = require('simple-peer') +var createTorrent = require('create-torrent') var File = require('./file') var RarityMap = require('./rarity-map') @@ -50,6 +52,16 @@ var TMP = typeof pathExists.sync === 'function' ? path.join(pathExists.sync('/tmp') ? '/tmp' : os.tmpDir(), 'webtorrent') : '/tmp/webtorrent' +if (Peer.WEBRTC_SUPPORT && !global.WEBTORRENT_ANNOUNCE) { + global.WEBTORRENT_ANNOUNCE = createTorrent.announceList + .map(function (arr) { + return arr[0] + }) + .filter(function (url) { + return url.indexOf('wss://') === 0 || url.indexOf('ws://') === 0 + }) +} + inherits(Torrent, EventEmitter) /** From d98414904816b93539b604f695a0c7103c9263b3 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Mon, 14 Mar 2016 11:45:04 +0100 Subject: [PATCH 2/3] fix tests : remove the trackers when testing the magnetURI in the browser --- test/client-add.js | 6 +++--- test/client-seed.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/client-add.js b/test/client-add.js index d30fea00..f10ad9ec 100644 --- a/test/client-add.js +++ b/test/client-add.js @@ -16,7 +16,7 @@ test('client.add: magnet uri, utf-8 string', function (t) { torrent.on('infoHash', function () { t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI, fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) client.remove(fixtures.leaves.magnetURI, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) @@ -38,7 +38,7 @@ test('client.add: torrent file, buffer', function (t) { torrent.on('infoHash', function () { t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI, fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) client.remove(fixtures.leaves.torrent, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) @@ -104,7 +104,7 @@ test('client.add: parsed torrent, from `parse-torrent`', function (t) { torrent.on('infoHash', function () { t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI, fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) client.remove(fixtures.leaves.parsedTorrent, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) diff --git a/test/client-seed.js b/test/client-seed.js index 1f50d9b2..1625ff7b 100644 --- a/test/client-seed.js +++ b/test/client-seed.js @@ -17,7 +17,7 @@ test('client.seed: torrent file (Buffer)', function (t) { }, function (torrent) { t.equal(client.torrents.length, 1) t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI, fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) client.remove(torrent, function (err) { t.error(err, 'torrent removed') }) t.equal(client.torrents.length, 0) @@ -40,7 +40,7 @@ test('client.seed: torrent file (Buffer), set name on buffer', function (t) { client.seed(buf, function (torrent) { t.equal(client.torrents.length, 1) t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI, fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) client.remove(torrent, function (err) { t.error(err, 'torrent removed') }) t.equal(client.torrents.length, 0) @@ -64,7 +64,7 @@ test('client.seed: torrent file (Blob)', function (t) { }, function (torrent) { t.equal(client.torrents.length, 1) t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI, fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) client.remove(torrent, function (err) { t.error(err, 'torrent removed') }) t.equal(client.torrents.length, 0) From 7c44a43bf0d349f1b91a4d3122c544dbe31e228c Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Mon, 14 Mar 2016 11:48:10 +0100 Subject: [PATCH 3/3] make standard happy : "&tr" -> '&tr' --- test/client-add.js | 6 +++--- test/client-seed.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/client-add.js b/test/client-add.js index f10ad9ec..6a3c7475 100644 --- a/test/client-add.js +++ b/test/client-add.js @@ -16,7 +16,7 @@ test('client.add: magnet uri, utf-8 string', function (t) { torrent.on('infoHash', function () { t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split('&tr')[0], fixtures.leaves.magnetURI) client.remove(fixtures.leaves.magnetURI, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) @@ -38,7 +38,7 @@ test('client.add: torrent file, buffer', function (t) { torrent.on('infoHash', function () { t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split('&tr')[0], fixtures.leaves.magnetURI) client.remove(fixtures.leaves.torrent, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) @@ -104,7 +104,7 @@ test('client.add: parsed torrent, from `parse-torrent`', function (t) { torrent.on('infoHash', function () { t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split('&tr')[0], fixtures.leaves.magnetURI) client.remove(fixtures.leaves.parsedTorrent, function (err) { t.error(err, 'torrent destroyed') }) t.equal(client.torrents.length, 0) diff --git a/test/client-seed.js b/test/client-seed.js index 1625ff7b..516db6d2 100644 --- a/test/client-seed.js +++ b/test/client-seed.js @@ -17,7 +17,7 @@ test('client.seed: torrent file (Buffer)', function (t) { }, function (torrent) { t.equal(client.torrents.length, 1) t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split('&tr')[0], fixtures.leaves.magnetURI) client.remove(torrent, function (err) { t.error(err, 'torrent removed') }) t.equal(client.torrents.length, 0) @@ -40,7 +40,7 @@ test('client.seed: torrent file (Buffer), set name on buffer', function (t) { client.seed(buf, function (torrent) { t.equal(client.torrents.length, 1) t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split('&tr')[0], fixtures.leaves.magnetURI) client.remove(torrent, function (err) { t.error(err, 'torrent removed') }) t.equal(client.torrents.length, 0) @@ -64,7 +64,7 @@ test('client.seed: torrent file (Blob)', function (t) { }, function (torrent) { t.equal(client.torrents.length, 1) t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash) - t.equal(torrent.magnetURI.split("&tr")[0], fixtures.leaves.magnetURI) + t.equal(torrent.magnetURI.split('&tr')[0], fixtures.leaves.magnetURI) client.remove(torrent, function (err) { t.error(err, 'torrent removed') }) t.equal(client.torrents.length, 0)