Skip to content

Commit

Permalink
Dedupe cast.js status handlers, fix #889
Browse files Browse the repository at this point in the history
  • Loading branch information
dcposch committed Sep 4, 2016
1 parent f2007be commit 5488267
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/renderer/lib/cast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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 () {
Expand Down

0 comments on commit 5488267

Please sign in to comment.