amjr
Hi,
I’m currently diving into world of websockets via Phoenix channels. Absolutely awesome stuff.
The thing I’m wondering is Phoenix presence. Almost all of the examples are chat-examples however my use-case is not a chat but rather a game.
Usually everybody handles the presence state diff-messages in Javascript. For example:
room.on("presence_diff", diff => {
presences = Presence.syncDiff(presences, diff)
render(presences)
})
given this channel implementation:
defmodule PhoenixChat.RoomChannel do
use PhoenixChat.Web, :channel
alias PhoenixChat.Presence
def join("room:lobby", _, socket) do
send self(), :after_join
{:ok, socket}
end
def handle_info(:after_join, socket) do
Presence.track(socket, socket.assigns.user, %{
online_at: :os.system_time(:milli_seconds)
})
push socket, "presence_state", Presence.list(socket)
{:noreply, socket}
end
end
How can I suppress the sending of presence_diffs to clients? As I don’t want to expose the presence information to connected clients but keep it only on the server side.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 5 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
chrismccord
intercepting is the way to go to easily filter out the
presence_diffeventsamjr
Great. This helps me forward. Thanks!
By the way. Gotta love the Elixir/Phoenix community. You guys rock!
OvermindDL1
That is precisely it.
Personally I would have a few processing processes that handle the messages of what is happening, and ‘they’ would then send messages to topics to send updates to clients, and the clients would connect to as many topics as they need for the data they want to receive.
amjr
Intercepting would be something like this?
The target is to use the channel for sending in-game data and event to clients and utilize the presence internally on the server-side. Client side would only connect the websocket (swift / iOS, Android) and get updates on the game events.
Clients wouldn’t get updates on who is online and who is not (prevent players for example attacking players who go offline in the hopes of catching them off-guard)
OvermindDL1
Two ways, you can also PubSub subscribe to a new process that does all the actual processing with the messages then posts to the client as needed, this would also let clients share a ‘processing’ actor. Or you can hook the ‘outgoing’ messages in Phoenix Channels (detailed in the docs) for the outgoing message of “presence_diff” then do what you wish, such as pushing it out or canceling it or whatever.
For note, if the client should get the pubsub messages then they should get them all or will desync.
If the client should get none then it should be handled by another process.
The client should never just get ‘some’, what you probably want here is an intermediary process as well to coalesce the updates.