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:
authorFeross Aboukhadijeh <feross@feross.org>2016-03-04 00:53:26 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-03-04 00:53:26 +0300
commitabdd426c55e2813ebe1ea31db0e0b0e3cd9aa4b9 (patch)
tree9e241c4828092e38350019269cc5f15fb2a29e84 /index.js
parent0569fb16970b1565047295aecccff3a43ca7ba3e (diff)
add client.progress property
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() }