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:
-rw-r--r--README.md12
-rw-r--r--index.js5
-rw-r--r--package.json1
-rw-r--r--test/browser/basic.js15
-rw-r--r--test/node/basic.js15
5 files changed, 47 insertions, 1 deletions
diff --git a/README.md b/README.md
index 1a6a09a..ebae51d 100644
--- a/README.md
+++ b/README.md
@@ -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.
diff --git a/index.js b/index.js
index 2281a91..6a7776a 100644
--- a/index.js
+++ b/index.js
@@ -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)