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
path: root/lib
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2016-04-21 13:10:29 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-04-21 13:10:29 +0300
commitfa2a6c541849853ded575b95ee424ab94c0936a4 (patch)
treecf58865f0c2b84e26fb5899de41bd92628109d87 /lib
parent597d1ce10ce20ae33b0118d85cfdbc8cbabcb32a (diff)
fix more bugs
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js35
1 files changed, 21 insertions, 14 deletions
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
}