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 01:24:37 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-03-04 01:24:37 +0300
commit2670b687f9ef7be87f4f8a128c80f0260f1ea131 (patch)
tree4b3816233f5b96a38994c7e37e573a023784a6ac /index.js
parent5d7f05142612935064a94e37dc29cce2f1518701 (diff)
client.progress only for *active* torrents
Diffstat (limited to 'index.js')
-rw-r--r--index.js43
1 files changed, 21 insertions, 22 deletions
diff --git a/index.js b/index.js
index 736fc4c..f6f7614 100644
--- a/index.js
+++ b/index.js
@@ -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
+ }
})
/**