Phoenix.SocketClient.Channel behaviour (phoenix_socket_client v0.8.1)
View SourceA process for interacting with a Phoenix Channel.
Summary
Callbacks
Callback invoked when the channel process is terminating.
Callback invoked when the server replies to a channel join request.
Callback for handling incoming messages.
Functions
Join a channel topic through a socket with optional params
Leave the channel topic and stop the channel
Push a message to the server and wait for a a response or timeout
Push a message to the server and do not wait for a response
Stops the channel process.
Types
Callbacks
Callback invoked when the channel process is terminating.
reason is the termination reason (e.g. :normal, :shutdown, or an error).
@callback handle_join_reply(status :: atom(), payload :: map(), state :: state()) :: {:noreply, new_state :: state()}
Callback invoked when the server replies to a channel join request.
status is :ok on successful join or :error on failure.
payload contains the server's response payload.
@callback handle_message(event :: String.t(), payload :: map(), state :: state()) :: {:noreply, new_state :: state()}
Callback for handling incoming messages.
Functions
@spec join(pid() | atom(), binary(), map(), non_neg_integer()) :: {:ok, any(), pid()} | {:error, :socket_not_connected} | {:error, :timeout} | {:error, {:already_joined, pid()}} | {:error, any()}
Join a channel topic through a socket with optional params
A socket can only join a topic once. If the socket you pass already has a
channel connection for the supplied topic, you will receive an error
{:error, {:already_joined, pid}} with the channel pid of the process joined
to that topic through that socket. If you require to join the same topic with
multiple processes, you will need to start a new socket process for each channel.
Calling join will link the caller to the channel process.
@spec leave(pid()) :: :ok
Leave the channel topic and stop the channel
Push a message to the server and wait for a a response or timeout
The server must be configured to return {:reply, _, socket}
otherwise, the call will timeout.
Push a message to the server and do not wait for a response
@spec stop(pid()) :: :ok
Stops the channel process.