Skip to main content

Crate phoenix_channel_client

Crate phoenix_channel_client 

Source
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.
ChannelEvents
Independent bounded stream of ChannelEvent values.
ChannelPresence
Current Presence state and changes for a joined channel.
ConnectContext
Information supplied to a Connector for one connection attempt.
ConnectionConfig
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.
EventSubscription
Filtered bounded subscription for one application event name.
JoinContext
Information supplied when loading a channel’s join payload.
Options
Heartbeat, retry, timeout, buffering, and telemetry settings.
ReconnectContext
Information supplied to a custom reconnect policy.
Reply
Correlated Phoenix reply status and response payload.
ResolvedEndpoint
Fully resolved URL and WebSocket subprotocols for one connection attempt.
Socket
Handle used to configure channels and control the managed connection.
SocketEvents
Independent bounded stream of SocketEvent values.
StatusChanges
Stream of changes to a copyable socket or channel status.

Enums§

CallJsonError
Failure from Channel::call_json.
CallOutcome
Terminal outcome recorded for call telemetry.
ChannelEvent
Protocol or lifecycle notification for one channel topic.
ChannelStatus
Observable lifecycle state for one channel topic.
ClientError
Failure returned by the managed socket or channel API.
ClientOperation
Managed operation used in timeout and interruption errors.
DisconnectReason
Condition that disconnected a managed socket.
EndpointError
Invalid URL or failure while refreshing endpoint configuration.
PresenceEvent
A synchronized Presence change or channel lifecycle event.
PresenceStreamError
Failure while decoding or consuming a Presence event stream.
ReconnectAction
Decision returned by a custom reconnect policy.
ReplyError
Server rejection or response decoding failure.
SocketEvent
Socket connection and reconnect lifecycle notification.
SocketStatus
Observable socket lifecycle state.
SubscriptionEvent
Event returned by an application-event subscription.
TelemetryEvent
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§

ChannelStatusChanges
Status-change stream for a Channel.
ConnectionConfigLoader
Async callback that refreshes connection parameters and authentication.
JoinPayloadLoader
Async callback that produces a fresh JSON payload for each join attempt.
ReconnectPolicy
Callback that decides whether and when to reconnect.
SocketStatusChanges
Status-change stream for a Socket.
TelemetryHook
Callback invoked synchronously for every TelemetryEvent.