Skip to main content

Crate phoenix_channel_runtime

Crate phoenix_channel_runtime 

Source
Expand description

§phoenix-channel-runtime

Phoenix Channels v2 protocol building blocks for Rust.

This crate contains the transport-independent frame codec, protocol state machine, Presence synchronization, and session helper. Applications usually use it through phoenix-channel-client; use it directly when implementing a custom transport or execution model.

use phoenix_channel_runtime::{Frame, Protocol, ProtocolEvent};
use serde_json::json;

let mut protocol = Protocol::new();
let join = protocol.join("room:lobby", json!({}))?;
let encoded = join.frame.encode_text()?;

let reply = Frame::decode_text(
    r#"["1","1","room:lobby","phx_reply",{"status":"ok","response":{}}]"#,
)?;
assert!(matches!(
    protocol.receive(reply)?,
    ProtocolEvent::Joined { .. }
));

The default codec supports Phoenix’s JSON and binary v2 representations. LimitedPhoenixV2Codec can reject oversized frames and binary payloads before they enter protocol state.

§License

MIT

Structs§

CodecLimits
Maximum accepted sizes for encoded frames and binary payloads.
Frame
A Phoenix Channels v2 JSON frame.
LimitedPhoenixV2Codec
Phoenix Channels v2 codec with configurable frame and payload limits.
Outbound
An outbound frame and the reference allocated to correlate its reply.
PhoenixV2Codec
Phoenix Channels v2 JSON and binary codec without size limits.
Presence
A Presence entry and its active connection metadata.
PresenceDiff
Presence joins and leaves produced by a state or diff synchronization.
PresenceState
Current Phoenix Presence entries keyed by application-defined presence key.
PresenceTracker
Applies Phoenix Presence state and diff frames in join-generation order.
Protocol
Pure Phoenix Channels protocol state.
Session
A sequential, runtime-neutral Phoenix Channels session.
TransportClose
Details reported when a transport connection closes.
TransportCloseRequest
Close code and reason requested by the client.
TransportError
Error returned by a runtime-specific transport.

Enums§

ChannelState
Local lifecycle state for a channel topic.
CodecError
Failure while encoding or decoding a Phoenix v2 wire message.
FrameCodecError
Failure while encoding or decoding a Phoenix JSON v2 frame.
Payload
Payload carried by a Phoenix protocol frame.
PayloadError
Failure while reading a typed value from a Payload.
PresenceError
Invalid Phoenix Presence state, diff, or metadata.
PresenceUpdate
Result of applying a frame to a PresenceTracker.
ProtocolError
Invalid operation or reply for the current protocol state.
ProtocolEvent
Semantic event produced from an incoming Phoenix frame or connection reset.
ReplyStatus
Status carried by a Phoenix phx_reply.
SessionError
Protocol, codec, or transport failure produced by a Session.
TransportErrorKind
Operation in which a transport failure occurred.
TransportEvent
Message or close notification received from a transport.
WireMessage
A transport-level WebSocket message.

Constants§

V2_PROTOCOL_VERSION
Phoenix’s current JSON serializer protocol version.

Traits§

Codec
Encodes and decodes Phoenix frames for a transport.
EventRoute
Associates an application event name with its deserialized payload type.
Transport
A runtime-neutral, object-safe transport interface.

Functions§

sync_presence_diff
Applies incremental Presence joins and leaves to state.
sync_presence_state
Replaces state with a full server state and returns its joins and leaves.