v0.14 - Viewer view

This commit is contained in:
Diego Rodríguez 2016-02-28 02:47:19 -03:00
parent 37c1add251
commit 35072541a1
6 changed files with 85 additions and 28 deletions

View file

@ -8,7 +8,7 @@ html(ng-app='BTorrent', lang='en')
meta(name='keywords', content='βTorrent, btorrent, client, webtorrent, browser, torrent, stream, bittorrent, torrenting, sharing, filesharing') meta(name='keywords', content='βTorrent, btorrent, client, webtorrent, browser, torrent, stream, bittorrent, torrenting, sharing, filesharing')
meta(name='author', content='Diego Rodríguez Baquero - DiegoRBaquero') meta(name='author', content='Diego Rodríguez Baquero - DiegoRBaquero')
meta(name='viewport', content='width=device-width, initial-scale=1') meta(name='viewport', content='width=device-width, initial-scale=1')
script(src='https://cdn.jsdelivr.net/g/webtorrent@0.78,momentjs@2.11,angularjs@1.4(angular.min.js+angular-route.min.js+angular-sanitize.min.js),angular.ui-grid@3.1,angular.ng-notify@0.7,angular.file-upload@12') script(src='https://cdn.jsdelivr.net/g/webtorrent@0.79,momentjs@2.11,angularjs@1.4(angular.min.js+angular-route.min.js+angular-sanitize.min.js),angular.ui-grid@3.1,angular.ng-notify@0.7,angular.file-upload@12')
link(rel='stylesheet', href='https://cdn.jsdelivr.net/g/normalize@3.0,skeleton@2.0,angular.ng-notify@0.7(ng-notify.min.css)') link(rel='stylesheet', href='https://cdn.jsdelivr.net/g/normalize@3.0,skeleton@2.0,angular.ng-notify@0.7(ng-notify.min.css)')
link(rel='stylesheet', href='https://cdn.jsdelivr.net/fontawesome/4.5/css/font-awesome.min.css') link(rel='stylesheet', href='https://cdn.jsdelivr.net/fontawesome/4.5/css/font-awesome.min.css')
link(rel='stylesheet', href='https://cdn.jsdelivr.net/angular.ui-grid/3.1/ui-grid.min.css') link(rel='stylesheet', href='https://cdn.jsdelivr.net/angular.ui-grid/3.1/ui-grid.min.css')
@ -17,11 +17,14 @@ html(ng-app='BTorrent', lang='en')
header header
h1 h1
| βTorrent | βTorrent
span.version v0.13.1 span.version v0.14.0
div.views div.views(ng-show='$root.client.torrents.length == 0')
a(ng-href='/#') Full a(ng-href='/#') Full
| | | |
a(ng-href='/download') Single Download a(ng-href='/download') Single Download
| |
a(ng-href='/view') Stream / View
#viewer
#view(ng-view) #view(ng-view)
footer footer
a.button(href="https://github.com/DiegoRBaquero/BTorrent/issues", target="_blank") a.button(href="https://github.com/DiegoRBaquero/BTorrent/issues", target="_blank")

View file

@ -50,15 +50,15 @@ app = angular.module 'BTorrent', ['ngRoute', 'ui.grid', 'ui.grid.resizeColumns',
requireBase: false requireBase: false
).hashPrefix '#' ).hashPrefix '#'
$routeProvider.when '/stream', $routeProvider.when '/view',
templateUrl: 'views/stream.html' templateUrl: 'views/view.html'
controller: 'StreamCtrl' controller: 'ViewCtrl'
.when '/download', .when '/download',
templateUrl: 'views/download.html' templateUrl: 'views/download.html'
controller: 'DownloadCtrl' controller: 'DownloadCtrl'
.otherwise .otherwise
templateUrl: 'views/main.html' templateUrl: 'views/full.html'
controller: 'MainCtrl' controller: 'FullCtrl'
] ]
app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) -> app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) ->
@ -103,11 +103,11 @@ app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location'
ngNotify.set err, 'error' ngNotify.set err, 'error'
er err, torrent er err, torrent
$rootScope.addMagnet = (magnet) -> $rootScope.addMagnet = (magnet, onTorrent) ->
if magnet? && magnet.length > 0 if magnet? && magnet.length > 0
dbg 'Adding magnet/hash ' + magnet dbg 'Adding magnet/hash ' + magnet
$rootScope.client.processing = true $rootScope.client.processing = true
$rootScope.client.add magnet, opts, $rootScope.onTorrent $rootScope.client.add magnet, opts, onTorrent || $rootScope.onTorrent
$rootScope.destroyedTorrent = (err) -> $rootScope.destroyedTorrent = (err) ->
if err if err
@ -129,6 +129,8 @@ app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location'
torrent.safeTorrentFileURL = torrent.torrentFileBlobURL torrent.safeTorrentFileURL = torrent.torrentFileBlobURL
torrent.fileName = torrent.name + '.torrent' torrent.fileName = torrent.name + '.torrent'
if !isSeed if !isSeed
dbg 'Received metadata', torrent
ngNotify.set 'Received ' + torrent.name + ' metadata'
if !($rootScope.selectedTorrent?) if !($rootScope.selectedTorrent?)
$rootScope.selectedTorrent = torrent $rootScope.selectedTorrent = torrent
$rootScope.client.processing = false $rootScope.client.processing = false
@ -145,11 +147,6 @@ app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location'
if !isSeed if !isSeed
dbg 'Done ', file dbg 'Done ', file
ngNotify.set '<b>' + file.name + '</b> ready for download', 'success' ngNotify.set '<b>' + file.name + '</b> ready for download', 'success'
if !isSeed
dbg 'Received metadata', file
ngNotify.set 'Received ' + torrent.name + ' metadata'
console.info $rootScope.client
console.info $rootScope.client
torrent.on 'download', (chunkSize) -> torrent.on 'download', (chunkSize) ->
#if !isSeed #if !isSeed
# dbg 'Downloaded chunk', torrent # dbg 'Downloaded chunk', torrent
@ -167,17 +164,10 @@ app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location'
$rootScope.onSeed = (torrent) -> $rootScope.onSeed = (torrent) ->
$rootScope.onTorrent torrent, true $rootScope.onTorrent torrent, true
if $location.hash() != ''
$rootScope.client.processing = true
setTimeout ->
dbg 'Adding ' + $location.hash()
$rootScope.client.add $location.hash(), $rootScope.onTorrent
, 0
dbg 'Ready' dbg 'Ready'
] ]
app.controller 'MainCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) -> app.controller 'FullCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) ->
ngNotify.config ngNotify.config
duration: 10000 duration: 10000
html: true html: true
@ -215,6 +205,13 @@ app.controller 'MainCtrl', ['$scope','$rootScope','$http','$log','$location', 'n
$rootScope.selectedTorrent = null $rootScope.selectedTorrent = null
else else
$rootScope.selectedTorrent = row.entity $rootScope.selectedTorrent = row.entity
if $location.hash() != ''
$rootScope.client.processing = true
setTimeout ->
dbg 'Adding ' + $location.hash()
$rootScope.client.add $location.hash(), $rootScope.onTorrent
, 0
] ]
app.controller 'DownloadCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) -> app.controller 'DownloadCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) ->
@ -225,16 +222,56 @@ app.controller 'DownloadCtrl', ['$scope','$rootScope','$http','$log','$location'
$scope.addMagnet = -> $scope.addMagnet = ->
$rootScope.addMagnet($scope.torrentInput) $rootScope.addMagnet($scope.torrentInput)
$scope.torrentInput = '' $scope.torrentInput = ''
if $location.hash() != ''
$rootScope.client.processing = true
setTimeout ->
dbg 'Adding ' + $location.hash()
$rootScope.client.add $location.hash(), $rootScope.onTorrent
, 0
] ]
app.controller 'StreamCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) -> app.controller 'ViewCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) ->
ngNotify.config ngNotify.config
duration: 10000 duration: 10000
html: true html: true
onTorrent = (torrent, isSeed) ->
dbg torrent.magnetURI
torrent.safeTorrentFileURL = torrent.torrentFileBlobURL
torrent.fileName = torrent.name + '.torrent'
$rootScope.selectedTorrent = torrent
$rootScope.client.processing = false
dbg 'Received metadata', torrent
ngNotify.set 'Received ' + torrent.name + ' metadata'
torrent.files.forEach (file) ->
file.appendTo '#viewer'
file.getBlobURL (err, url) ->
if err
throw err
file.url = url
dbg 'Done ', file
torrent.on 'download', (chunkSize) ->
# dbg 'Downloaded chunk', torrent
torrent.on 'upload', (chunkSize) ->
#dbg 'Uploaded chunk', torrent
torrent.on 'done', ->
dbg 'Done', torrent
torrent.on 'wire', (wire, addr) ->
dbg 'Wire ' + addr, torrent
torrent.on 'error', (err) ->
er err
$scope.addMagnet = -> $scope.addMagnet = ->
$rootScope.addMagnet($scope.torrentInput) $rootScope.addMagnet $scope.torrentInput, onTorrent
$scope.torrentInput = '' $scope.torrentInput = ''
if $location.hash() != ''
$rootScope.client.processing = true
setTimeout ->
dbg 'Adding ' + $location.hash()
$rootScope.client.add $location.hash(), onTorrent
, 0
] ]
app.filter 'html', ['$sce', ($sce) -> app.filter 'html', ['$sce', ($sce) ->

View file

@ -17,6 +17,9 @@ h2, h3, h4, h5, h6, ul, li
footer footer
margin-top: 10px margin-top: 10px
#viewer
margin-top: -20px
.container .container
width: 95% width: 95%
max-width: 95% max-width: 95%
@ -32,6 +35,7 @@ footer
.views .views
margin-top: -20px margin-top: -20px
margin-bottom: 10px
.download-button .download-button
margin-left: 10px margin-left: 10px

View file

@ -1,3 +0,0 @@
.container
.row
h1 Hello

16
views/view.jade Normal file
View file

@ -0,0 +1,16 @@
.container
div(ng-hide='$root.client.torrents.length != 0', style='vertical-align: middle; text-align: center')
.row
form.no-margin(ng-submit='addMagnet()')
label Enter magnet, hash or http(s) .torrent
input(type='text', placeholder='magnet, hash or http(s) .torrent', ng-model='torrentInput', ng-disabled='$root.disabled', style='width: 50%')
//button(ng-click='addMagnet()', ng-disabled='!torrentInput.length || $root.disabled', ng-class='{"button-primary": torrentInput.length}')
i.fa.fa-download
| Download
.row
label or...
button(type='file', ngf-select='$root.openTorrentFile($file)', ng-disabled='$root.disabled', ng-class='{"button-primary": !$root.disabled}')
i.fa.fa-folder-open
| Open torrent file
.div(ng-if="selectedTorrent", style="text-align: center")
| Downloaded {{$root.selectedTorrent.downloaded | pbytes}}/{{$root.selectedTorrent.length | pbytes}} ({{$root.selectedTorrent.progress | progress}}) at {{$root.selectedTorrent.downloadSpeed | pbytes:1}} from {{$root.selectedTorrent.numPeers}} peers. ETA: {{$root.selectedTorrent.timeRemaining | humanTime}}