tommyp

tommyp

A phoenix presence meta value based on other connected users

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?

Most Liked

LostKobrakai

LostKobrakai

I’d argue that updating metas of pids other than ones own is a antipattern. It sounds like you’re looking for “show friends presences”. It’s old and using outdated apis, but https://medium.com/@alvinlindstam/phoenix-presence-for-social-networks-5fb67143f0ad discusses a way to handle that usecase.

Where Next?

Popular in Questions Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement