Closed bhelx closed 7 years ago
Thanks for reporting this. There is currently no way to be notified of reconnects.
The problem is that the supervision hierarchy is structured such that if MPDClient
dies, PlayerState
dies (and forgets its subscribers). So instead of detecting reconnects to allow users to resubscribe after each reconnect, I would rather change the supervision hierarchy to make PlayerState
independent of MpdClient
.
I'm going to change this and push a new release to hex.pm soon.
@nroi thanks for looking into it! Another option might be to store the state of subscribers outside of PlayerState (maybe in an ETS table or an Agent). That way if PlayerState does die for an unexpected reason, you still have the system's state.
Good point. I don't like the idea of using ETS, because I would have to use a globally shared :public
table, but using an Agent where the PID is only known to the main process and the PlayerState
process seems acceptable.
The fix is already on the master branch, I'll see if anything unexpected happens and, if not, close this and push a new version to hex.pm.
Thanks a bunch! Going to try this out tonight.
I am currently using
Paracusia.PlayerState.subscribe/1
in a GenServer just as described with yourParacusia.DefaultEventHandler
. If mpd dies, the paracusia application properly recovers but I no longer get updates to my event handler. I believe that is because I'll need tosubscribe/1
again after reconnect. Is there some way I can detect that the MpdClient has reconnected? Or can you think of another way I can get this event handler to resubscribe?