ChannelClient. Socket
(channel_client v0.1.1)
Copy Markdown
A GenServer holding the WebSocket connection to a Phoenix endpoint.
The socket owns the wire protocol: it assigns refs, tracks each joined
topic's join_ref (as required by Phoenix Channels protocol v2),
serializes outbound frames and routes decoded inbound frames to the
matching ChannelClient.Channel process.
Lifecycle
The socket connects asynchronously after start_link/2 and, unless
reconnect?: false is given, keeps reconnecting forever when the
connection drops. Channels are unregistered on disconnect and their
owners receive a %ChannelClient.Message{} with event "phx_error"
(or "phx_close" for clean closes); callers are expected to re-join.
Options
:url- (required) WebSocket URL,ws://orwss://.:format- wire format::json(default),:etf,:toon,:btoon, a module implementing theChannelClient.Formatbehaviour, or{module, opts}. SeeChannelClient.Format.:json_library- JSON module implementingencode!/1anddecode!/1. Defaults toJason.:serializeris accepted as an alias. Only used by the JSON format.:vsn- Phoenix Channels protocol version,"1.0.0"or"2.0.0". Defaults to"2.0.0". Only used by the JSON format.:transport- module implementing theChannelClient.Transportbehaviour. Defaults toChannelClient.Transports.Websocket.:transport_opts- options passed through to the transport.:headers- extra headers for the WebSocket upgrade request.:params- map of query params merged into the connect URL.:heartbeat_interval- keepalive ping interval in ms (default30_000).:reconnect_interval- ms between reconnect attempts (default60_000).:reconnect?- whether to automatically reconnect (defaulttrue).:inbound_plugs- plug specs run on every decoded server frame before routing; halting a frame drops it. SeeChannelClient.Plug.:outbound_plugs- plug specs run on every outgoing frame before encoding; halting returns{:error, {:halted, reason}}to sync callers and drops async pushes. SeeChannelClient.Plug.
Summary
Functions
Returns a specification to start this module under a supervisor.
Returns whether the underlying transport is currently connected.
Stops the socket process.
Types
@type t() :: %ChannelClient.Socket{ channels: term(), flush_pending: term(), format: term(), format_opts: term(), inbound_plugs: term(), outbound_plugs: term(), reconnect: term(), reconnect_interval: term(), reconnect_timer: term(), ref: term(), status: term(), to_send: term(), transport: term(), transport_opts: term(), transport_pid: term(), url: term() }
Functions
@spec child_spec(keyword() | {keyword(), keyword()}) :: Supervisor.child_spec()
Returns a specification to start this module under a supervisor.
See Supervisor.
Returns whether the underlying transport is currently connected.
Returns false for dead or missing sockets instead of crashing.
Stops the socket process.