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-01-10 19:53:10 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-01-11 02:08:59 +0300
commit19a942d6c2215352a35bde3abc5bfed21d9e3fc2 (patch)
treea2e652f7f9524b10f8e72b3bc7bf92a6d79d4e5c /index.js
parent427f2d3b7b6e6d1bbb19681f7515acd80cc60d61 (diff)
BREAKING: `downloadSpeed` and `uploadSpeed` are getters
torrent.downloadSpeed() -> torrent.downloadSpeed torrent.uploadSpeed() -> torrent.uploadSpeed
Diffstat (limited to 'index.js')
-rw-r--r--index.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/index.js b/index.js
index 6a7776a..754b4f0 100644
--- a/index.js
+++ b/index.js
@@ -64,8 +64,8 @@ function WebTorrent (opts) {
self.torrents = []
- self.downloadSpeed = speedometer()
- self.uploadSpeed = speedometer()
+ self._downloadSpeed = speedometer()
+ self._uploadSpeed = speedometer()
self.maxConns = opts.maxConns
@@ -104,23 +104,29 @@ function WebTorrent (opts) {
}
}
-/**
- * Seed ratio for all torrents in the client.
- * @type {number}
- */
+// Seed ratio for all torrents (uploaded / downloaded)
Object.defineProperty(WebTorrent.prototype, 'ratio', {
get: function () {
- var self = this
- var uploaded = self.torrents.reduce(function (total, torrent) {
+ var uploaded = this.torrents.reduce(function (total, torrent) {
return total + torrent.uploaded
}, 0)
- var downloaded = self.torrents.reduce(function (total, torrent) {
+ var downloaded = this.torrents.reduce(function (total, torrent) {
return total + torrent.downloaded
}, 0) || 1
return uploaded / downloaded
}
})
+// 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() }
+})
+
/**
* Returns the torrent with the given `torrentId`. Convenience method. Easier than
* searching through the `client.torrents` array. Returns `null` if no matching torrent