diff options
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() } |