Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tracker options into `opts.tracker` #793

Merged
merged 1 commit into from May 8, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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)
@@ -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
})

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.