Permalink
Browse files

show time remaining

  • Loading branch information...
1 parent 1b5e966 commit 2a596dd12d6294866ba857ac3b4003a8416b6705 @feross feross committed Mar 3, 2014
Showing with 24 additions and 2 deletions.
  1. +10 −1 lib/app.js
  2. +12 −0 lib/torrent.js
  3. +2 −1 package.json
View
@@ -3,8 +3,9 @@ module.exports = App
var $ = require('jquery')
var bncode = require('bncode')
var fs = require('fs')
-var key = require('keymaster')
var humanize = require('humanize')
+var key = require('keymaster')
+var moment = require('moment')
var TEMPLATE = {
TORRENT: fs.readFileSync(__dirname + '/../views/torrent.html')
@@ -142,6 +143,14 @@ App.prototype.updateTorrentUI = function ($torrent, torrent) {
else
$torrent.removeClass('is-seeding')
+ var timeRemaining
+ if (torrent.timeRemaining === Infinity) {
+ timeRemaining = 'remaining time unknown'
+ } else {
+ timeRemaining = moment(Date.now() + torrent.timeRemaining).fromNow() + '...'
+ }
+ $torrent.find('.timeRemaining').text(timeRemaining)
+
$torrent.find('.name').text(torrent.name)
$torrent.find('.downloaded').text(humanize.filesize(torrent.downloaded))
$torrent.find('.uploaded').text(humanize.filesize(torrent.uploaded))
View
@@ -65,6 +65,18 @@ Object.defineProperty(Torrent.prototype, 'length', {
})
/**
+ * Time remaining (in milliseconds)
+ */
+Object.defineProperty(Torrent.prototype, 'timeRemaining', {
+ get: function () {
+ var self = this
+ var remainingBytes = self.length - self.downloaded
+ if (self.swarm.downloadSpeed() === 0) return Infinity
+ return (remainingBytes / self.swarm.downloadSpeed()) * 1000
+ }
+})
+
+/**
* Percentage complete, represented as a number between 0 and 1.
*/
Object.defineProperty(Torrent.prototype, 'progress', {
View
@@ -40,7 +40,8 @@
"magnet-uri": "1.x",
"parse-torrent": "0.x",
"rusha-browserify": "^0.7.3",
- "speedometer": "^0.1.2"
+ "speedometer": "^0.1.2",
+ "moment": "^2.5.1"
},
"devDependencies": {
"brfs": "^0.2.2",

0 comments on commit 2a596dd

Please sign in to comment.