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>2014-03-03 12:30:22 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-03-03 12:30:22 +0400
commitf59b774dbcf600ea6dbb4b07a31068e0c522391c (patch)
treefc904419d21417536757fd124c69f4c36c390539 /lib/torrent.js
parentde465f37d4cd35a8a4879c2caefc8994730f3bad (diff)
hooked up a lot more of the UI
Diffstat (limited to 'lib/torrent.js')
-rw-r--r--lib/torrent.js44
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 3347e04..ccca022 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -38,6 +38,7 @@ function Torrent (uri, opts) {
self.metadataRaw = null
self.metadata = null
+ self.parsedTorrent = null
self.swarm = new Swarm(self.infoHash, self.peerId, { dht: true })
self.storage = null
@@ -55,6 +56,48 @@ function Torrent (uri, opts) {
self.swarm.on('wire', self._onWire.bind(self))
}
+Object.defineProperty(Torrent.prototype, 'length', {
+ get: function () {
+ var self = this
+ if (!self.parsedTorrent) return 0
+ return self.parsedTorrent.length
+ }
+})
+
+/**
+ * Percentage complete, represented as a number between 0 and 1.
+ */
+Object.defineProperty(Torrent.prototype, 'progress', {
+ get: function () {
+ var self = this
+ if (!self.parsedTorrent) return 0
+ return self.downloaded / self.parsedTorrent.length
+ }
+})
+
+Object.defineProperty(Torrent.prototype, 'downloaded', {
+ get: function () {
+ var self = this
+ return (self.storage && self.storage.downloaded) || 0
+ }
+})
+
+Object.defineProperty(Torrent.prototype, 'uploaded', {
+ get: function () {
+ var self = this
+ return self.swarm.uploaded
+ }
+})
+
+
+Object.defineProperty(Torrent.prototype, 'ratio', {
+ get: function () {
+ var self = this
+ if (self.uploaded === 0) return 0
+ return self.downloaded / self.uploaded
+ }
+})
+
/**
* Add a peer to the swarm
* @param {string} addr
@@ -272,7 +315,6 @@ Torrent.prototype._onMetadata = function () {
self.storage.on('piece', self._onStoragePiece.bind(self))
self.storage.on('file', function (file) {
console.log('FILE', file.name)
- self.file = file.buffer
})
self.storage.on('done', function () {
console.log('done with torrent!')