Dedupe cast.js status handlers, fix #889

This commit is contained in:
DC
2016-09-04 15:07:04 -07:00
parent f2007be1b0
commit 54882679c1

View File

@@ -126,13 +126,7 @@ function chromecastPlayer () {
} }
function status () { function status () {
ret.device.status(function (err, status) { ret.device.status(handleStatus)
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()
})
} }
function seek (time, callback) { function seek (time, callback) {
@@ -306,13 +300,7 @@ function dlnaPlayer (player) {
} }
function status () { function status () {
ret.device.status(function (err, status) { ret.device.status(handleStatus)
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()
})
} }
function seek (time, callback) { 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 // Start polling cast device state, whenever we're connected
function startStatusInterval () { function startStatusInterval () {
statusInterval = setInterval(function () { statusInterval = setInterval(function () {