diff --git a/client/index.js b/client/index.js
index 93433174..d158f962 100644
--- a/client/index.js
+++ b/client/index.js
@@ -4,6 +4,7 @@ var dragDrop = require('drag-drop')
// var listify = require('listify')
var path = require('path')
var prettyBytes = require('pretty-bytes')
+var throttle = require('throttleit')
var thunky = require('thunky')
var uploadElement = require('upload-element')
var WebTorrent = require('webtorrent')
@@ -50,7 +51,7 @@ dragDrop('body', onFiles)
// Download via input element
document.querySelector('form').addEventListener('submit', function (e) {
e.preventDefault()
- downloadTorrent(document.querySelector('form input[name=torrentId]').value)
+ downloadTorrent(document.querySelector('form input[name=torrentId]').value.trim())
})
// Download by URL hash
@@ -138,11 +139,16 @@ function onTorrent (torrent) {
var torrentFileName = path.basename(torrent.name, path.extname(torrent.name)) + '.torrent'
+ util.log('"' + torrentFileName + '" contains ' + torrent.files.length + ' files:')
+ torrent.files.forEach(function (file) {
+ util.log(' - ' + file.name + ' (' + prettyBytes(file.length) + ')')
+ })
+
util.log(
'Torrent info hash: ' + torrent.infoHash + ' ' +
'[Share link] ' +
'[Magnet URI] ' +
- '[Download .torrent]'
+ '[Download .torrent]'
)
function updateSpeed () {
@@ -150,13 +156,13 @@ function onTorrent (torrent) {
util.updateSpeed(
'Peers: ' + torrent.swarm.wires.length + ' ' +
'Progress: ' + progress + '% ' +
- 'Download speed: ' + prettyBytes(window.client.downloadSpeed()) + '/s ' +
- 'Upload speed: ' + prettyBytes(window.client.uploadSpeed()) + '/s'
+ 'Download speed: ' + prettyBytes(window.client.downloadSpeed) + '/s ' +
+ 'Upload speed: ' + prettyBytes(window.client.uploadSpeed) + '/s'
)
}
- torrent.swarm.on('download', updateSpeed)
- torrent.swarm.on('upload', updateSpeed)
+ torrent.on('download', throttle(updateSpeed, 250))
+ torrent.on('upload', throttle(updateSpeed, 250))
setInterval(updateSpeed, 5000)
updateSpeed()
diff --git a/package.json b/package.json
index e7e29377..9530e1f4 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,7 @@
"drag-drop": "^2.3.1",
"electron-debug": "^0.5.0",
"pretty-bytes": "^3.0.0",
+ "throttleit": "^1.0.0",
"thunky": "^0.1.0",
"upload-element": "^1.0.1",
"webtorrent": "^0.68.0",