diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-05-30 00:28:21 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-05-30 00:28:21 +0300 |
commit | 2c60fb03ce731fee555697b7221f0014c4f30d55 (patch) | |
tree | 1ebde7faddbde35096ec93793c0c90109baa3452 /index.js | |
parent | 8dfcea0e818dc072202ffef93731e74e16128c8b (diff) |
return torrent object from webtorrent.seed
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 37 |
1 files changed, 21 insertions, 16 deletions
@@ -202,9 +202,26 @@ WebTorrent.prototype.seed = function (input, opts, onseed) { if (!opts) opts = {} opts.noVerify = true + var streams + var torrent = self.add(undefined, opts, function (torrent) { + var tasks = [function (cb) { + torrent.storage.load(streams, cb) + }] + if (self.dht) { + tasks.push(function (cb) { + torrent.on('dhtAnnounce', cb) + }) + } + parallel(tasks, function (err) { + if (err) return self.emit('error', err) + if (onseed) onseed(torrent) + self.emit('seed', torrent) + }) + }) + createTorrent.parseInput(input, opts, function (err, files) { if (err) return self.emit('error', err) - var streams = files.map(function (file) { return file.getStream }) + streams = files.map(function (file) { return file.getStream }) createTorrent(input, opts, function (err, torrentBuf) { if (err) return self.emit('error', err) @@ -212,23 +229,11 @@ WebTorrent.prototype.seed = function (input, opts, onseed) { // if client was destroyed asyncronously, bail early (or `add` will throw) if (self.destroyed) return - self.add(torrentBuf, opts, function (torrent) { - var tasks = [function (cb) { - torrent.storage.load(streams, cb) - }] - if (self.dht) { - tasks.push(function (cb) { - torrent.on('dhtAnnounce', cb) - }) - } - parallel(tasks, function (err) { - if (err) return self.emit('error', err) - if (onseed) onseed(torrent) - self.emit('seed', torrent) - }) - }) + torrent._onTorrentId(torrentBuf) }) }) + + return torrent } /** |