Custom video controls + button to delete torrents

Also:
* Clean up the state object a bit
* Simplify, factor out torrent-list.js
This commit is contained in:
DC
2016-03-03 08:40:59 -08:00
parent d72999df57
commit 28948e0dbc
4 changed files with 193 additions and 70 deletions

View File

@@ -29,7 +29,8 @@ global.WEBTORRENT_ANNOUNCE = createTorrent.announceList
})
var state = global.state = {
server: null,
server: null, /* local WebTorrent-to-HTTP server */
player: null, /* 'local', 'airplay', or 'chromecast'. persists across videos */
view: {
url: '/',
dock: {
@@ -37,15 +38,18 @@ var state = global.state = {
progress: 0
},
devices: {
airplay: null,
chromecast: null
airplay: null, /* airplay client. finds and manages AppleTVs */
chromecast: null /* chromecast client. finds and manages Chromecasts */
},
client: null, // TODO: remove this
// history: [],
client: null, /* the WebTorrent client */
// history: [], /* track how we got to the current view. enables Back button */
// historyIndex: 0,
isFocused: true,
mainWindowBounds: null,
title: 'WebTorrent'
mainWindowBounds: null, /* x y width height */
title: 'WebTorrent' /* current window title */
},
video: {
isPaused: false
}
}
@@ -129,6 +133,9 @@ function dispatch (action, ...args) {
if (action === 'openPlayer') {
openPlayer(args[0] /* torrent */)
}
if (action === 'deleteTorrent') {
deleteTorrent(args[0] /* torrent */)
}
if (action === 'openChromecast') {
openChromecast(args[0] /* torrent */)
}
@@ -146,6 +153,10 @@ function dispatch (action, ...args) {
state.view.url = '/'
update()
}
if (action === 'playPause') {
state.video.isPaused = !state.video.isPaused
update()
}
}
electron.ipcRenderer.on('addTorrent', function (e, torrentId) {
@@ -243,6 +254,16 @@ function openPlayer (torrent) {
})
}
function deleteTorrent (torrent) {
console.log('Deleting %o', torrent)
torrent.isDeleting = true
update()
state.view.client.remove(torrent.infoHash, function () {
console.log('Deleted torrent ' + torrent.infoHash)
update()
})
}
function openChromecast (torrent) {
startServer(torrent, function () {
state.view.chromecast.play(state.server.networkURL, { title: 'WebTorrent — ' + torrent.name })