Expand description
§phoenix-channel-runtime-native
Native Tokio WebSocket transport for Phoenix Channels v2.
NativeSocket runs the managed client on a dedicated current-thread Tokio
runtime and exposes Send + Sync socket, channel, event, and Presence handles.
use phoenix_channel_client::ConnectionConfig;
use phoenix_channel_runtime_native::NativeSocket;
use serde_json::json;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let socket = NativeSocket::spawn(
"wss://example.com/socket",
ConnectionConfig::default().auth_token("token"),
)?;
socket.connect().await?;
let channel = socket.channel("room:lobby", json!({})).await?;
channel.join().await?;
let response: serde_json::Value = channel
.call_json("profile", &json!({"user_id": "123"}))
.await?;
println!("{response}");
socket.shutdown().await?;
Ok(())
}For applications that already run a local task set, NativeConnector and
NativeTimer can instead be passed directly to phoenix-channel-client.
Transport options support custom headers, Rustls configuration, HTTP CONNECT
proxies, message limits, and TCP nodelay.
§License
MIT
Structs§
- Native
Channel Send + Synchandle for one Phoenix channel topic.- Native
Channel Events - Independent bounded native channel event receiver.
- Native
Channel Presence - Current Presence state and changes for a native channel.
- Native
Channel Status Changes - Receiver for native channel status changes.
- Native
Connector - Connector for native
wsandwssWebSocket endpoints. - Native
Event Subscription - Filtered native subscription for one application event name.
- Native
Options - Settings for a dedicated native client worker.
- Native
Socket Send + Synchandle for a managed client running on a dedicated thread.- Native
Socket Events - Independent bounded native socket event receiver.
- Native
Socket Status Changes - Receiver for managed socket status changes.
- Native
Timer - Tokio timer using monotonic
std::time::Instantmeasurements. - Native
Transport - Tokio Tungstenite transport implementing the runtime-neutral transport API.
- Native
Transport Options - TLS, proxy, header, and WebSocket limit settings for native transports.
- Native
Worker Status Changes - Receiver for dedicated worker-thread status changes.
- Proxy
Config - HTTP CONNECT proxy URL and host bypass rules.
Enums§
- Native
Call Json Error - Failure from
NativeChannel::call_json. - Native
Event Error - Failure while consuming a native broadcast or status stream.
- Native
Presence Error - Failure while consuming native Presence state and events.
- Native
Runtime Error - Failure from the native worker or managed client.
- Native
Worker Status - Lifecycle state of the dedicated native worker thread.
Functions§
- native_
static_ connection_ config - Creates a native loader that clones the same connection configuration.
- native_
static_ join_ payload - Creates a native loader that clones the same join payload.
Type Aliases§
- Native
Connection Config Loader - Thread-safe async callback that refreshes connection configuration.
- Native
Join Payload Loader - Thread-safe async callback that refreshes a channel join payload.
- Native
Reconnect Policy - Thread-safe callback that decides whether and when to reconnect.
- Native
Telemetry Hook - Thread-safe callback for managed-client telemetry.