happyleavesaoc/python-snapcast

Way to subscribe to the Server for new clients/groups?

airdrummingfool opened this issue · 2 comments

Hello, and thanks for this cool library! I was wondering if there was a way to subscribe to Server changes to watch for things like never-before-seen clients. Right now I can easily subscribe to updates on all clients that exist at a given point in time, but there doesn't seem to be a way to watch for new clients that get connected after that without polling. It would also be useful for clients that get deleted and groups being added/deleted.

Seems like if we fire the callback here, that should alert to not-seen-before clients. Disconnecting clients should already fire the callback.

Groups are trickier. I believe a new client is automatically joined to a new group by the snapcast server, but we as an API consumer only get a Client.OnConnect notification. At that point, we have a record of the client, but not of the associated group. Calling server.status() should then get everything updated.

I'm definitely open to suggestions, especially when it comes to group handling.

Agreed that that is the correct place to fire a callback. I've taken a stab at it in #6, but let me know if you have a different idea for it. I'm not super thrilled at having a specific callback for the one case, but the obvious alternative (having a callback that is fired whenever anything on the server changes) seems worse.

I don't actually use groups at this point, but it does seem like it would be useful to get a notification from Snapserver when a group is created or modified. Perhaps it can be gleaned from Server.OnUpdate? Since I don't use groups, I don't know whether that notification is fired when a group is created/changed.