diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-03-04 00:53:26 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-03-04 00:53:26 +0300 |
commit | abdd426c55e2813ebe1ea31db0e0b0e3cd9aa4b9 (patch) | |
tree | 9e241c4828092e38350019269cc5f15fb2a29e84 /index.js | |
parent | 0569fb16970b1565047295aecccff3a43ca7ba3e (diff) |
add client.progress property
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -124,6 +124,19 @@ Object.defineProperty(WebTorrent.prototype, 'ratio', { } }) +// 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) { + return total + torrent.downloaded + }, 0) + var length = this.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() } |