Expand description
§phoenix-channel-client
Managed sockets and channels for Phoenix Channels v2.
The client owns heartbeat, reconnect, rejoin, buffering, timeout, Presence, and
event subscription behavior. Supply a Connector and Timer, then run the
returned driver on the runtime used by the application.
use phoenix_channel_client::{Options, Socket, static_join_payload};
use phoenix_channel_runtime_native::{NativeConnector, NativeTimer};
use serde_json::json;
let (socket, driver) = Socket::new(
NativeConnector::new("wss://example.com/socket/websocket?vsn=2.0.0"),
NativeTimer,
Options::default(),
);
tokio::task::spawn_local(driver);
let channel = socket.channel(
"room:lobby",
static_join_payload(json!({"user_id": "123"})),
)?;
channel.join().await?;
let reply = channel.call("new_message", json!({"body": "hello"})).await?;Use Endpoint with a connection configuration loader when credentials must be
refreshed for each connection attempt. Join payload loaders are evaluated for
every join and rejoin.
Calls waiting for a connection or join are buffered. A call already sent when
the transport disconnects returns ClientError::Interrupted and is not retried.
Event subscribers are bounded and receive an explicit lag event if they fall
behind.
Enable the tracing feature to convert structured client telemetry into
tracing events.
§License
MIT
Structs§
- Channel
- Handle for one Phoenix channel topic.
- Channel
Events - Independent bounded stream of
ChannelEventvalues. - Channel
Presence - Current Presence state and changes for a joined channel.
- Connect
Context - Information supplied to a
Connectorfor one connection attempt. - Connection
Config - Query parameters and Phoenix 1.8 authentication for a connection attempt.
- Driver
- A future that owns all connection and protocol state.
- Endpoint
- A Phoenix socket base URL and per-attempt connection configuration.
- Event
Subscription - Filtered bounded subscription for one application event name.
- Join
Context - Information supplied when loading a channel’s join payload.
- Options
- Heartbeat, retry, timeout, buffering, and telemetry settings.
- Reconnect
Context - Information supplied to a custom reconnect policy.
- Reply
- Correlated Phoenix reply status and response payload.
- Resolved
Endpoint - Fully resolved URL and WebSocket subprotocols for one connection attempt.
- Socket
- Handle used to configure channels and control the managed connection.
- Socket
Events - Independent bounded stream of
SocketEventvalues. - Status
Changes - Stream of changes to a copyable socket or channel status.
Enums§
- Call
Json Error - Failure from
Channel::call_json. - Call
Outcome - Terminal outcome recorded for call telemetry.
- Channel
Event - Protocol or lifecycle notification for one channel topic.
- Channel
Status - Observable lifecycle state for one channel topic.
- Client
Error - Failure returned by the managed socket or channel API.
- Client
Operation - Managed operation used in timeout and interruption errors.
- Disconnect
Reason - Condition that disconnected a managed socket.
- Endpoint
Error - Invalid URL or failure while refreshing endpoint configuration.
- Presence
Event - A synchronized Presence change or channel lifecycle event.
- Presence
Stream Error - Failure while decoding or consuming a Presence event stream.
- Reconnect
Action - Decision returned by a custom reconnect policy.
- Reply
Error - Server rejection or response decoding failure.
- Socket
Event - Socket connection and reconnect lifecycle notification.
- Socket
Status - Observable socket lifecycle state.
- Subscription
Event - Event returned by an application-event subscription.
- Telemetry
Event - Structured lifecycle and frame observation emitted by the driver.
Traits§
- Connector
- Creates target-specific WebSocket transports for the driver.
- Timer
- Supplies sleeps without choosing an executor.
Functions§
- static_
connection_ config - Creates a loader that clones the same configuration for every attempt.
- static_
join_ payload - Creates a join payload loader that clones the same value for every attempt.
- tracing_
telemetry_ hook - Creates a telemetry hook that emits structured events through
tracing.
Type Aliases§
- Channel
Status Changes - Status-change stream for a
Channel. - Connection
Config Loader - Async callback that refreshes connection parameters and authentication.
- Join
Payload Loader - Async callback that produces a fresh JSON payload for each join attempt.
- Reconnect
Policy - Callback that decides whether and when to reconnect.
- Socket
Status Changes - Status-change stream for a
Socket. - Telemetry
Hook - Callback invoked synchronously for every
TelemetryEvent.