Subscribing to events with Sonos API

核能气质少年 提交于 2020-07-10 03:23:15

问题


I'm in the process of building a Sonos iPhone app with Swift using the Sonos API but have hit a stumbling block. I would like to detect when a state/volume / metadata change on my app when someone uses a different app or the hardware buttons. I believe that subscribing to events is the way forward. I have copied in the reference link below.

  • Subscribe—Subscribe to group namespaces to receive events when states change, such as changes to volume or playback status.

https://developer.sonos.com/build/direct-control/connect/

I send a HTTP POST to the subscription path as described and get a 200 ok response back but have no idea what to do next. I've been using Xcode and testing in Postman. The callback url is registered on the developer site and OAuth token is verified.

Any help would be greatly appreciated.

Thanks, Paul


回答1:


You must host a service to receive events. Your server should satisfy all of these requirements:

  • Support at least HTTP 1.1 with persistent connections (“keep-alive”). This is important to maintain the flow of data going back and forth between Sonos and your client.
  • Support secure HTTP with SSL/TLS v1.2.
  • Have a valid and trusted CA-signed X.509 certificate for the DNS name.

Your event service should also verify the X-Sonos-Event-Signature of each event it receives. See Subscribe on the Sonos developer portal for details.

Enter your callback URL in the form field for your Control integration.

You should receive an HTTP POST to your callback URL when states change in the namespace to which you subscribed. For example, if you subscribed to the groupVolume namespace for a group, you should receive a group volume event when the group volume changes. Try changing the group volume in the Sonos app and verify that your callback URL gets an event.

Here's a sample group volume event from the documentation, sent after a change in the volume state:

    POST {YOUR_CALLBACK_BASE_URL} HTTP/1.1
    Content-Type: application/json
    Content-Length: 41
    X-Sonos-Household-Id: Sonos_1234567890
    X-Sonos-Event-Seq-Id: 1234
    X-Sonos-Event-Signature: 90192js8cjhvd7ebcjsfdfw
    X-Sonos-Namespace: groupVolume
    X-Sonos-Type: groupVolume
    X-Sonos-Target-Type: groupId
    X-Sonos-Target-Value: RINCON_00012345678001400:0
    {"volume":16,"muted":false,"fixed":false}


来源:https://stackoverflow.com/questions/57189170/subscribing-to-events-with-sonos-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!