Phoenix.Socket

Holds state for multiplexed socket connections and Channel authorization

Summary

assign(socket, key, value)

Adds key/value pair to ephemeral socket state

authorize(socket, channel, topic)

Adds authorized channel/topic pair to Socket’s channel list

authorized?(socket, channel, topic)

Checks if a given String channel/topic pair is authorized for this Socket

deauthorize(socket)

Deauthorizes channel/topic pair

set_current_channel(socket, channel, topic)

Sets current channel of multiplexed socket connection

Functions

assign(socket, key, value)

Adds key/value pair to ephemeral socket state

Examples

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

Adds authorized channel/topic pair to Socket’s channel list

Examples

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

Checks if a given String channel/topic pair is authorized for this Socket

Examples

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

Deauthorizes channel/topic pair

Examples

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

Sets current channel of multiplexed socket connection