Skip to content
Permalink
Browse files

Improve client code, upgrade bootstrap

  • Loading branch information...
jakefb committed Sep 13, 2015
1 parent 22f4c6c commit 99683fd3846c5ef5a9131db64d0a0dac47376241
@@ -1,13 +1,18 @@
var dragDrop = require('drag-drop')
var uploadElement = require('upload-element')
var path = require('path')
var Peer = require('simple-peer')
var prettyBytes = require('pretty-bytes')
var WebTorrent = require('webtorrent')

var util = require('./util')

global.WEBTORRENT_ANNOUNCE = [ 'ws://tracker.fastcast.nz' ]

if (!Peer.WEBRTC_SUPPORT) {
util.error('Sorry, your browser is unsupported. Please try using Chrome.')
}

var client = new WebTorrent()

var upload = document.querySelector('input[name=upload]')
@@ -40,13 +45,11 @@ function onTorrent (torrent) {
util.updateSpeed(
'<b>Peers:</b> ' + torrent.swarm.wires.length + ' ' +
'<b>Progress:</b> ' + progress + '% ' +
'<b>Download speed:</b> ' + prettyBytes(client.downloadSpeed()) + '/s ' +
'<b>Upload speed:</b> ' + prettyBytes(client.uploadSpeed()) + '/s'
'<b>Download speed:</b> ' + prettyBytes(client.downloadSpeed()).toFixed(1) + '/s ' +
'<b>Upload speed:</b> ' + prettyBytes(client.uploadSpeed()).toFixed(1) + '/s'
)
}

torrent.swarm.on('download', updateSpeed)
torrent.swarm.on('upload', updateSpeed)
setInterval(updateSpeed, 5000)
updateSpeed()
setInterval(updateSpeed, 500)
}
@@ -1,11 +1,16 @@
var path = require('path')
var Peer = require('simple-peer')
var prettyBytes = require('pretty-bytes')
var WebTorrent = require('webtorrent')

var util = require('./util')

global.WEBTORRENT_ANNOUNCE = [ 'ws://tracker.fastcast.nz' ]

if (!Peer.WEBRTC_SUPPORT) {
util.error('Sorry, your browser is unsupported. Please try using Chrome.')
}

var client = new WebTorrent()

client.add(magnetUri, onTorrent)
@@ -24,26 +29,21 @@ function onTorrent (torrent) {
util.updateSpeed(
'<b>Peers:</b> ' + torrent.swarm.wires.length + ' ' +
'<b>Progress:</b> ' + progress + '% ' +
'<b>Download speed:</b> ' + prettyBytes(client.downloadSpeed()) + '/s ' +
'<b>Upload speed:</b> ' + prettyBytes(client.uploadSpeed()) + '/s'
'<b>Download speed:</b> ' + prettyBytes(client.downloadSpeed()).toFixed(1) + '/s ' +
'<b>Upload speed:</b> ' + prettyBytes(client.uploadSpeed()).toFixed(1) + '/s'
)
var progressBar = document.getElementById('progressBar')
progressBar.setAttribute('aria-valuenow', progress)
progressBar.setAttribute('style', 'width: ' + progress + '%')
}

progressBar.classList.add('active')

torrent.swarm.on('download', updateSpeed)
torrent.swarm.on('upload', updateSpeed)
setInterval(updateSpeed, 5000)
updateSpeed()
setInterval(updateSpeed, 500)

torrent.files.forEach(function (file) {
// Create a video element
file.appendTo('#player')

document.getElementById('downloadButton').onclick = function() {
downloadButton.addEventListener('click', function () {
var download = document.getElementById('download')
download.classList.remove('hidden')

@@ -53,17 +53,13 @@ function onTorrent (torrent) {

// Hide download progress
download.classList.add('hidden')
var progress = document.getElementById('progress')
progress.classList.add('hidden')

// Add a link to the page
var a = document.createElement('a')
a.download = file.name
a.href = url
download.appendChild(a)
a.download = window.URL.createObjectURL(url)
a.click()
window.URL.revokeObjectURL(url)
})
}
})
})
}
@@ -1,5 +1,6 @@
var parseTorrent = require('parse-torrent')
var path = require('path')
var Peer = require('simple-peer')
var prettyBytes = require('pretty-bytes')
var http = require('stream-http')
var WebTorrent = require('webtorrent')
@@ -8,14 +9,18 @@ var util = require('./util')

global.WEBTORRENT_ANNOUNCE = [ 'ws://tracker.fastcast.nz' ]

if (!Peer.WEBRTC_SUPPORT) {
util.error('Sorry, your browser is unsupported. Please try using Chrome.')
}

http.get('/torrents/' + torrentName, function (res) {
var data = [] // List of Buffer objects

res.on("data", function(chunk) {
res.on('data', function (chunk) {
data.push(chunk) // Append Buffer object
})

res.on("end", function() {
res.on('end', function () {
data = Buffer.concat(data) // Make one large Buffer of it

var torrentParsed = parseTorrent(data) // Parse the Buffer
@@ -41,24 +46,18 @@ http.get('/torrents/' + torrentName, function (res) {
'<b>Download speed:</b> ' + prettyBytes(client.downloadSpeed()) + '/s ' +
'<b>Upload speed:</b> ' + prettyBytes(client.uploadSpeed()) + '/s'
)
var progressBar = document.getElementById('progressBar')
progressBar.setAttribute('aria-valuenow', progress)
progressBar.setAttribute('style', 'width: ' + progress + '%')
}

progressBar.classList.add('active')

torrent.swarm.on('download', updateSpeed)
torrent.swarm.on('upload', updateSpeed)
setInterval(updateSpeed, 5000)
updateSpeed()
setInterval(updateSpeed, 500)

torrent.files.forEach(function (file) {
// Create a video element
file.appendTo('#player')

document.getElementById('downloadButton').onclick = function() {
var download = document.getElementById('download')
downloadButton.addEventListener('click', function () {
download.classList.remove('hidden')

// Get a url for each file
@@ -67,18 +66,14 @@ http.get('/torrents/' + torrentName, function (res) {

// Hide download progress
download.classList.add('hidden')
var progress = document.getElementById('progress')
progress.classList.add('hidden')

// Add a link to the page
var a = document.createElement('a')
a.download = file.name
a.href = url
download.appendChild(a)
a.download = window.URL.createObjectURL(url)
a.click()
window.URL.revokeObjectURL(url)
})
}
})
})
}
})
@@ -1,6 +1,8 @@
var downlaodButton = document.getElementById('downloadButton')
var download = document.getElementById('download')
var logElem = document.querySelector('.log')
var progressBar = document.getElementById('progressBar')
var speed = document.querySelector('.speed')
var caption = document.querySelector('.caption')

exports.log = function log (item) {
if (typeof item === 'string') {
@@ -28,6 +30,6 @@ exports.warning = function warning (err) {
exports.error = function error (err) {
console.error(err.stack || err.message || err)
var p = exports.log(err.message || err)
p.style.color = 'red'
p.style.color = '#3d3d62'
p.style.fontWeight = 'bold'
}

0 comments on commit 99683fd

Please sign in to comment.
You can’t perform that action at this time.