diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-01-10 19:53:10 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-01-11 02:08:59 +0300 |
commit | 19a942d6c2215352a35bde3abc5bfed21d9e3fc2 (patch) | |
tree | a2e652f7f9524b10f8e72b3bc7bf92a6d79d4e5c /index.js | |
parent | 427f2d3b7b6e6d1bbb19681f7515acd80cc60d61 (diff) |
BREAKING: `downloadSpeed` and `uploadSpeed` are getters
torrent.downloadSpeed() -> torrent.downloadSpeed
torrent.uploadSpeed() -> torrent.uploadSpeed
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -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 |