Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/index.js b/index.js
index 09b18b0..736fc4c 100644
--- a/index.js
+++ b/index.js
@@ -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() }