Hi all! I’m fairly new to LiveView and am working on a simple game to get started. I’m using Phoenix.Presence
to track connected users, which was going great until I wanted to track subscriptions to multiple topics independently. I could use some help orienting myself in the right direction.
My game consists of a lobby from which players pair off to play a game together; when the game ends they’re sent back to the lobby. I want to track users in the lobby for the purpose of maintaining an up-to-date list of idle players; I also want to track players in each game “room” by subscribing them to a game:<id>
channel, mostly so that if a user disconnects I can react accordingly. The snag I’m running into is that joins/leaves result in a presence_diff
event that doesn’t seem to care which topic it originated from.
What I really want is to override outbound events and differentiate them, which with a channel would look something like this:
intercept ["presence_diff"]
def handle_out("presence_diff", message, socket) do
# send different events depending on message contents
end
… but without introducing a channel, and I haven’t found a way to do that. Barring that, I’ve considered adding the topic to tracking metadata, and then parsing the topic out in the presence_diff
payloads to determine the right behavior… but that feels complex and not really in the spirit of metadata.
Anyway, thanks for reading, and any input would be much appreciated!