The main API for the Phoenix Socket Client.
Namespace Notice
This library is not part of the official Phoenix Framework.
The Phoenix.SocketClient namespace is used for clarity as this is a client
for Phoenix Channels.
Summary
Functions
Joins a channel through the socket.
Leaves a channel.
Returns a child specification for the socket client supervisor.
Connects the socket.
Checks if the socket is connected.
Returns the current connection attempt independently of telemetry configuration.
Releases private configuration for an unused client child specification.
Disconnects the socket.
Gets the entire socket state.
Gets a value from the socket state.
Pushes a message through the socket.
Puts a value into the socket state.
Removes a channel from the list of joined channels. For internal use.
Starts the socket client supervisor.
Updates the status of a channel. For internal use.
Functions
@spec channel_join(pid(), binary(), map()) :: {:ok, pid()} | {:error, :channel_manager_not_found | {:already_started, pid()}}
Joins a channel through the socket.
Leaves a channel.
@spec child_spec(keyword()) :: Supervisor.child_spec()
Returns a child specification for the socket client supervisor.
Delegates to Phoenix.SocketClient.Supervisor.child_spec/1.
Connects the socket.
Checks if the socket is connected.
@spec connection_info(pid() | atom()) :: %{ attempt_ref: reference() | nil, status: :disconnected | :connecting | :connected, last_error: atom() | {atom(), integer()} | nil } | {:error, :no_socket_found}
Returns the current connection attempt independently of telemetry configuration.
The snapshot contains :attempt_ref, :status, and :last_error. The reference
is nil before the first attempt and changes whenever a new transport is opened,
including automatic retries. Failures retain the reference and reason until
another attempt starts. Successful connections clear the error.
HTTP upgrade rejections retain {:unexpected_status, status} (including 401
and 403); transient failures retain their error atom, such as :econnrefused
or :timeout. Other structured errors expose their category without private
details. Explicit disconnect records :cancelled and cancels pending retries.
Read the snapshot again before acting on a previously observed failure; an
older attempt must not override a newer connection. Automatic retries replace
the snapshot, so use reconnect?: false and let the caller initiate retries
when each rejection must be classified. This function reports
connection state and leaves authentication policy to the caller.
@spec discard_child_spec(Supervisor.child_spec()) :: :ok | {:error, :in_use}
Releases private configuration for an unused client child specification.
See Phoenix.SocketClient.Supervisor.discard_child_spec/1 for its lifetime.
Disconnects the socket.
Gets the entire socket state.
Gets a value from the socket state.
@spec push(pid() | atom(), Phoenix.SocketClient.Message.t()) :: Phoenix.SocketClient.Message.t() | no_return()
Pushes a message through the socket.
Puts a value into the socket state.
Removes a channel from the list of joined channels. For internal use.
@spec start_link(keyword()) :: Supervisor.on_start()
Starts the socket client supervisor.
Delegates to Phoenix.SocketClient.Supervisor.start_link/1.
Updates the status of a channel. For internal use.