Phoenix.Socket

Holds state for multiplexed socket connections and Channel authorization

Socket Fields

Source

Summary

assign(socket, key, value)

Adds key/value pair to ephemeral socket state

authorize(socket, topic)

Authorizes socket’s topic

authorized?(socket, topic)

Checks if a given String topic is authorized for this Socket

deauthorize(socket)

Deauthorizes topic

put_channel(socket, channel)

Sets channel of socket

put_topic(socket, topic)

Sets topic of socket

Functions

assign(socket, key, value)

Adds key/value pair to ephemeral socket state

Examples

iex> socket = Socket.put_topic(%Socket{}, "rooms:lobby")
%Socket{topic: "rooms:lobby"}
iex> socket.assigns[:token]
nil
iex> socket = Socket.assign(socket, :token, "bar")
iex> socket.assigns[:token]
"bar"
Source
authorize(socket, topic)

Authorizes socket’s topic

Examples

iex> Socket.authorize(%Socket{}, "rooms:lobby")
%Socket{topic: "rooms:lobby", authorized: true}
Source
authorized?(socket, topic)

Checks if a given String topic is authorized for this Socket

Examples

iex> socket = %Socket{}
iex> Socket.authorized?(socket, "rooms:lobby")
false
iex> socket = Socket.authorize(socket, "rooms:lobby")
%Socket{topic: "rooms:lobby", authorized: true}
iex> Socket.authorized?(socket, "rooms:lobby")
true
Source
deauthorize(socket)

Deauthorizes topic

Examples

iex> socket = Socket.authorize(%Socket{}, "rooms:lobby")
%Socket{topic: "rooms:lobby", authorized: true}
iex> Socket.deauthorize(socket)
%Socket{topic: "rooms:lobby", authorized: false}
Source
put_channel(socket, channel)

Sets channel of socket

Source
put_topic(socket, topic)

Sets topic of socket

Source