clear cast interval when casting stops; naming
* fix ipc logs * minWidth 425 So title "WebTorrent (BETA)" doesn't get cut off * clear cast interval when casting stops; naming Fix #300
This commit is contained in:
@@ -81,10 +81,10 @@ function init () {
|
||||
if (name.startsWith('wt-')) {
|
||||
if (e.sender.browserWindowOptions.title === 'webtorrent-hidden-window') {
|
||||
windows.main.send(name, ...args)
|
||||
log('webtorrent ipc: sent %s', name)
|
||||
log('webtorrent: got %s', name)
|
||||
} else {
|
||||
windows.webtorrent.send(name, ...args)
|
||||
log('webtorrent ipc: receieved %s', name)
|
||||
log('webtorrent: sent %s', name)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ function createMainWindow () {
|
||||
backgroundColor: '#282828',
|
||||
darkTheme: true, // Forces dark theme (GTK+3)
|
||||
icon: config.APP_ICON + '.png',
|
||||
minWidth: 375,
|
||||
minWidth: 425,
|
||||
minHeight: 38 + (120 * 2), // header height + 2 torrents
|
||||
show: false, // Hide window until DOM finishes loading
|
||||
title: config.APP_WINDOW_TITLE,
|
||||
|
||||
@@ -207,8 +207,8 @@ function dispatch (action, ...args) {
|
||||
if (action === 'openDevice') {
|
||||
lazyLoadCast().open(args[0] /* deviceType */)
|
||||
}
|
||||
if (action === 'stopCasting') {
|
||||
lazyLoadCast().stopCasting()
|
||||
if (action === 'closeDevice') {
|
||||
lazyLoadCast().close()
|
||||
}
|
||||
if (action === 'setDimensions') {
|
||||
setDimensions(args[0] /* dimensions */)
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
var chromecasts = require('chromecasts')()
|
||||
var airplay = require('airplay-js')
|
||||
var dlnacasts = require('dlnacasts')()
|
||||
|
||||
var config = require('../../config')
|
||||
var state = require('../state')
|
||||
|
||||
// The Cast module talks to Airplay and Chromecast
|
||||
// * Modifies state when things change
|
||||
// * Starts and stops casting, provides remote video controls
|
||||
module.exports = {
|
||||
init,
|
||||
open,
|
||||
stopCasting,
|
||||
close,
|
||||
playPause,
|
||||
seek,
|
||||
setVolume
|
||||
}
|
||||
|
||||
var airplay = require('airplay-js')
|
||||
var chromecasts = require('chromecasts')()
|
||||
var dlnacasts = require('dlnacasts')()
|
||||
|
||||
var config = require('../../config')
|
||||
var state = require('../state')
|
||||
|
||||
// Callback to notify module users when state has changed
|
||||
var update
|
||||
|
||||
var statusInterval = null
|
||||
|
||||
// chromecast player implementation
|
||||
function chromecastPlayer (player) {
|
||||
function addEvents () {
|
||||
@@ -65,7 +67,7 @@ function chromecastPlayer (player) {
|
||||
player.stop(callback)
|
||||
}
|
||||
|
||||
function status (state) {
|
||||
function status () {
|
||||
player.status(function (err, status) {
|
||||
if (err) return console.log('error getting %s status: %o', state.playing.location, err)
|
||||
state.playing.isPaused = status.playerState === 'PAUSED'
|
||||
@@ -122,7 +124,7 @@ function airplayPlayer (player) {
|
||||
player.stop(callback)
|
||||
}
|
||||
|
||||
function status (state) {
|
||||
function status () {
|
||||
player.status(function (status) {
|
||||
state.playing.isPaused = status.rate === 0
|
||||
state.playing.currentTime = status.position
|
||||
@@ -201,7 +203,7 @@ function dlnaPlayer (player) {
|
||||
player.stop(callback)
|
||||
}
|
||||
|
||||
function status (state) {
|
||||
function status () {
|
||||
player.status(function (err, status) {
|
||||
if (err) return console.log('error getting %s status: %o', state.playing.location, err)
|
||||
state.playing.isPaused = status.playerState === 'PAUSED'
|
||||
@@ -240,9 +242,6 @@ function dlnaPlayer (player) {
|
||||
function init (callback) {
|
||||
update = callback
|
||||
|
||||
// Start polling Chromecast or Airplay, whenever we're connected
|
||||
setInterval(() => pollCastStatus(state), 1000)
|
||||
|
||||
// Listen for devices: Chromecast, DLNA and Airplay
|
||||
chromecasts.on('update', function (player) {
|
||||
state.devices.chromecast = chromecastPlayer(player)
|
||||
@@ -258,12 +257,14 @@ function init (callback) {
|
||||
}).start()
|
||||
}
|
||||
|
||||
// Update our state from the remote TV
|
||||
function pollCastStatus (state) {
|
||||
var device = getDevice()
|
||||
if (device) {
|
||||
device.status(state)
|
||||
}
|
||||
// Start polling cast device state, whenever we're connected
|
||||
function startStatusInterval () {
|
||||
statusInterval = setInterval(function () {
|
||||
var device = getDevice()
|
||||
if (device) {
|
||||
device.status()
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
function open (location) {
|
||||
@@ -275,16 +276,18 @@ function open (location) {
|
||||
var device = getDevice(location)
|
||||
if (device) {
|
||||
getDevice(location).open()
|
||||
startStatusInterval()
|
||||
}
|
||||
|
||||
update()
|
||||
}
|
||||
|
||||
// Stops Chromecast or Airplay, move video back to local screen
|
||||
function stopCasting () {
|
||||
// Stops casting, move video back to local screen
|
||||
function close () {
|
||||
var device = getDevice()
|
||||
if (device) {
|
||||
device.stop(stoppedCasting)
|
||||
clearInterval(statusInterval)
|
||||
} else {
|
||||
stoppedCasting()
|
||||
}
|
||||
@@ -305,6 +308,8 @@ function getDevice (location) {
|
||||
return state.devices.airplay
|
||||
} else if (state.playing.location === 'dlna') {
|
||||
return state.devices.dlna
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ function renderPlayerControls (state) {
|
||||
chromecastClass = 'active'
|
||||
dlnaClass = 'disabled'
|
||||
airplayClass = 'disabled'
|
||||
chromecastHandler = dispatcher('stopCasting')
|
||||
chromecastHandler = dispatcher('closeDevice')
|
||||
airplayHandler = undefined
|
||||
dlnaHandler = undefined
|
||||
} else if (isOnAirplay) {
|
||||
@@ -253,7 +253,7 @@ function renderPlayerControls (state) {
|
||||
dlnaClass = 'disabled'
|
||||
airplayClass = 'active'
|
||||
chromecastHandler = undefined
|
||||
airplayHandler = dispatcher('stopCasting')
|
||||
airplayHandler = dispatcher('closeDevice')
|
||||
dlnaHandler = undefined
|
||||
} else if (isOnDlna) {
|
||||
chromecastClass = 'disabled'
|
||||
@@ -261,7 +261,7 @@ function renderPlayerControls (state) {
|
||||
airplayClass = 'disabled'
|
||||
chromecastHandler = undefined
|
||||
airplayHandler = undefined
|
||||
dlnaHandler = dispatcher('stopCasting')
|
||||
dlnaHandler = dispatcher('closeDevice')
|
||||
} else {
|
||||
chromecastClass = ''
|
||||
airplayClass = ''
|
||||
|
||||
Reference in New Issue
Block a user