improve loading experience

This commit is contained in:
Nate Goldman
2016-03-07 12:42:39 -08:00
parent 0d18641bcb
commit 5f0c8e86ad
3 changed files with 41 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
/* global URL, Blob */
console.time('init')
var airplay = require('airplay-js')
var chromecasts = require('chromecasts')()
var createTorrent = require('create-torrent')
@@ -49,6 +50,8 @@ loadState(init)
* the dock icon and drag+drop.
*/
function init () {
document.querySelector('.loading').remove()
// Connect to the WebTorrent and BitTorrent networks
// WebTorrent.app is a hybrid client, as explained here: https://webtorrent.io/faq
state.client = new WebTorrent()
@@ -81,14 +84,7 @@ function init () {
// OS integrations:
// ...Chromecast and Airplay
chromecasts.on('update', function (player) {
state.devices.chromecast = player
update()
})
airplay.createBrowser().on('deviceOn', function (player) {
state.devices.airplay = player
}).start()
detectDevices()
// ...drag and drop a torrent or video file to play or seed
dragDrop('body', onFiles)
@@ -121,6 +117,8 @@ function init () {
window.addEventListener('blur', function () {
state.isFocused = false
})
console.timeEnd('init')
}
// This is the (mostly) pure funtion from state -> UI. Returns a virtual DOM
@@ -213,6 +211,16 @@ function setupIpc () {
})
}
function detectDevices () {
chromecasts.on('update', function (player) {
state.devices.chromecast = player
})
airplay.createBrowser().on('deviceOn', function (player) {
state.devices.airplay = player
}).start()
}
// Load state.saved from the JSON state file
function loadState (callback) {
cfg.read(function (err, data) {