postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
882 stars 96 forks source link

Use feedback instead of metadata for keep-alive in RAOP #1107

Closed postlund closed 3 years ago

postlund commented 3 years ago

Short feature/function description I currently send metadata periodically in RAOP to keep the connection alive according to a post I found over at owntone. But there's actually a feedback endpoint dedicated for this purpose, so I should move over to that instead.

What needs to be done?

Is this a breaking change? No

Anything else worth knowing? No

Schlaubischlump commented 3 years ago

The feedback endpoint is not available on older devices / firmware versions, is it ? What happens if a request is send to a device, which does not support the endpoint ?

It would be a good idea to either check the ANNOUNCE response to see if the feedback endpoint is available and only send it if required or send and OPTIONS request every 30 seconds as heartbeat like RAOP-Player does. OPTIONS is always available, no matter how outdated the firmware or device is.

postlund commented 3 years ago

Right, that might be true of course. Would be interesting to know when it was introduced. Anyways, it's probably hard to see if it's supported as it's a POST request. OPTIONS will contain POST if that's supported, but that might not necessary mean that the /feedback endpoint is available. I'm leaning towards using the feedback method as I find that to be cleaner and let potential problems emerge as an issue later.

Schlaubischlump commented 3 years ago

Good point, that makes it indeed very hard to detect if the 'feedback' endpoint is available. Sadly there is not much information about the endpoint out there. First time I read about it was around the time iOS 11.4 for the original Homepod came out. Maybe its part of the Airplay 2 protocol specification and not part of the original AirTunes v2. I'm not sure.

Like you said, keeping the future in mind, it might be best to just use it and see if it causes any problems down the road for any device.

postlund commented 3 years ago

I can confirm that the presence of POST does not necessarily mean that /feedback is supported. My old Yamaha receiver has AirPlay support (AirTunes v2 I presume) and it reports that POST is supported:

2021-05-31 14:01:35 DEBUG [pyatv.support.http]: Sending RTSP/1.0 message: b'OPTIONS * RTSP/1.0\r\nUser-Agent: AirPlay/540.31\r\nCSeq: 1\r\nDACP-ID: 27737845AA20C901\r\nActive-Remote: 1857361097\r\nClient-Instance: 27737845AA20C901\r\n\r\n'
2021-05-31 14:01:35 DEBUG [pyatv.support.http]: Received: b'RTSP/1.0 200 OK\r\nPublic: ANNOUNCE, SETUP, RECORD, PAUSE, FLUSH, TEARDOWN, OPTIONS, GET_PARAMETER, SET_PARAMETER, POST, GET\r\nServer: AirTunes/103.2\r\nCSeq: 1\r\n\r\n'

Sending feedback is not however:

2021-05-31 14:01:07 DEBUG [pyatv.support.http]: Sending RTSP/1.0 message: b'POST /feedback RTSP/1.0\r\nUser-Agent: AirPlay/540.31\r\nCSeq: 1\r\nDACP-ID: B5B21A57B164B24A\r\nActive-Remote: 2199282051\r\nClient-Instance: B5B21A57B164B24A\r\n\r\n'
2021-05-31 14:01:07 DEBUG [pyatv.support.http]: Received: b'RTSP/1.0 501 Not Implemented\r\nServer: AirTunes/103.2\r\nCSeq: 1\r\n\r\n'

So, that puts me in the spot that I need different methods of sending keep-alive messages depending on what is supported. I guess I can just try to call /feedback and use the response to determine what method to use.

Schlaubischlump commented 3 years ago

Is it even necessary to send a feedback request on these old devices ? In my experience only the homepod and homepod mini require the keep-alive signal. Shouldn't, check if feedback produces a valid response, otherwise do not send any more feedback signals be enough ?

postlund commented 3 years ago

Yeah, that sounds even more correct now when you say it. That's what I will do 👍 But first I'm gonna do some work on a fake device so I can get at least some basic functional tests up and running.

postlund commented 3 years ago

Fixed by #1119.