move renderer state into new file

This commit is contained in:
Feross Aboukhadijeh
2016-03-05 19:52:16 -08:00
parent e78716b0fa
commit c01fb66bae
2 changed files with 59 additions and 55 deletions

View File

@@ -9,6 +9,7 @@ var EventEmitter = require('events')
var mainLoop = require('main-loop')
var networkAddress = require('network-address')
var path = require('path')
var state = require('./state')
var throttle = require('throttleit')
var torrentPoster = require('./lib/torrent-poster')
var WebTorrent = require('webtorrent')
@@ -30,68 +31,18 @@ global.WEBTORRENT_ANNOUNCE = createTorrent.announceList
return url.indexOf('wss://') === 0 || url.indexOf('ws://') === 0
})
var state = global.state = {
/* Temporary state disappears once the program exits.
* It can contain complex objects like open connections, etc.
*/
url: '/',
client: null, /* the WebTorrent client */
server: null, /* local WebTorrent-to-HTTP server */
dock: {
badge: 0,
progress: 0
},
devices: {
airplay: null, /* airplay client. finds and manages AppleTVs */
chromecast: null /* chromecast client. finds and manages Chromecasts */
},
torrentPlaying: null, /* the torrent we're streaming. see client.torrents */
// history: [], /* track how we got to the current view. enables Back button */
// historyIndex: 0,
isFocused: true,
isFullScreen: false,
mainWindowBounds: null, /* x y width height */
title: 'WebTorrent', /* current window title */
video: {
isPaused: false,
currentTime: 0, /* seconds */
duration: 1, /* seconds */
mouseStationarySince: 0 /* Unix time in ms */
},
/* Saved state is read from and written to ~/.webtorrent/state.json
* It should be simple and minimal and must be JSONifiable
*/
saved: {
torrents: [
{
name: 'Elephants Dream',
torrentFile: 'resources/ElephantsDream_archive.torrent'
},
{
name: 'Big Buck Bunny',
torrentFile: 'resources/BigBuckBunny_archive.torrent'
},
{
name: 'Sintel',
torrentFile: 'resources/Sintel_archive.torrent'
},
{
name: 'Tears of Steel',
torrentFile: 'resources/TearsOfSteel_archive.torrent'
}
]
}
}
var client, vdomLoop, updateThrottled
function init () {
client = global.client = new WebTorrent()
client = new WebTorrent()
client.on('warning', onWarning)
client.on('error', onError)
state.client = client
// For easy debugging in Developer Tools
global.client = client
global.state = state
vdomLoop = mainLoop(state, render, {
create: createElement,
diff: diff,

53
renderer/state.js Normal file
View File

@@ -0,0 +1,53 @@
module.exports = {
/* Temporary state disappears once the program exits.
* It can contain complex objects like open connections, etc.
*/
url: '/',
client: null, /* the WebTorrent client */
server: null, /* local WebTorrent-to-HTTP server */
dock: {
badge: 0,
progress: 0
},
devices: {
airplay: null, /* airplay client. finds and manages AppleTVs */
chromecast: null /* chromecast client. finds and manages Chromecasts */
},
torrentPlaying: null, /* the torrent we're streaming. see client.torrents */
// history: [], /* track how we got to the current view. enables Back button */
// historyIndex: 0,
isFocused: true,
isFullScreen: false,
mainWindowBounds: null, /* x y width height */
title: 'WebTorrent', /* current window title */
video: {
isPaused: false,
currentTime: 0, /* seconds */
duration: 1, /* seconds */
mouseStationarySince: 0 /* Unix time in ms */
},
/* Saved state is read from and written to ~/.webtorrent/state.json
* It should be simple and minimal and must be JSONifiable
*/
saved: {
torrents: [
{
name: 'Elephants Dream',
torrentFile: 'resources/ElephantsDream_archive.torrent'
},
{
name: 'Big Buck Bunny',
torrentFile: 'resources/BigBuckBunny_archive.torrent'
},
{
name: 'Sintel',
torrentFile: 'resources/Sintel_archive.torrent'
},
{
name: 'Tears of Steel',
torrentFile: 'resources/TearsOfSteel_archive.torrent'
}
]
}
}