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:
Feross Aboukhadijeh
2016-04-05 23:12:23 -07:00
committed by DC
parent 292898de9e
commit 8629fc956d
5 changed files with 35 additions and 30 deletions

View File

@@ -81,10 +81,10 @@ function init () {
if (name.startsWith('wt-')) { if (name.startsWith('wt-')) {
if (e.sender.browserWindowOptions.title === 'webtorrent-hidden-window') { if (e.sender.browserWindowOptions.title === 'webtorrent-hidden-window') {
windows.main.send(name, ...args) windows.main.send(name, ...args)
log('webtorrent ipc: sent %s', name) log('webtorrent: got %s', name)
} else { } else {
windows.webtorrent.send(name, ...args) windows.webtorrent.send(name, ...args)
log('webtorrent ipc: receieved %s', name) log('webtorrent: sent %s', name)
} }
return return
} }

View File

@@ -82,7 +82,7 @@ function createMainWindow () {
backgroundColor: '#282828', backgroundColor: '#282828',
darkTheme: true, // Forces dark theme (GTK+3) darkTheme: true, // Forces dark theme (GTK+3)
icon: config.APP_ICON + '.png', icon: config.APP_ICON + '.png',
minWidth: 375, minWidth: 425,
minHeight: 38 + (120 * 2), // header height + 2 torrents minHeight: 38 + (120 * 2), // header height + 2 torrents
show: false, // Hide window until DOM finishes loading show: false, // Hide window until DOM finishes loading
title: config.APP_WINDOW_TITLE, title: config.APP_WINDOW_TITLE,

View File

@@ -207,8 +207,8 @@ function dispatch (action, ...args) {
if (action === 'openDevice') { if (action === 'openDevice') {
lazyLoadCast().open(args[0] /* deviceType */) lazyLoadCast().open(args[0] /* deviceType */)
} }
if (action === 'stopCasting') { if (action === 'closeDevice') {
lazyLoadCast().stopCasting() lazyLoadCast().close()
} }
if (action === 'setDimensions') { if (action === 'setDimensions') {
setDimensions(args[0] /* dimensions */) setDimensions(args[0] /* dimensions */)

View File

@@ -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 // The Cast module talks to Airplay and Chromecast
// * Modifies state when things change // * Modifies state when things change
// * Starts and stops casting, provides remote video controls // * Starts and stops casting, provides remote video controls
module.exports = { module.exports = {
init, init,
open, open,
stopCasting, close,
playPause, playPause,
seek, seek,
setVolume 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 // Callback to notify module users when state has changed
var update var update
var statusInterval = null
// chromecast player implementation // chromecast player implementation
function chromecastPlayer (player) { function chromecastPlayer (player) {
function addEvents () { function addEvents () {
@@ -65,7 +67,7 @@ function chromecastPlayer (player) {
player.stop(callback) player.stop(callback)
} }
function status (state) { function status () {
player.status(function (err, status) { player.status(function (err, status) {
if (err) return console.log('error getting %s status: %o', state.playing.location, err) if (err) return console.log('error getting %s status: %o', state.playing.location, err)
state.playing.isPaused = status.playerState === 'PAUSED' state.playing.isPaused = status.playerState === 'PAUSED'
@@ -122,7 +124,7 @@ function airplayPlayer (player) {
player.stop(callback) player.stop(callback)
} }
function status (state) { function status () {
player.status(function (status) { player.status(function (status) {
state.playing.isPaused = status.rate === 0 state.playing.isPaused = status.rate === 0
state.playing.currentTime = status.position state.playing.currentTime = status.position
@@ -201,7 +203,7 @@ function dlnaPlayer (player) {
player.stop(callback) player.stop(callback)
} }
function status (state) { function status () {
player.status(function (err, status) { player.status(function (err, status) {
if (err) return console.log('error getting %s status: %o', state.playing.location, err) if (err) return console.log('error getting %s status: %o', state.playing.location, err)
state.playing.isPaused = status.playerState === 'PAUSED' state.playing.isPaused = status.playerState === 'PAUSED'
@@ -240,9 +242,6 @@ function dlnaPlayer (player) {
function init (callback) { function init (callback) {
update = callback update = callback
// Start polling Chromecast or Airplay, whenever we're connected
setInterval(() => pollCastStatus(state), 1000)
// Listen for devices: Chromecast, DLNA and Airplay // Listen for devices: Chromecast, DLNA and Airplay
chromecasts.on('update', function (player) { chromecasts.on('update', function (player) {
state.devices.chromecast = chromecastPlayer(player) state.devices.chromecast = chromecastPlayer(player)
@@ -258,12 +257,14 @@ function init (callback) {
}).start() }).start()
} }
// Update our state from the remote TV // Start polling cast device state, whenever we're connected
function pollCastStatus (state) { function startStatusInterval () {
var device = getDevice() statusInterval = setInterval(function () {
if (device) { var device = getDevice()
device.status(state) if (device) {
} device.status()
}
}, 1000)
} }
function open (location) { function open (location) {
@@ -275,16 +276,18 @@ function open (location) {
var device = getDevice(location) var device = getDevice(location)
if (device) { if (device) {
getDevice(location).open() getDevice(location).open()
startStatusInterval()
} }
update() update()
} }
// Stops Chromecast or Airplay, move video back to local screen // Stops casting, move video back to local screen
function stopCasting () { function close () {
var device = getDevice() var device = getDevice()
if (device) { if (device) {
device.stop(stoppedCasting) device.stop(stoppedCasting)
clearInterval(statusInterval)
} else { } else {
stoppedCasting() stoppedCasting()
} }
@@ -305,6 +308,8 @@ function getDevice (location) {
return state.devices.airplay return state.devices.airplay
} else if (state.playing.location === 'dlna') { } else if (state.playing.location === 'dlna') {
return state.devices.dlna return state.devices.dlna
} else {
return null
} }
} }

View File

@@ -245,7 +245,7 @@ function renderPlayerControls (state) {
chromecastClass = 'active' chromecastClass = 'active'
dlnaClass = 'disabled' dlnaClass = 'disabled'
airplayClass = 'disabled' airplayClass = 'disabled'
chromecastHandler = dispatcher('stopCasting') chromecastHandler = dispatcher('closeDevice')
airplayHandler = undefined airplayHandler = undefined
dlnaHandler = undefined dlnaHandler = undefined
} else if (isOnAirplay) { } else if (isOnAirplay) {
@@ -253,7 +253,7 @@ function renderPlayerControls (state) {
dlnaClass = 'disabled' dlnaClass = 'disabled'
airplayClass = 'active' airplayClass = 'active'
chromecastHandler = undefined chromecastHandler = undefined
airplayHandler = dispatcher('stopCasting') airplayHandler = dispatcher('closeDevice')
dlnaHandler = undefined dlnaHandler = undefined
} else if (isOnDlna) { } else if (isOnDlna) {
chromecastClass = 'disabled' chromecastClass = 'disabled'
@@ -261,7 +261,7 @@ function renderPlayerControls (state) {
airplayClass = 'disabled' airplayClass = 'disabled'
chromecastHandler = undefined chromecastHandler = undefined
airplayHandler = undefined airplayHandler = undefined
dlnaHandler = dispatcher('stopCasting') dlnaHandler = dispatcher('closeDevice')
} else { } else {
chromecastClass = '' chromecastClass = ''
airplayClass = '' airplayClass = ''