From 9f9ba0b386cf00814ed510cfa0de1e784c33ea52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rodr=C3=ADguez?= Date: Sat, 2 Jan 2016 00:58:17 -0500 Subject: [PATCH] v0.9.1 - Optimized a lot of things --- README.md | 2 +- .../.FOR_REFERENCE_ONLY_-_DO_NOT_EDIT | 0 {compiled => _compiled}/app.js | 0 {compiled => _compiled}/index.html | 0 {compiled => _compiled}/style.css | 0 app.coffee | 54 +++++++++---------- index.jade | 2 +- 7 files changed, 26 insertions(+), 32 deletions(-) rename {compiled => _compiled}/.FOR_REFERENCE_ONLY_-_DO_NOT_EDIT (100%) rename {compiled => _compiled}/app.js (100%) rename {compiled => _compiled}/index.html (100%) rename {compiled => _compiled}/style.css (100%) diff --git a/README.md b/README.md index 400560b..d03493c 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ MIT. Copyright (c) [Diego Rodríguez Baquero](http://diegorbaquero.com) [βTorrent]: https://btorrent.xyz [Direct-βTorrent]: https://direct.btorrent.xyz -[RawGit]: https://rawgit.com/DiegoRBaquero/BTorrent/master/compiled/index.html +[RawGit]: https://rawgit.com/DiegoRBaquero/BTorrent/master/_compiled/index.html [WebTorrent]: https://webtorrent.io [AngularJS]: https://angularjs.org/ [Skeleton]: http://getskeleton.com/ diff --git a/compiled/.FOR_REFERENCE_ONLY_-_DO_NOT_EDIT b/_compiled/.FOR_REFERENCE_ONLY_-_DO_NOT_EDIT similarity index 100% rename from compiled/.FOR_REFERENCE_ONLY_-_DO_NOT_EDIT rename to _compiled/.FOR_REFERENCE_ONLY_-_DO_NOT_EDIT diff --git a/compiled/app.js b/_compiled/app.js similarity index 100% rename from compiled/app.js rename to _compiled/app.js diff --git a/compiled/index.html b/_compiled/index.html similarity index 100% rename from compiled/index.html rename to _compiled/index.html diff --git a/compiled/style.css b/_compiled/style.css similarity index 100% rename from compiled/style.css rename to _compiled/style.css diff --git a/app.coffee b/app.coffee index 0705c2a..efa0eb4 100644 --- a/app.coffee +++ b/app.coffee @@ -1,5 +1,5 @@ trackers = [ - [ 'wss://tracker.btorrent.xyz' ], + [ 'wss://tracker.btorrent.xyz' ] [ 'wss://tracker.webtorrent.io' ] ] @@ -9,32 +9,28 @@ opts = { rtcConfig = { "iceServers":[ - {"url":"stun:23.21.150.121","urls":"stun:23.21.150.121"}, - {"url":"stun:stun.l.google.com:19302","urls":"stun:stun.l.google.com:19302"}, - {"url":"stun:stun1.l.google.com:19302","urls":"stun:stun1.l.google.com:19302"}, - {"url":"stun:stun2.l.google.com:19302","urls":"stun:stun2.l.google.com:19302"}, - {"url":"stun:stun3.l.google.com:19302","urls":"stun:stun3.l.google.com:19302"}, - {"url":"stun:stun4.l.google.com:19302","urls":"stun:stun4.l.google.com:19302"}, + {"url":"stun:23.21.150.121","urls":"stun:23.21.150.121"} + {"url":"stun:stun.l.google.com:19302","urls":"stun:stun.l.google.com:19302"} { - "url":"turn:global.turn.twilio.com:3478?transport=udp", - "urls":"turn:global.turn.twilio.com:3478?transport=udp", - "username":"857315a4616be37252127d4ff924c3a3536dd3fa729b56206dfa0e6808a80478", + "url":"turn:global.turn.twilio.com:3478?transport=udp" + "urls":"turn:global.turn.twilio.com:3478?transport=udp" + "username":"857315a4616be37252127d4ff924c3a3536dd3fa729b56206dfa0e6808a80478" "credential":"EEEr7bxx8umMHC4sOoWDC/4MxU/4JCfL+W7KeSJEsBQ=" - }, + } { - "url": "turn:numb.viagenie.ca", - "urls": "turn:numb.viagenie.ca", - "credential": "webrtcdemo", + "url": "turn:numb.viagenie.ca" + "urls": "turn:numb.viagenie.ca" + "credential": "webrtcdemo" "username": "louis%40mozilla.com" } ] } -client = new WebTorrent {rtcConfig: rtcConfig} +debug = window.localStorage.getItem('debug')? dbg = (string, item, color) -> color = if color? then color else '#333333' - if window.localStorage.getItem('debug')? + if debug if item? && item.name console.debug '%cβTorrent:' + (if item.infoHash? then 'torrent ' else 'torrent ' + item._torrent.name + ':file ') + item.name + (if item.infoHash? then ' (' + item.infoHash + ')' else '') + ' %c' + string, 'color: #33C3F0', 'color: ' + color return @@ -46,6 +42,8 @@ dbg = (string, item, color) -> er = (err, torrent) -> dbg err, torrent, '#FF0000' +client = new WebTorrent {rtcConfig: rtcConfig} + app = angular.module 'bTorrent', ['ui.grid', 'ui.grid.resizeColumns', 'ui.grid.selection', 'ngFileUpload', 'ngNotify'], ['$compileProvider','$locationProvider', ($compileProvider, $locationProvider) -> $compileProvider.aHrefSanitizationWhitelist /^\s*(https?|magnet|blob|javascript):/ $locationProvider.html5Mode( @@ -56,7 +54,6 @@ app = angular.module 'bTorrent', ['ui.grid', 'ui.grid.resizeColumns', 'ui.grid.s app.controller 'bTorrentCtrl', ['$scope','$http','$log','$location', 'ngNotify', ($scope, $http, $log, $location, ngNotify) -> $scope.client = client $scope.seedIt = true - $scope.client.validTorrents = [] $scope.columns = [ {field: 'name', cellTooltip: true, minWidth: '200'} @@ -64,7 +61,7 @@ app.controller 'bTorrentCtrl', ['$scope','$http','$log','$location', 'ngNotify', {field: 'received', displayName: 'Downloaded', cellFilter: 'pbytes', width: '135'} {field: 'downloadSpeed()', displayName: '↓ Speed', cellFilter: 'pbytes:1', width: '100'} {field: 'progress', displayName: 'Progress', cellFilter: 'progress', width: '100'} - {field: 'timeRemaining', displayName: 'ETA', cellFilter: 'humanTime', width: '150'} + {field: 'timeRemaining', displayName: 'ETA', cellFilter: 'humanTime', width: '140'} {field: 'uploaded', displayName: 'Uploaded', cellFilter: 'pbytes', width: '125'} {field: 'uploadSpeed()', displayName: '↑ Speed', cellFilter: 'pbytes:1', width: '100'} {field: 'numPeers', displayName: 'Peers', width: '80'} @@ -85,8 +82,8 @@ app.controller 'bTorrentCtrl', ['$scope','$http','$log','$location', 'ngNotify', return $scope.$apply() return - - setInterval updateAll, 500 + + #setInterval updateAll, 500 $scope.gridOptions.onRegisterApi = ( gridApi ) -> $scope.gridApi = gridApi @@ -150,7 +147,6 @@ app.controller 'bTorrentCtrl', ['$scope','$http','$log','$location', 'ngNotify', torrent.fileName = torrent.name + '.torrent' if !isSeed - $scope.client.validTorrents.push torrent if !($scope.selectedTorrent?) $scope.selectedTorrent = torrent $scope.client.processing = false @@ -161,17 +157,15 @@ app.controller 'bTorrentCtrl', ['$scope','$http','$log','$location', 'ngNotify', throw err if isSeed dbg 'Started seeding', torrent - if $scope.client.validTorrents.indexOf(torrent) == -1 - $scope.client.validTorrents.push torrent if !($scope.selectedTorrent?) $scope.selectedTorrent = torrent $scope.client.processing = false file.url = url if !isSeed - dbg 'Finished downloading file ' + file.name, torrent + dbg 'Done ', file return if !isSeed - dbg 'Received file ' + file.name + ' metadata', torrent + dbg 'Received metadata', file return torrent.on 'download', (chunkSize) -> if !isSeed @@ -200,8 +194,10 @@ app.controller 'bTorrentCtrl', ['$scope','$http','$log','$location', 'ngNotify', setTimeout -> dbg 'Adding ' + $location.hash() $scope.client.add $location.hash(), $scope.onTorrent - , 500 + , 0 return + + dbg 'Ready' ] app.filter 'html', ['$sce', ($sce) -> @@ -214,8 +210,6 @@ app.filter 'pbytes', -> (num, speed) -> if isNaN(num) return '' - exponent = undefined - unit = undefined units = [ 'B' 'kB' @@ -225,7 +219,7 @@ app.filter 'pbytes', -> ] if num < 1 return (if speed then '' else '0 B') - exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), 8) + exponent = Math.min(Math.floor(Math.log(num) / 6.907755278982137), 8) num = (num / 1000 ** exponent).toFixed(1) * 1 unit = units[exponent] num + ' ' + unit + (if speed then '/s' else '') @@ -234,7 +228,7 @@ app.filter 'humanTime', -> (millis) -> if millis < 1000 return '' - remaining = moment.duration(millis / 1000, 'seconds').humanize() + remaining = moment.duration(millis).humanize() remaining[0].toUpperCase() + remaining.substr(1) app.filter 'progress', -> diff --git a/index.jade b/index.jade index 278c941..95e9b75 100644 --- a/index.jade +++ b/index.jade @@ -17,7 +17,7 @@ html(ng-app='bTorrent', lang='en') header h1 | βTorrent - span.version v0.9.0 + span.version v0.9.1 .container .row .four.columns