From 54882679c1f1edaa3aafb0ddfb4025034dccffb0 Mon Sep 17 00:00:00 2001 From: DC Date: Sun, 4 Sep 2016 15:07:04 -0700 Subject: [PATCH] Dedupe cast.js status handlers, fix #889 --- src/renderer/lib/cast.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/renderer/lib/cast.js b/src/renderer/lib/cast.js index 9cb9c6d7f4..9b63e4341e 100644 --- a/src/renderer/lib/cast.js +++ b/src/renderer/lib/cast.js @@ -126,13 +126,7 @@ function chromecastPlayer () { } function status () { - ret.device.status(function (err, status) { - if (err) return console.log('error getting %s status: %o', state.playing.location, err) - state.playing.isPaused = status.playerState === 'PAUSED' - state.playing.currentTime = status.currentTime - state.playing.volume = status.volume.muted ? 0 : status.volume.level - update() - }) + ret.device.status(handleStatus) } function seek (time, callback) { @@ -306,13 +300,7 @@ function dlnaPlayer (player) { } function status () { - ret.device.status(function (err, status) { - if (err) return console.log('error getting %s status: %o', state.playing.location, err) - state.playing.isPaused = status.playerState === 'PAUSED' - state.playing.currentTime = status.currentTime - state.playing.volume = status.volume.level - update() - }) + ret.device.status(handleStatus) } function seek (time, callback) { @@ -328,6 +316,18 @@ function dlnaPlayer (player) { } } +function handleStatus (err, status) { + if (err || !status) { + return console.log('error getting %s status: %o', + state.playing.location, + err || 'missing response') + } + state.playing.isPaused = status.playerState === 'PAUSED' + state.playing.currentTime = status.currentTime + state.playing.volume = status.volume.muted ? 0 : status.volume.level + update() +} + // Start polling cast device state, whenever we're connected function startStatusInterval () { statusInterval = setInterval(function () {