Questions tagged [phoenix-channels]

Phoenix framework's channels give the tools to organize the code and the communication among users while keeping the connection opened for live messages updates, its transportation-agnostic, so it can use different protocols, like websocket or log polling..

A Phoenix channel is a conversation. The channel sends messages, receives messages, and keeps state. We call the messages events, and we put the state in a struct called socket. A Phoenix conversation is about a topic, and it maps onto application concepts like a chat room, a local map, a game, or in our case, the annotations on a video. More than one user might be interested in the same topic at the same time. Channels give you tools to organize your code and the communication among users. The concept that makes channels so powerful in Elixir is that each user’s conversation on a topic has its own isolated, dedicated process.

102 questions
2
votes
1 answer

Synchronizing application state while joining a Phoenix Channel (or other pubsub)

I am building a collaborative drawing board (eg r/place): there is a grid of pixels which users can change at any time and the pixel updates get propagated to all other users online. I want to use Phoenix Channels to broadcast the pixel changes. My…
2
votes
1 answer

How do I use Phoenix Presence to track the existence of topics/subtopics?

I'm using subtopics as a one-user channel that others can use to send messages to specific other people. For example: - I'm user 1, and I want to send a message to user 2. - I send a message with payload { to: 2, message: 'hi' } and handle_in does…
NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
2
votes
1 answer

Is there a way to send files over websockets through phoenix channels?

I am working on a chat feature right now and was wondering if there was an easy way to send files over websockets. So far I have been pretty unsuccessful, I have it working just fine over http but it seems to never receive my file when it gets to…
Morgan G
  • 3,089
  • 4
  • 18
  • 26
2
votes
2 answers

phoenix presence fetch/2 override

I want to be able to pass user meta data through the :meta map in phoenix presence to access it from the JavaScript side. More specifically, I want to be able to push image file paths (strings) and have them associated with each user in my presence…
Abeltensor
  • 132
  • 1
  • 10
2
votes
1 answer

Elixir/Phoenix pass payload on joining channel

Channels have the authorized? function, and I would like to pass the generated local token when joining the channel so that I can verify user's role, like this: const data = { token: localStorage.getItem('phoenixAuthToken')…
Ilya
  • 1,120
  • 1
  • 12
  • 33
2
votes
0 answers

Duplicate channel join after reloading

I've used Phoenix Channels for distribution of colors in my project and I keep getting such error: [debug] Duplicate channel join for topic "colors:*" in EveryColor.ColorSocket. Closing existing channel for new join How to replicate: make install…
Haito
  • 2,039
  • 1
  • 24
  • 35
2
votes
1 answer

Streaming from a redis channel through a phoenix channel

I am currently trying to replace actioncable with a small phoenix app. What I need to do is get information from a redis channel and stream it to an ember client. I have been attempting to use Redis.PuSub and the Phoenix Redis adapter, but haven't…
James Byrne
  • 310
  • 1
  • 7
2
votes
1 answer

Phoenix Channels - broadcasting from controller - how to find current_user?

I have an app where I broadcast some submissions for forms in the submission_controller, like this: Formerer.Endpoint.broadcast("forms:#{form.id}", "new_submission", payload) However, what I try to do now, is to make sure that only the current_user…
iacobSon
  • 133
  • 10
2
votes
1 answer

Phoenix Channel sending messages from a client outside the project

I wanted to send a message to my user channel of my Phoenix Application. I have joined a user_token with the channel as users:user_token in the user_channel.ex . I was successful doing it from another controller called the toy_controller by calling…
2
votes
1 answer

How to set up Websockets with Phoenix behind Nginx?

I'm trying to set up web sockets to go through Nginx to a Phoenix app but keep getting a 403 error. Can anyone advise the correct configuration to make this work in production - development env is fine. My Nginx conf: upstream phoenix { server…
paul h
  • 152
  • 2
  • 10
2
votes
0 answers

How to create GenServer child process from spawn function?

I'm using ExTwitter Stream to track tweets in realtime and broadcast them via channel endpoint. I would like to create one process per event and assign to it one twitter stream listener, then when new subscriber join to the same event get previous…
luzny
  • 2,380
  • 7
  • 30
  • 64
2
votes
1 answer

Can't connect to Phoenix channel hosted on Heroku from iOS using PhoenixWebSocket

I have pushed a Phoenix app to Heroku and it is running fine, apart from connecting to a channel from iOS. Channels over the browser work as expected. In iOS I am using PhoenixWebSocket, and in dev env, connecting to the local Phoenix app works as…
paul h
  • 152
  • 2
  • 10
1
vote
1 answer

phoenix socket multiple assign

I want to add a few data into socket but wondering what the best way to do that would be. Instead of doing a bunch of socket = assign(socket, :channel_id, channel_id)
user1354934
  • 8,139
  • 15
  • 50
  • 80
1
vote
1 answer

Why am I getting this error when I try to broadcast to one socket

so I have socket.endpoint.subscribe("user_socket:" <> socket.id) And when I try to broadcast to it RealmWeb.Endpoint.broadcast( "user_socket:#{player_state.socket_id}", "quest completed", %{}) I get…
bezzoon
  • 1,755
  • 4
  • 24
  • 52
1
vote
2 answers

How do I expose my own Elixir websocket using WebSockex

I see the basic example for Elixir's WebSockex library here but it doesn't really explain how I can expose my own websocket to the internet. This question has answers which explain how to chat to an existing websocket externally, but I want to…
Thomas Browne
  • 23,824
  • 32
  • 78
  • 121