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--index.js15
-rw-r--r--lib/torrent.js35
2 files changed, 30 insertions, 20 deletions
diff --git a/index.js b/index.js
index ff69201..2947888 100644
--- a/index.js
+++ b/index.js
@@ -278,21 +278,24 @@ WebTorrent.prototype.seed = function (input, opts, onseed) {
else cb(null, item)
}
}), function (err, input) {
- if (err) return torrent._destroy(err)
if (self.destroyed) return
+ if (err) return torrent._destroy(err)
+
createTorrent.parseInput(input, opts, function (err, files) {
- if (err) return torrent._destroy(err)
if (self.destroyed) return
- streams = files.map(function (file) { return file.getStream })
+ if (err) return torrent._destroy(err)
+
+ streams = files.map(function (file) {
+ return file.getStream
+ })
createTorrent(input, opts, function (err, torrentBuf) {
- if (err) return torrent._destroy(err)
if (self.destroyed) return
+ if (err) return torrent._destroy(err)
var existingTorrent = self.get(torrentBuf)
if (existingTorrent) {
- torrent._destroy(new Error('Cannot add duplicate torrent ' + torrent.infoHash))
- _onseed(existingTorrent)
+ torrent._destroy(new Error('Cannot add duplicate torrent ' + existingTorrent.infoHash))
} else {
torrent._onTorrentId(torrentBuf)
}
diff --git a/lib/torrent.js b/lib/torrent.js
index a105148..f24b52c 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -1,5 +1,3 @@
-// TODO: cleanup event listeners
-
/* global URL, Blob */
module.exports = Torrent
@@ -315,25 +313,34 @@ Torrent.prototype._onListening = function () {
tracker: self.client.tracker && trackerOpts,
port: self.client.torrentPort
})
- self.discovery.on('error', function (err) {
+
+ self.discovery.on('error', onError)
+ self.discovery.on('peer', onPeer)
+ self.discovery.on('trackerAnnounce', onTrackerAnnounce)
+ self.discovery.on('dhtAnnounce', onDHTAnnounce)
+ self.discovery.on('warning', onWarning)
+
+ function onError (err) {
self._destroy(err)
- })
- self.discovery.on('peer', function (peer) {
+ }
+
+ function onPeer (peer) {
// Don't create new outgoing TCP connections when torrent is done
if (typeof peer === 'string' && self.done) return
self.addPeer(peer)
- })
+ }
- // expose discovery events
- self.discovery.on('trackerAnnounce', function () {
+ function onTrackerAnnounce () {
self.emit('trackerAnnounce')
- })
- self.discovery.on('dhtAnnounce', function () {
+ }
+
+ function onDHTAnnounce () {
self.emit('dhtAnnounce')
- })
- self.discovery.on('warning', function (err) {
+ }
+
+ function onWarning (err) {
self.emit('warning', err)
- })
+ }
// if full metadata was included in initial torrent id, use it immediately. Otherwise,
// wait for torrent-discovery to find peers and ut_metadata to get the metadata.
@@ -611,7 +618,7 @@ Torrent.prototype.addPeer = function (peer) {
if (host && self.client.blocked.contains(host)) {
self._debug('ignoring peer: blocked %s', peer)
- if (typeof peer === 'string') peer.destroy()
+ if (typeof peer !== 'string') peer.destroy()
self.emit('blockedPeer', peer)
return false
}