Subscribing to events with Sonos API

后端 未结 1 1039
-上瘾入骨i
-上瘾入骨i 2021-01-25 16:55

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

1条回答
  •  后悔当初
    2021-01-25 17:42

    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}
    

    0 讨论(0)
提交回复
热议问题