Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function addDevice (device) {
log.info('Add device %s %s', device.Name, device.host)
// Start listening for those events!
device.Events.on(SonosEvents.CurrentTrack, trackUri => {
publishTrackUri(device, trackUri)
})
device.Events.on(SonosEvents.CurrentTrackMetadata, metadata => {
publishCurrentTrack(device, metadata)
})
device.Events.on(SonosEvents.CurrentTransportStateSimple, state => {
publishState(device, state)
})
device.Events.on(SonosEvents.Mute, muted => {
publishMuted(device, muted)
})
device.Events.on(SonosEvents.Volume, volume => {
publishVolume(device, volume)
})
device.Events.on(SonosEvents.GroupName, groupName => {
publishData(`${config.name}/status/${cleanName(device.Name)}/group`, groupName, cleanName(device.Name), true)
})
function cancelSubscriptions (device) {
device.Events.removeAllListeners(SonosEvents.CurrentTrack)
device.Events.removeAllListeners(SonosEvents.CurrentTrackMetadata)
device.Events.removeAllListeners(SonosEvents.CurrentTransportState)
device.Events.removeAllListeners(SonosEvents.Mute)
device.Events.removeAllListeners(SonosEvents.Volume)
}