Skip to content

Commit

Permalink
Merge pull request #440 from svrooij/notifications
Browse files Browse the repository at this point in the history
Fixing Notifications for streams
  • Loading branch information
svrooij authored Aug 27, 2019
2 parents 87d6bed + 8b0cd41 commit e9be3b8
Show file tree
Hide file tree
Showing 5 changed files with 607 additions and 369 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ cache:
notifications:
email: false
node_js:
- '12'
- '10'
- '9'
- '8'
before_install:
- npm i -g npm@latest
Expand Down
4 changes: 2 additions & 2 deletions examples/playTuneinRadio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const sonos = new Sonos(process.env.SONOS_HOST || '192.168.2.11')
// This example demonstrates playing radio staions
// the Sonos built-in support for tunein radio.

// CAUTION: ID is without leading s
const stationId = '34682'
// CAUTION: ID is with leading s since version 1.12.1
const stationId = 's34682'
const stationTitle = '88.5 | Jazz24 (Jazz)'

sonos.playTuneinRadio(stationId, stationTitle).then(success => {
Expand Down
20 changes: 18 additions & 2 deletions lib/sonos.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,9 @@ Sonos.prototype.playNotification = async function (options) {
}

const mediaInfo = await this.avTransportService().GetMediaInfo()
debug('Current mediaInfo %j', mediaInfo)
const positionInfo = await this.avTransportService().GetPositionInfo()
debug('Current positionInfo %j', positionInfo)
await this.setAVTransportURI(options)
if (volume > 0) await this.setVolume(options.volume)
const self = this
Expand All @@ -900,8 +902,22 @@ Sonos.prototype.playNotification = async function (options) {
if (volume > 0) await this.setVolume(volume)
if (!wasListening) await Listener.stopListener()
await self.setAVTransportURI({ uri: mediaInfo.CurrentURI, metadata: mediaInfo.CurrentURIMetaData, onlySetUri: true })
if (positionInfo.Track > 0) await self.selectTrack(positionInfo.Track)
await self.avTransportService().Seek({ InstanceID: 0, Unit: 'REL_TIME', Target: positionInfo.RelTime })

// These statements can maybe be improved. See discussion on https://github.com/bencevans/node-sonos/pull/430
if (positionInfo.Track && positionInfo.Track > 1 && mediaInfo.NrTracks > 1) {
debug('Selecting track %j', positionInfo.Track)
await self.selectTrack(positionInfo.Track).catch(reason => {
debug('Reverting back track failed, happens for some muic services.')
})
}

if (positionInfo.RelTime && positionInfo.TrackDuration !== '0:00:00') {
debug('Setting back time to %j', positionInfo.RelTime)
await self.avTransportService().Seek({ InstanceID: 0, Unit: 'REL_TIME', Target: positionInfo.RelTime }).catch(reason => {
debug('Reverting back track time failed, happens for some muic services (radio or stream).')
})
}

if (wasPlaying) await self.play()
return true
}
Expand Down
Loading

0 comments on commit e9be3b8

Please sign in to comment.