Closed hklages closed 3 years ago
You can call device.CancelEvents()
on the device. https://github.com/svrooij/node-sonos-ts/blob/eeb96398689ae79972f7a3717e446a7453022f78/src/sonos-device.ts#L524
But the easiest way is to just remove your listener from the event emitter.
Check-out the sample here
here is the code that triggers the unsubscribe if you remove the last listener.
Hi. I did some debugging.
To subscribe: works fine:
player.ZoneGroupTopologyService.Events.on(ServiceEvents.Data, data => { ... })
to unsubscribe: does not work
const x = await player.ZoneGroupTopologyService.Events.removeAllListeners(ServiceEvents.Data)
console.log('subscription canceled' + JSON.stringify(x))
Result: subscription canceled{"_events":{},"_eventsCount":2}
So the method was executed but when looking at the modified /status I get:
my code modification to see all subscribtions: subscrptionCount: Object.keys(this.subscriptions),
Result:
{"host":"192.168.178.61","port":6329,"subscriptionUrl":"http://192.168.178.61:6329/sonos/{sonos-uuid}/{serviceName}","listeningSince":"2020-12-19T07:30:15.782Z","subscrptionCount":["uuid:RINCON_949F3EC13B9901400_sub0000004382","uuid:RINCON_949F3EC13B9901400_sub0000004383"]}
So it seems that
If you remove all listeners from the .Events it does unsubscribe from the service. That is why you see that if you re-subscribe a new subscription is created.
I never bothered to remove the old subscription link from the SonosEventListener (the array that is counted with the status endpoint) because the array was only used to deliver the events to the right service. And since the old subscriptions where removed from the speakers no new events would be delivered on that service.
The entries in the array are just all subscriptions, even if it automatically unsubscribed. They won’t get any events (because the the code already cancelled the subscription at the speaker). I agree that the status endpoint doesn’t respond with the correct information, but keep in mind that it is just for debugging. Since the subscriptions are actually cancelled correctly, you can check with the in the debug logging.
OK. Understand. I close this issue.
I suggest to replace the last line by
subscriptionHistory: Object.keys(this.subscriptions)
or subscriptionHistoryLength.
Summary:
:tada: This issue has been resolved in version 2.2.0-beta.7 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 2.3.0-beta.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 2.3.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Hi - me again :-) I just installed 2.2.0.
How to unsubscribe?
This code (the volume is only to demonstrate, that player is defined)
produces: