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:
authorFeross Aboukhadijeh <feross@feross.org>2015-04-11 20:00:20 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-04-11 20:00:20 +0300
commit633be9e8feb66960b1a4a6862e6fb744a639056b (patch)
tree8d4107875919b6e7bce285f0a1ccc6f3236e09bd /lib/torrent.js
parent09c09ff372832bc5710a8ad13e58422a140fc445 (diff)
support new bittorrent-swarm@2 usage
Diffstat (limited to 'lib/torrent.js')
-rw-r--r--lib/torrent.js21
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 2b21459..c7b4bb0 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -130,13 +130,10 @@ function Torrent (torrentId, opts) {
self.swarm.on('download', self.client.downloadSpeed.bind(self.client))
self.swarm.on('upload', self.client.uploadSpeed.bind(self.client))
- if (process.browser) {
- // in browser, swarm does not listen
- self._onSwarmListening()
- } else {
- // listen for peers
- self.swarm.listen(self.client.torrentPort, self._onSwarmListening.bind(self))
- }
+ // listen for peers (note: in the browser, this is a no-op and callback is called on
+ // next tick)
+ self.swarm.listen(self.client.torrentPort, self._onSwarmListening.bind(self))
+
process.nextTick(function () {
self.emit('infoHash')
})
@@ -192,11 +189,11 @@ Object.defineProperty(Torrent.prototype, 'magnetURI', {
}
})
-Torrent.prototype._onSwarmListening = function (port) {
+Torrent.prototype._onSwarmListening = function () {
var self = this
if (self._destroyed) return
- self.client.torrentPort = port
+ if (self.swarm.server) self.client.torrentPort = self.swarm.address().port
// begin discovering peers via the DHT and tracker servers
self.discovery = new Discovery({
@@ -204,7 +201,7 @@ Torrent.prototype._onSwarmListening = function (port) {
dht: self.client.dht,
tracker: self.client.tracker,
peerId: self.client.peerId,
- port: port,
+ port: self.client.torrentPort,
rtcConfig: self.client.rtcConfig
})
self.discovery.setTorrent(self.infoHash)
@@ -216,7 +213,7 @@ Torrent.prototype._onSwarmListening = function (port) {
// if full metadata was included in initial torrent id, use it
if (self.parsedTorrent.info) self._onMetadata(self.parsedTorrent)
- self.emit('listening', port)
+ self.emit('listening', self.client.torrentPort)
}
/**
@@ -454,7 +451,7 @@ Torrent.prototype._onWire = function (wire) {
wire.ut_pex.on('dropped', function (peer) {
// the remote peer believes a given peer has been dropped from the swarm.
// if we're not currently connected to it, then remove it from the swarm's queue.
- if (!(peer in self.swarm._peers)) self.swarm.removePeer(peer)
+ if (!(peer in self.swarm._peers)) self.swarm._removePeer(peer)
})
}