tommyp

tommyp

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?

Showing Posts 1 to 2

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.

codeanpeace

codeanpeace

Hmm, assuming you’re using LiveView, you could handle the filtering at the LiveView process level by having each LiveView server side process subscribe directly to Presence broadcasts rather than each LiveView client subscribe via phoenix.js.

Then you could store each user’s friends as a list of ids in the assigns and check/filter against that. This could be useful approach say if you wanted to show all active users, but elevate a user’s active friends into its own separate section at the top.

Using Elixir as a Presence Client | Phoenix.Presence docs

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews