Skip to content

Commit

Permalink
fix: Group events no longer worked
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan van Rooij committed May 26, 2020
1 parent 32f67bb commit 617818a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions examples/manager_events.js
@@ -0,0 +1,24 @@
const SonosManager = require('../lib/').SonosManager

const manager = new SonosManager();
manager.InitializeFromDevice(process.env.SONOS_HOST || '192.168.96.56', 1400)
.then(result => {
if(result) {
manager.Devices.forEach(d => {
console.log('Start listening for event from %s', d.Name);
d.Events.on('groupname', name => {
console.log('Device %s has a new group name %s', d.Name, name);
});
})
}
})

process.on('SIGINT', () => {
console.log('Hold-on cancelling all subscriptions')
manager.Devices.forEach(d => d.CancelEvents());
manager.CancelSubscription();

setTimeout(() => {
process.exit(0)
}, 300)
})
4 changes: 2 additions & 2 deletions src/sonos-device.ts
Expand Up @@ -45,7 +45,7 @@ export default class SonosDevice extends SonosDeviceBase {
this.coordinator = groupConfig.coordinator;
}
if (uuid) {
groupConfig.managerEvents.on(uuid, this.handleGroupUpdate);
groupConfig.managerEvents.on(uuid, this.boundHandleGroupUpdate);
}
}
}
Expand Down Expand Up @@ -566,7 +566,7 @@ export default class SonosDevice extends SonosDeviceBase {
// #endregion

// #region Group stuff
private _handleGroupUpdate = this.handleGroupUpdate.bind(this);
private boundHandleGroupUpdate = this.handleGroupUpdate.bind(this);

private handleGroupUpdate(data: { coordinator: SonosDevice | undefined; name: string}): void {
if (data.coordinator && data.coordinator.uuid !== this.uuid && (!this.coordinator || this.coordinator.uuid !== data.coordinator.uuid)) {
Expand Down

0 comments on commit 617818a

Please sign in to comment.