I’m working on a realtime video chat application and the feature that I’m trying to build can be thought of as something similar to:
-
Alice comes online and her metadata has a list of user ids of her friends who are also online and are connected to the same socket
-
Bob comes online and must have his own list, but now we must also regenerate Alice’s list to include Bob’s id
-
Charlie comes online and must have his own list, but now we must also regenerate Alice’s and Bob’s lists to include Charlie’s id
-
Alice leaves, so we must now remove her user id from Bob’s and Charlie’s lists
I’m placing these in the Presence under a key called remote_participant_ids
. These lists are unique to each user, so I unfortunately can’t do Object.keys(presence)
on the client.
I’ve tried overwriting Presence.fetch/2
, but that seemed to lose the remote_participant_ids
when calling Presence.syncDiff
on the client.
I tried manually calling Presence.list()
on each action, but I found that the User with the process calling this would receive an updated list, but nobody else would.
After trying various incarnations of this within my Presence
module I’ve tried moving it out to the channel and manually regenerating each person’s list on actions between clients, but that’s also seeing inconsistencies between connected clients.
Here is a gist with my code within Presence.fetch/2
- presence.ex · GitHub
What am I doing wrong here? I assumed that fetch/2
is called and updates everyone’s outgoing presence? What’s the right way to update everyone’s Presence in one go like this, or even to use Phoenix to build something like this?