celsobonutti
I’m trying to use a Phoenix Channel for the signaling part of a WebRTC application, as I thought Presence would be perfect for this.
The thing is: I’m trying to track a user join using Phoenix.js’ Presence object, like this:
presence.onJoin(async (id, current, newPres) => {
if (!current) {
const peerConnection = await createPeerConnection(
channel,
sendMessage,
config.onTrack,
localStreamMedia
);
peerMap.set(id, peerConnection);
} else {
}
});
The thing is: every time a user joins, this callback is fired multiple times, even with its own Presence object and the objects of users that were previously in the channel. I don’t know if this is the expected behavior and couldn’t find a reference about that.
My Channel looks like this right now:
defmodule ElmWebRtcWeb.VideoChannel do
use Phoenix.Channel
alias ElmWebrtcWeb.Presence
def join("videoroom:" <> _channel, _message, socket) do
send(self(), :after_join)
{:ok, socket}
end
def handle_info(:after_join, socket) do
{:ok, _} =
Presence.track(socket, socket.assigns.user_id, %{
online_at: inspect(System.system_time(:millisecond))
})
push(socket, "presence_state", Presence.list(socket))
{:noreply, socket}
end
end
and the JS Presence is created like this:
const channel = socket.channel(`videoroom:${room}`, {});
channel.join();
const presence = new Presence(channel);
Does anyone have a clue about:
- Is this the expected behavior of Presence.js?
- If so, is there any way for me to achieve what I want with it?
- If not, what could be going wrong?
Thank you very much!
Trending in Questions
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
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
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
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
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
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
celsobonutti
I haven’t been able to use this with
const presence = Presence(channel), but this:did the job and is working perfectly.
I’m still wondering if the first implementation should work though
peoj
I found the exact same thing when working with
onJoin()- it would fire more than expected.My workaround has been to use
onSync()instead and then callingpresence.list(), which is always (in my experience) accurate.For example:
Hope that helps!
njwest
Chiming in to add (somewhat late, but for anyone else who finds this thread) that presence.onJoin isn’t working as expected (or in my case, at all), with the following code taken directly from the docs:
I’ve tried async, and defining presence logic in the
joincallback, and while I can logpresenceitself and see the functions, the event listeners never fire