diff options
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | index.js | 5 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | test/browser/basic.js | 15 | ||||
-rw-r--r-- | test/node/basic.js | 15 |
5 files changed, 47 insertions, 1 deletions
@@ -220,6 +220,18 @@ In addition to magnet uris, webtorrent supports [many ways to specify a torrent] This API should work exactly the same in node and the browser. Open an issue if this is not the case. +#### `WebTorrent.WEBRTC_SUPPORT` + +Detect native WebRTC support in the environment. + +```js +if (WebTorrent.WEBRTC_SUPPORT) { + // webrtc support! +} else { + // fallback +} +``` + #### `client = new WebTorrent([opts])` Create a new `WebTorrent` instance. @@ -11,12 +11,13 @@ var loadIPSet = require('load-ip-set') // browser exclude var parallel = require('run-parallel') var parseTorrent = require('parse-torrent') var path = require('path') +var Peer = require('simple-peer') var speedometer = require('speedometer') var zeroFill = require('zero-fill') var Torrent = require('./lib/torrent') -inherits(WebTorrent, EventEmitter) +module.exports.WEBRTC_SUPPORT = Peer.WEBRTC_SUPPORT /** * WebTorrent version. @@ -40,6 +41,8 @@ var VERSION_STR = VERSION.match(/([0-9]+)/g).slice(0, 2).map(zeroFill(2)).join(' */ var VERSION_PREFIX = '-WW' + VERSION_STR + '-' +inherits(WebTorrent, EventEmitter) + /** * WebTorrent Client * @param {Object=} opts diff --git a/package.json b/package.json index 39d13b3..32c0337 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "re-emitter": "^1.0.0", "render-media": "^2.0.0", "run-parallel": "^1.0.0", + "simple-peer": "^5.11.6", "simple-sha1": "^2.0.0", "speedometer": "^1.0.0", "stream-to-blob-url": "^1.0.0", diff --git a/test/browser/basic.js b/test/browser/basic.js index 09889d7..c25f2f3 100644 --- a/test/browser/basic.js +++ b/test/browser/basic.js @@ -92,3 +92,18 @@ test('image render w/ element', function (t) { }) }) }) + +test('WebTorrent.WEBRTC_SUPPORT', function (t) { + t.plan(2) + + var client = new WebTorrent({ dht: false, tracker: false }) + + client.on('error', function (err) { t.fail(err) }) + client.on('warning', function (err) { t.fail(err) }) + + t.equal(WebTorrent.WEBRTC_SUPPORT, true) + + client.destroy(function (err) { + t.error(err, 'client destroyed') + }) +}) diff --git a/test/node/basic.js b/test/node/basic.js index b225b8d..6bee61c 100644 --- a/test/node/basic.js +++ b/test/node/basic.js @@ -3,6 +3,21 @@ var http = require('http') var test = require('tape') var WebTorrent = require('../../') +test('WebTorrent.WEBRTC_SUPPORT', function (t) { + t.plan(2) + + var client = new WebTorrent({ dht: false, tracker: false }) + + client.on('error', function (err) { t.fail(err) }) + client.on('warning', function (err) { t.fail(err) }) + + t.equal(WebTorrent.WEBRTC_SUPPORT, false) + + client.destroy(function (err) { + t.error(err, 'client destroyed') + }) +}) + test('client.add: http url to a torrent file, string', function (t) { t.plan(8) |