Phoenix LiveView Currently Connected Socket

Hello ,

I have a use case in which I have to fire an event from the server to the liveview. To handle the event in the liveview I have to use Phoenix.LiveView.assign/2 which expects a Phoenix.LiveView.Socket -to which the liveview is already connected-, my question is how do I get the currently connected socket to liveview in order to do so.

Thanks in advance

@aligredo When you say “the liveview” what do you mean? Is this event happening inside a specific connected live view or is it just happening in the server generally and you need it to end up showing up in a specific live view? Keep in mind that each connected person has their own unique liveview process, there isn’t just one.

Generally speaking if you want to have events from elsewhere show up in live view you use phoenix pubsub. The live view subscribes to a topic, something else publishes to that topic, and then the liveview gets a message via handle_info.

1 Like

I know that each user has his own process, I meant getting the socket of each process.

Yes, I should use Pubsub for proper event firing and handling.

Thank you so much for your help!

1 Like