Skip to main content

Crate phoenix_channel_runtime_native

Crate phoenix_channel_runtime_native 

Source
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§

NativeChannel
Send + Sync handle for one Phoenix channel topic.
NativeChannelEvents
Independent bounded native channel event receiver.
NativeChannelPresence
Current Presence state and changes for a native channel.
NativeChannelStatusChanges
Receiver for native channel status changes.
NativeConnector
Connector for native ws and wss WebSocket endpoints.
NativeEventSubscription
Filtered native subscription for one application event name.
NativeOptions
Settings for a dedicated native client worker.
NativeSocket
Send + Sync handle for a managed client running on a dedicated thread.
NativeSocketEvents
Independent bounded native socket event receiver.
NativeSocketStatusChanges
Receiver for managed socket status changes.
NativeTimer
Tokio timer using monotonic std::time::Instant measurements.
NativeTransport
Tokio Tungstenite transport implementing the runtime-neutral transport API.
NativeTransportOptions
TLS, proxy, header, and WebSocket limit settings for native transports.
NativeWorkerStatusChanges
Receiver for dedicated worker-thread status changes.
ProxyConfig
HTTP CONNECT proxy URL and host bypass rules.

Enums§

NativeCallJsonError
Failure from NativeChannel::call_json.
NativeEventError
Failure while consuming a native broadcast or status stream.
NativePresenceError
Failure while consuming native Presence state and events.
NativeRuntimeError
Failure from the native worker or managed client.
NativeWorkerStatus
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§

NativeConnectionConfigLoader
Thread-safe async callback that refreshes connection configuration.
NativeJoinPayloadLoader
Thread-safe async callback that refreshes a channel join payload.
NativeReconnectPolicy
Thread-safe callback that decides whether and when to reconnect.
NativeTelemetryHook
Thread-safe callback for managed-client telemetry.