skokon

skokon

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

Showing Posts 1 to 5

sfusato

sfusato

In the template rendered by render you can access it directly like this: @user_id. In the other callbacks (handle_params, handle_event, handle_info) or other functions where you pass the socket, it will be under the :assigns key, so in this case: socket.assigns.user_id.

skokon

skokon OP

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

sfusato

sfusato

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?

skokon

skokon OP

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

rogerweb

rogerweb

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?

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
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
nseaSeb
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
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews