Tracking Presence across sockets

I currently have 2 sockets each handling only one channel. One of the channels is for users and each user has its own sub-topic. The other channel is an admin channel and they all share a subtopic since I don’t care who the admin is, they all get the same. Everything works and any new update from the users gets relayed to the admins so they always get the information, but now I want to track those users’ Presence and send it to the admins.

What I currently have working is:
I track each user when they join the Channel. I can then do push(,, Presence.list(“user:#{uid}”) and I receive the data. But since I have multiple users, I’d have to map the currently connected users and do a push for each one (and I’m not sure how to get a list of presences). My other option is to just handle everything on the user channel and use PubSub to send the new presence to the admin channel which would then push it down to the admin client. I just wanted to verify if there’s an easier way to do this or if my current ideas are ok.


After a lot of open tabs, I managed to find some reference for a similar situation. I wrote the second option where everything is handled in the user channel, when the user client receives the “presence_diff” it will send it back and when the channel receives that message, it uses Endpoint to broadcast it to the admin channel. Also, user’s :after_join also sends a broadcast to the admin with “presence_state”.
I’m sorry if I ‘prematurely’ posted it but I figured I’d write the solution in here in case anyone needed it.

Source: StackOverflow