nallwhy

nallwhy

Is it possible to get all connected sockets on phoenix?

I want to know socket connected user list on phoenix.
I used Presence and it works but it notifies all connection changes to all clients. I don’t want it.
The idea I have now is monitoring sockets with worker, but I want to know any better idea.
Thanks!

Marked As Solved

LostKobrakai

LostKobrakai

Track all the users in Presence under a key different to the channel name. This will prevent users from receiving the diff messages.

Also Liked

LostKobrakai

LostKobrakai

It surely does convey the intention quite well, but not trying to send diffs in the first place is probably the better implementation than trying to send them just to discard them on their way. I’m not sure how performance intensive a noop intercept is, but it has a warning that customizing messages per user can become a performance issue.

If you track users in presence using e.g. something like an internal:users topic I feel like the intend can be communicated in a similarly explicit fashion.

nallwhy

nallwhy

cool! thx!

rjk

rjk

I had another method found earlier within this forum and that is to
intercept(["presence_diff"]) inside the channel module. That’s the message phoenix tries to send to provide the presence to connected clients. By intercepting you are able the change the outgoing message (even changing it to a no-op and effectively not sending a message to the clients).
To change the presence_diff message you use the following in the same channel module (where you just added the intercept line from above):

def handle_out("presence_diff", _, socket), do: {:noreply, socket}

Because this function returns a noreply it will not send out any presence information to the connected clients.
I guess both methods work but maybe this method conveys your intention a little better.

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
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
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement