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§
- Codec
Limits - Maximum accepted sizes for encoded frames and binary payloads.
- Frame
- A Phoenix Channels v2 JSON frame.
- Limited
Phoenix V2Codec - Phoenix Channels v2 codec with configurable frame and payload limits.
- Outbound
- An outbound frame and the reference allocated to correlate its reply.
- Phoenix
V2Codec - Phoenix Channels v2 JSON and binary codec without size limits.
- Presence
- A Presence entry and its active connection metadata.
- Presence
Diff - Presence joins and leaves produced by a state or diff synchronization.
- Presence
State - Current Phoenix Presence entries keyed by application-defined presence key.
- Presence
Tracker - 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.
- Transport
Close - Details reported when a transport connection closes.
- Transport
Close Request - Close code and reason requested by the client.
- Transport
Error - Error returned by a runtime-specific transport.
Enums§
- Channel
State - Local lifecycle state for a channel topic.
- Codec
Error - Failure while encoding or decoding a Phoenix v2 wire message.
- Frame
Codec Error - Failure while encoding or decoding a Phoenix JSON v2 frame.
- Payload
- Payload carried by a Phoenix protocol frame.
- Payload
Error - Failure while reading a typed value from a
Payload. - Presence
Error - Invalid Phoenix Presence state, diff, or metadata.
- Presence
Update - Result of applying a frame to a
PresenceTracker. - Protocol
Error - Invalid operation or reply for the current protocol state.
- Protocol
Event - Semantic event produced from an incoming Phoenix frame or connection reset.
- Reply
Status - Status carried by a Phoenix
phx_reply. - Session
Error - Protocol, codec, or transport failure produced by a
Session. - Transport
Error Kind - Operation in which a transport failure occurred.
- Transport
Event - Message or close notification received from a transport.
- Wire
Message - 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.
- Event
Route - 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
statewith a full server state and returns its joins and leaves.