diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2014-10-10 09:34:01 +0400 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2014-10-10 09:34:01 +0400 |
commit | 99bf8c8466db12c5e88072b389eb690a47488988 (patch) | |
tree | ab71309e122fb52b6dbe23999748c6f61d2de0c5 /bin | |
parent | 80d2f86e8bebc1e660124980f55e97e5427a91d6 (diff) |
fix --list option (#95)
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cmd.js | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -140,9 +140,8 @@ function getRuntime () { } var client = new WebTorrent({ - list: argv.list, blocklist: argv.blocklist, - port: argv.port + port: !argv.list && argv.port }) .on('error', errorAndExit) @@ -175,8 +174,8 @@ torrent.on('infoHash', function () { } }) -client.on('torrent', function (torrent) { - if (client.listening) onTorrent(torrent) +torrent.on('ready', function () { + if (client.listening || argv.list) onTorrent(torrent) else client.on('listening', onTorrent) }) @@ -187,8 +186,15 @@ function onTorrent (torrent) { swarm = torrent.swarm wires = torrent.swarm.wires + if (argv.list) { + torrent.files.forEach(function (file, i) { + clivas.line('{3+bold:' + i + '} : {magenta:' + file.name + '}') + }) + process.exit(0) + } + torrent.on('verifying', function (data) { - if (argv.quiet || argv.list) return + if (argv.quiet) return clivas.clear() clivas.line( '{green:verifying existing torrent} {bold:'+Math.floor(data.percentDone)+'%} ' + @@ -197,8 +203,6 @@ function onTorrent (torrent) { }) torrent.on('done', function () { - if (argv.list) return - if (!argv.quiet) { // TODO: expose this data from bittorrent-swarm var numActiveWires = torrent.swarm.wires.reduce(function (num, wire) { @@ -220,13 +224,6 @@ function onTorrent (torrent) { } }) - if (argv.list) { - torrent.files.forEach(function (file, i) { - clivas.line('{3+bold:' + i + '} : {magenta:' + file.name + '}') - }) - process.exit(0) - } - var href if (client.server) { href = 'http://' + networkAddress() + ':' + client.server.address().port + '/' |