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:
authorAlex <alxmorais8@msn.com>2019-08-12 15:06:27 +0300
committerAlex <alxmorais8@msn.com>2019-08-12 15:06:27 +0300
commit26dcc3fb29e3d9fa4b94fe195aae7ba028684178 (patch)
treec9c8cf0a4d48bac01b159dfe004e099cf3759715 /lib/torrent.js
parentcd43d50b15e17abd575b2aa1ac0b07010c84324d (diff)
Fix left parameter for asynchronous behaviour
Diffstat (limited to 'lib/torrent.js')
-rw-r--r--lib/torrent.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 0254b87..abf439b 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -277,6 +277,19 @@ class Torrent extends EventEmitter {
}
_onListening () {
+ if (this.destroyed) return
+
+ if (this.info) {
+ // 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.
+ this._onMetadata(this)
+ } else {
+ if (this.xs) this._getMetadataFromServer()
+ this._startDiscovery()
+ }
+ }
+
+ _startDiscovery () {
if (this.discovery || this.destroyed) return
let trackerOpts = this.client.tracker
@@ -300,14 +313,6 @@ class Torrent extends EventEmitter {
})
}
- if (this.info) {
- // 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.
- this._onMetadata(this)
- } else if (this.xs) {
- this._getMetadataFromServer()
- }
-
// begin discovering peers via DHT and trackers
this.discovery = new Discovery({
infoHash: this.infoHash,
@@ -611,6 +616,9 @@ class Torrent extends EventEmitter {
if (this.destroyed) return
this._debug('on store')
+ // Start discovery before emitting 'ready'
+ this._startDiscovery()
+
this.ready = true
this.emit('ready')