diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-03-04 01:24:37 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-03-04 01:24:37 +0300 |
commit | 2670b687f9ef7be87f4f8a128c80f0260f1ea131 (patch) | |
tree | 4b3816233f5b96a38994c7e37e573a023784a6ac /index.js | |
parent | 5d7f05142612935064a94e37dc29cce2f1518701 (diff) |
client.progress only for *active* torrents
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 43 |
1 files changed, 21 insertions, 22 deletions
@@ -111,40 +111,39 @@ function WebTorrent (opts) { } } -// Seed ratio for all torrents (uploaded / downloaded) -Object.defineProperty(WebTorrent.prototype, 'ratio', { - get: function () { - var uploaded = this.torrents.reduce(function (total, torrent) { - return total + torrent.uploaded - }, 0) - var downloaded = this.torrents.reduce(function (total, torrent) { - return total + torrent.downloaded - }, 0) || 1 - return uploaded / downloaded - } +Object.defineProperty(WebTorrent.prototype, 'downloadSpeed', { + get: function () { return this._downloadSpeed() } +}) + +Object.defineProperty(WebTorrent.prototype, 'uploadSpeed', { + get: function () { return this._uploadSpeed() } }) -// Percentage complete, represented as a number between 0 and 1 Object.defineProperty(WebTorrent.prototype, 'progress', { get: function () { - var downloaded = this.torrents.reduce(function (total, torrent) { + var torrents = this.torrents.filter(function (torrent) { + return torrent.progress !== 1 + }) + var downloaded = torrents.reduce(function (total, torrent) { return total + torrent.downloaded }, 0) - var length = this.torrents.reduce(function (total, torrent) { + var length = torrents.reduce(function (total, torrent) { return total + (torrent.length || 0) }, 0) || 1 return downloaded / length } }) -// Download speed in bytes/sec -Object.defineProperty(WebTorrent.prototype, 'downloadSpeed', { - get: function () { return this._downloadSpeed() } -}) - -// Upload speed in bytes/sec -Object.defineProperty(WebTorrent.prototype, 'uploadSpeed', { - get: function () { return this._uploadSpeed() } +Object.defineProperty(WebTorrent.prototype, 'ratio', { + get: function () { + var uploaded = this.torrents.reduce(function (total, torrent) { + return total + torrent.uploaded + }, 0) + var downloaded = this.torrents.reduce(function (total, torrent) { + return total + torrent.downloaded + }, 0) || 1 + return uploaded / downloaded + } }) /** |