hifiberry / audiocontrol2

A controller application that can handle multiple concurrent media players
MIT License
48 stars 20 forks source link

Bidirectional communication API #20

Closed schnabel closed 2 years ago

schnabel commented 3 years ago

HI, I would like to improve the way clients can interact with hifiberry OS. In my case it is the integration into homeassistant. Polling the REST API for changes in the audiocontrol state is not the best approach. It would be great if there was an websocket API. I could try to offer an implementation using python-socketio.

hifiberry commented 3 years ago

Feel free to try and send a pull. As this won't be used by many users, please make sure it's disabled by default and the service will run without this. Only import additional modules if the websocket API is enabled.

schnabel commented 3 years ago

Hi, thanks for your interest. My first idea was to integrate the new API with the bottle server like in this gist because python-socketio supports it. That way the footprint would be small. As I understand you, being able to disable the API and using conditional imports is a MUST. Then I would go for a new daemon thread.

hifiberry commented 3 years ago

As audiocontrol is already using bottle, I would not recommend to run a second server on another port. Just extend the existing server, but make sure the additional functionality needs to be enabled in the configuration file.

schnabel commented 3 years ago

I am having trouble to test my code :-(. Not sure if a should open a bug report in hifiberry os or if you can help me here. I get an error when I try to build the hifiberry-os because of the python keyboard package. It seems to require root privileges because it calls dumpkeys. I tried to add the user I build with to tty and input group as suggested but that did not help. Do you have any idea what to do?

hifiberry commented 2 years ago

CHanges have been merged

schnabel commented 2 years ago

Thanks a lot!