How to put something in a socket's assigns from another process

Thought it might not, Sockets are for handling sockets only so that makes sense, keep it to channels then. :slight_smile:

Iā€™m not sure why you would want to receive messages in the socket to be honest, Iā€™ve never thought up a need other than disconnecting themā€¦

1 Like

I thought that changing the assigns in the socket would change them everywhere, but as you said earlier, it was wrong since they are copied into channels. So yeah, there is little reason to receive messages in the socket.

Thanks.

1 Like

Sorry, but I still donā€™t understand how the example in the comments to id/1 function Test.Web.Endpoint.broadcast "user_socket:#{id}", "disconnect", %{} works.

Where if not in the UserSocket would I implement the disconnecting logic?

1 Like

The disconnect message is handled internally to the socket. If you want to handle when it disconnects then setup a normal OTP-style monitor, nothing special with that. :slight_smile:

So is it like a predefined verb in phoenix? I donā€™t have to write anything, just send ā€œdisconnectā€ event to a socket and it would disconnect?

Looks like it yeah, that is how Iā€™ve used it at least and it works. :slight_smile:

1 Like