Answered

Notifications: How to detect volume changes from other client

  • 21 October 2016
  • 1 reply
  • 940 views

Badge
How to receive a notification (or whatever) when the volume is changed by any client on the network.
I am ok in opening a socket, which seems to be the way it travels over the network but I don't know what
the frame will look like.

I can control many functions of my Sonos using the POST apis.
That is one thing that I can't figure out.

Any help on the matter is much appreciated!

thx
icon

Best answer by jishi 22 October 2016, 01:19

View original

This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.

1 reply

Userlevel 4
Badge +14
The "notifications" are standard UPnP events, which basically works like this:

a controller (your device) subscribes to events by sending an HTTP request to the player in question, with information about endpoint to send notifications to (which would receive standard UPnP SOAP request), and also for how long (timeout). That endpoint needs to be alive and respond with a 200 OK at this time, since it would be tested for availability (IIRC) and also send the first event immediately.

Once that is done, ever ytime a volume change is made, it would send a request with verb NOTIFY and a UPnP body with one or more event tags, which you would be able to parse.

Before the timeout occurs, you would need to re-subscribe once again, and preferably provide the "sid" (subscription ID) you received when subscribing the first time. If this fail, you would need to subscribe from scratch again.

If you want to see some samples of the data, you can look at these mocks I use for my tests:

An actual subscribe request: https://gist.github.com/jishi/66ed97e69edddb1a036dd6b515030bd2
Volume event request: https://gist.github.com/jishi/f6f760ca3a84ea992ac405a266970eb1

It might also be wise to unsubscribe gracefully if possible, by sending a UNSUBSCRIBE verb with the SID header in the request.

Hope that helps!