Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

progress

  • Loading branch information...
commit 9a59a604d0e3c358093a8b204e710080a13fbfaf 1 parent 24d4c31
@feross authored
View
53 lib/app.js
@@ -23,11 +23,11 @@ function App (torrentManager) {
// TODO: Show error in UI somehow
})
- setupWindow()
- setupTorrentManager()
+ self.setupWindow()
+ self.setupTorrentManager()
}
-function setupWindow () {
+App.prototype.setupWindow = function () {
$('.system .close').on('click', function () {
chrome.app.window.current().close()
})
@@ -41,7 +41,6 @@ function setupWindow () {
$('#addTorrent').on('submit', function (e) {
e.preventDefault()
var uri = $('#addTorrent input').val().trim()
- console.log(uri)
if (uri) {
window.torrentManager.add(uri)
$('#addTorrent input').val('')
@@ -64,47 +63,33 @@ function setupWindow () {
// contexts: ['all']
// })
// })
-
}
-function setupTorrentManager () {
+App.prototype.setupTorrentManager = function () {
window.torrentManager.on('addTorrent', function (torrent) {
var $torrent = $(handlebars.templates.torrent(torrent))
$('#torrents').append($torrent)
- window.setInterval(function () {
- $torrent.replaceWith(handlebars.templates.torrent(torrent))
- }, 300)
+
+ // $('.downloadMetadata').click(function () {
+ // t.downloadMetadata()
+ // })
})
- // var t = self.torrents['d2474e86c95b19b8bcfdb92bc12c9d44667cfa36']
- // $('.downloadMetadata').click(function () {
- // t.downloadMetadata()
+ // window.torrentManager.on('torrent:metadata', function (torrent, metadata) {
+ // var $torrent = $(handlebars.templates.torrent(torrent))
+ // $('#torrents').append($torrent)
// })
-
- window.torrentManager.on('torrent:metadata', function (torrent, metadata) {
-
- })
}
-// TODO: show multiple torrents
-function updateUI () {
- // console.log('Peer ID: ' + this.peerId.toString('utf8'))
- // console.log('Node ID: ' + this.nodeId.toString('hex'))
-
- var t = this.torrents['d2474e86c95b19b8bcfdb92bc12c9d44667cfa36']
- $('.infoHash span').text(t.infoHash)
- $('.displayName span').text(t.displayName)
+ // $('.dhtPeers span').text(Object.keys(this.dht.peers).length)
- $('.dhtNodes span').text(Object.keys(this.dht.nodes).length)
- $('.dhtPeers span').text(Object.keys(this.dht.peers).length)
+ // var connectedPeers = 0
+ // for (var infoHash in this.torrents) {
+ // var torrent = this.torrents[infoHash]
+ // connectedPeers += torrent.numPeers
+ // }
+ // $('.connectedPeers span').text(connectedPeers)
+ // $('.downloadMetadata').toggleClass('highlight', !!t.metadata)
- var connectedPeers = 0
- for (var infoHash in this.torrents) {
- var torrent = this.torrents[infoHash]
- connectedPeers += torrent.numPeers
- }
- $('.connectedPeers span').text(connectedPeers)
- $('.downloadMetadata').toggleClass('highlight', !!t.metadata)
-}
View
12 lib/torrent-manager.js
@@ -27,8 +27,7 @@ function TorrentManager () {
self.dht = new DHT({ nodeId: self.nodeId })
- // self.dht.on('node', self.updateUI.bind(self))
- // self.dht.on('peer', self.updateUI.bind(self))
+ self._reemitEvents(self.dht, 'dht', ['node', 'peer'])
self.dht.on('peer', function (addr, infoHash) {
var torrent = self.getTorrent(infoHash)
@@ -79,7 +78,7 @@ TorrentManager.prototype.add = function (uri) {
})
self.torrents.push(torrent)
- self._installTorrentEvents(torrent)
+ self._reemitEvents(torrent, 'torrent', ['listening', 'metadata'])
self.emit('addTorrent', torrent)
torrent.on('listening', function (port) {
@@ -91,13 +90,12 @@ TorrentManager.prototype.add = function (uri) {
self.dht.findPeers(MAX_PEERS) // TODO: should the DHT be concerned with max peers?
}
-TorrentManager.prototype._installTorrentEvents = function (torrent) {
+TorrentManager.prototype._reemitEvents = function (obj, eventPrefix, events) {
var self = this
- var events = ['listening', 'metadata']
events.forEach(function (event) {
- torrent.on(event, function () {
+ obj.on(event, function () {
var args = Array.prototype.slice.call(arguments)
- args.unshift('torrent:' + event, torrent)
+ args.unshift(eventPrefix + ':' + event, obj)
self.emit.apply(self, args)
})
})
View
6 lib/torrent.js
@@ -178,6 +178,12 @@ Object.defineProperty(Torrent.prototype, 'numPeers', {
}
})
+Object.defineProperty(Torrent.prototype, 'progress', {
+ get: function () {
+ return 0.7 // TODO
+ }
+})
+
/**
* Add a peer to the swarm
* @param {string} addr
View
19 views/torrent.html
@@ -1,18 +1,19 @@
-<section class="torrent" id="torrentXX">
- <!--
- <div v-show="!metadata">
- Getting metadata from peers...
- </div>
- -->
+<section class="torrent" id="torrent_{{ infoHash }}">
<div class="image">
<img src="img/folder.png">
</div>
<div class="info">
<div class="title">{{ title }}</div>
<div class="stats">
- {{humanizeFilesize swarm.downloaded }}, uploaded {{humanizeFilesize swarm.uploaded }} (Ratio: {{ swarm.ratio }})
+ {{#if metadata }}
+ {{humanizeFilesize swarm.downloaded }}, uploaded {{humanizeFilesize swarm.uploaded }} (Ratio: {{ swarm.ratio }})
+ {{else}}
+ Getting metadata from peers...
+ {{/if}}
+ </div>
+ <progress max="1" value="{{ progress }}"></progress>
+ <div class="stats2">
+ Downloading from 0 of {{ numPeers }} peers - UL: 0.0 KB/s
</div>
- <progress max="100" value="70"></progress>
- <div class="stats2">Seeding to 0 of 0 peers - UL: 0.0 KB/s</div>
</div>
</section>
Please sign in to comment.
Something went wrong with that request. Please try again.