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
parent5d7f05142612935064a94e37dc29cce2f1518701 (diff)
client.progress only for *active* torrents
-rw-r--r--index.js43
-rw-r--r--lib/torrent.js20
2 files changed, 29 insertions, 34 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
+ }
})
/**
diff --git a/lib/torrent.js b/lib/torrent.js
index 2fe75ca..25edd25 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -150,26 +150,22 @@ Object.defineProperty(Torrent.prototype, 'uploaded', {
// }
// })
-// Percentage complete, represented as a number between 0 and 1
-Object.defineProperty(Torrent.prototype, 'progress', {
- get: function () { return this.length ? this.downloaded / this.length : 0 }
-})
-
-// Seed ratio (uploaded / downloaded)
-Object.defineProperty(Torrent.prototype, 'ratio', {
- get: function () { return this.uploaded / (this.downloaded || 1) }
-})
-
-// Download speed in bytes/sec
Object.defineProperty(Torrent.prototype, 'downloadSpeed', {
get: function () { return this.swarm ? this.swarm.downloadSpeed() : 0 }
})
-// Upload speed in bytes/sec
Object.defineProperty(Torrent.prototype, 'uploadSpeed', {
get: function () { return this.swarm ? this.swarm.uploadSpeed() : 0 }
})
+Object.defineProperty(Torrent.prototype, 'progress', {
+ get: function () { return this.length ? this.downloaded / this.length : 0 }
+})
+
+Object.defineProperty(Torrent.prototype, 'ratio', {
+ get: function () { return this.uploaded / (this.downloaded || 1) }
+})
+
// Number of peers
Object.defineProperty(Torrent.prototype, 'numPeers', {
get: function () { return this.swarm ? this.swarm.numPeers : 0 }