How to link users to presence connections ?

Hi,

I'm making a lobby system (See picture for schema)

Basically I would like to tie users connected to the Presence room of a given lobby to the lobby_player table. Because if a user isn't connected live, then it shouldn't count as part of the players.

My current idea is to have a cron job running every minute and deleting players from lobby_players where they are not part of the lobby's presence room.

Another idea would be to have an event triggered whenever someone disconnects from the Presence and remove the respective row in the table.

But currently I don't see how I could do that, it seems like we don't really have control over what goes on in Realtime channels.
image.png
Was this page helpful?