Hello Elixir community, I’m new to elixir and phoenix, I’m trying to get the socket by the data I already assigned to it
for example, I’ve set the user-id
socket = assign(socket, :user_id, USER_ID)
Now I want to get the socket using user_id I already have
In the template rendered by
render you can access it directly like this: @user_id. In the other callbacks (
handle_info) or other functions where you pass the socket, it will be under the
:assigns key, so in this case:
Hello, thanks for the reply, I know how to access the assigns key, actually what I want is to access the socket from the user_id, what I want to do is I call a function and pass player id and returns all assigned keys by the player id, I hope u understood what I mean
I’m not aware of anything built-in that will return all the sockets that have a specific assign in it. You could wire this with
PubSub where each liveview would subscribe and when called upon would respond.
What are you trying to achieve?
I have a function and I called it get_status I will call it from the client and pass playerID parameter, what I want to get everything assigned to that socket with that playerID, I have some data I’ve set like channel id and player name and i want to retrieve that data using the player ID
Hi @skokon , I have the same need as you, i.e., given a socket’s id (as defined by the
id/1 function), I want to get the socket struct. Did you figure out how to do it?