diff options
-rw-r--r-- | docs/api.md | 18 | ||||
-rw-r--r-- | index.js | 19 | ||||
-rw-r--r-- | lib/torrent.js | 36 |
3 files changed, 49 insertions, 24 deletions
diff --git a/docs/api.md b/docs/api.md index a4ebe55..4750f02 100644 --- a/docs/api.md +++ b/docs/api.md @@ -51,16 +51,20 @@ If `opts` is specified, then the default options (shown below) will be overridde ```js { - dht: Boolean|Object, // Enable DHT (default=true), or options object for DHT - maxConns: Number, // Max number of connections per torrent (default=55) - nodeId: String|Buffer, // DHT protocol node ID (default=randomly generated) - peerId: String|Buffer, // Wire protocol peer ID (default=randomly generated) - rtcConfig: Object, // RTCPeerConnection configuration object (default=STUN only) - tracker: Boolean, // Whether or not to enable trackers (default=true) - wrtc: Object // Custom webrtc implementation (in node, specify the [wrtc](https://www.npmjs.com/package/wrtc) or [electron-webrtc](https://github.com/mappum/electron-webrtc) package) + dht: Boolean|Object, // Enable DHT (default=true), or options object for DHT + maxConns: Number, // Max number of connections per torrent (default=55) + nodeId: String|Buffer, // DHT protocol node ID (default=randomly generated) + peerId: String|Buffer, // Wire protocol peer ID (default=randomly generated) + tracker: Boolean|Object // Enable trackers (default=true), or options object for Tracker } ``` +For possible values of `opts.dht` see the +[`bittorrent-dht` documentation](https://github.com/feross/bittorrent-dht#dht--new-dhtopts). + +For possible values of `opts.tracker` see the +[`bittorrent-tracker` documentation](https://github.com/feross/bittorrent-tracker#client). + ## `client.add(torrentId, [opts], [function ontorrent (torrent) {}])` Start downloading a new torrent. @@ -68,12 +68,24 @@ function WebTorrent (opts) { self.listening = false self.torrentPort = opts.torrentPort || 0 self.dhtPort = opts.dhtPort || 0 - self.tracker = opts.tracker !== undefined ? opts.tracker : true + self.tracker = opts.tracker !== undefined ? opts.tracker : {} self.torrents = [] self.maxConns = Number(opts.maxConns) || 55 - self._rtcConfig = opts.rtcConfig - self._wrtc = opts.wrtc || global.WRTC // to support `webtorrent-hybrid` package + if (self.tracker) { + if (typeof self.tracker !== 'object') self.tracker = {} + if (opts.rtcConfig) { + // TODO: remove in v1 + console.warn('WebTorrent: opts.rtcConfig is deprecated. Use opts.tracker.rtcConfig instead') + self.tracker.rtcConfig = opts.rtcConfig + } + if (opts.wrtc) { + // TODO: remove in v1 + console.warn('WebTorrent: opts.wrtc is deprecated. Use opts.tracker.wrtc instead') + self.tracker.wrtc = opts.wrtc // to support `webtorrent-hybrid` package + } + if (!self.tracker.wrtc) self.tracker.wrtc = global.WRTC + } if (typeof TCPPool === 'function') { self._tcpPool = new TCPPool(self) @@ -197,6 +209,7 @@ WebTorrent.prototype.get = function (torrentId) { return null } +// TODO: remove in v1 WebTorrent.prototype.download = function (torrentId, opts, ontorrent) { console.warn('WebTorrent: client.download() is deprecated. Use client.add() instead') return this.add(torrentId, opts, ontorrent) diff --git a/lib/torrent.js b/lib/torrent.js index 810e10d..e29c38f 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -202,10 +202,10 @@ Object.defineProperty(Torrent.prototype, '_numConns', { } }) -// TODO: remove in v2 +// TODO: remove in v1 Object.defineProperty(Torrent.prototype, 'swarm', { get: function () { - console.log('WebTorrent: `torrent.swarm` is deprecated. Use `torrent` directly instead.') + console.warn('WebTorrent: `torrent.swarm` is deprecated. Use `torrent` directly instead.') return this } }) @@ -291,18 +291,26 @@ Torrent.prototype._processParsedTorrent = function (parsedTorrent) { Torrent.prototype._onListening = function () { var self = this if (self.discovery || self.destroyed) return - var trackerOpts = { - rtcConfig: self.client._rtcConfig, - wrtc: self.client._wrtc, - getAnnounceOpts: function () { - var opts = { - uploaded: self.uploaded, - downloaded: self.downloaded, - left: Math.max(self.length - self.downloaded, 0) + + var trackerOpts = self.client.tracker + if (trackerOpts) { + trackerOpts = extend(self.client.tracker, { + getAnnounceOpts: function () { + var opts = { + uploaded: self.uploaded, + downloaded: self.downloaded, + left: Math.max(self.length - self.downloaded, 0) + } + if (self.client.tracker.getAnnounceOpts) { + extendMutable(opts, self.client.tracker.getAnnounceOpts()) + } + if (self._getAnnounceOpts) { + // TODO: consider deprecating this, as it's redundant with the former case + extendMutable(opts, self._getAnnounceOpts()) + } + return opts } - if (self._getAnnounceOpts) opts = extend(opts, self._getAnnounceOpts()) - return opts - } + }) } // begin discovering peers via DHT and trackers @@ -311,7 +319,7 @@ Torrent.prototype._onListening = function () { announce: self.announce, peerId: self.client.peerId, dht: !self.private && self.client.dht, - tracker: self.client.tracker && trackerOpts, + tracker: trackerOpts, port: self.client.torrentPort }) |