pub struct Protocol { /* private fields */ }Expand description
Pure Phoenix Channels protocol state.
The caller owns I/O, clocks, authentication refresh, and retry scheduling. That makes the same state machine usable from browser WASM, Tokio, smol, or a UI framework executor.
Implementations§
Source§impl Protocol
impl Protocol
Sourcepub fn channel_state(&self, topic: &str) -> Option<ChannelState>
pub fn channel_state(&self, topic: &str) -> Option<ChannelState>
Returns the local state of topic, if it is known.
Sourcepub fn join(
&mut self,
topic: impl Into<String>,
params: Value,
) -> Result<Outbound, ProtocolError>
pub fn join( &mut self, topic: impl Into<String>, params: Value, ) -> Result<Outbound, ProtocolError>
Starts joining a topic with the supplied parameters.
The returned frame must be sent and later passed back through
Protocol::receive when its reply arrives.
Sourcepub fn rejoin(
&mut self,
topic: impl Into<String>,
refreshed_params: Value,
) -> Result<Outbound, ProtocolError>
pub fn rejoin( &mut self, topic: impl Into<String>, refreshed_params: Value, ) -> Result<Outbound, ProtocolError>
Starts a new join generation for a disconnected, errored, or closed topic.
Sourcepub fn rejoin_all_with_stored_params(&mut self) -> Vec<Outbound>
pub fn rejoin_all_with_stored_params(&mut self) -> Vec<Outbound>
Rejoins every inactive topic using the parameters stored by its prior join.
Sourcepub fn leave(&mut self, topic: &str) -> Result<Outbound, ProtocolError>
pub fn leave(&mut self, topic: &str) -> Result<Outbound, ProtocolError>
Starts leaving a joined topic.
Sourcepub fn push(
&mut self,
topic: &str,
event: impl Into<String>,
payload: impl Into<Payload>,
) -> Result<Outbound, ProtocolError>
pub fn push( &mut self, topic: &str, event: impl Into<String>, payload: impl Into<Payload>, ) -> Result<Outbound, ProtocolError>
Builds and tracks an application push that expects a reply.
Sourcepub fn cast(
&self,
topic: &str,
event: impl Into<String>,
payload: impl Into<Payload>,
) -> Result<Frame, ProtocolError>
pub fn cast( &self, topic: &str, event: impl Into<String>, payload: impl Into<Payload>, ) -> Result<Frame, ProtocolError>
Builds a push that does not request a reply.
The frame has no ref, so it is not tracked as an in-flight request.
Sourcepub fn forget_push(&mut self, reference: &str) -> bool
pub fn forget_push(&mut self, reference: &str) -> bool
Stops correlating a push reply, for example after an API timeout.
Join and leave requests cannot be forgotten through this method because their replies also transition channel state.
Sourcepub fn forget_heartbeat(&mut self, reference: &str) -> bool
pub fn forget_heartbeat(&mut self, reference: &str) -> bool
Stops correlating a heartbeat reply, for example after an explicit ping has timed out at the client API boundary.
Sourcepub fn discard_channel(&mut self, topic: &str) -> bool
pub fn discard_channel(&mut self, topic: &str) -> bool
Removes all local state associated with a topic.
This is used when a channel handle is dropped. Any later replies for the removed join generation are treated as unmatched messages.
Sourcepub fn receive(&mut self, frame: Frame) -> Result<ProtocolEvent, ProtocolError>
pub fn receive(&mut self, frame: Frame) -> Result<ProtocolEvent, ProtocolError>
Applies an incoming frame and returns its semantic protocol event.
Sourcepub fn reset_connection(&mut self) -> Vec<ProtocolEvent>
pub fn reset_connection(&mut self) -> Vec<ProtocolEvent>
Marks active channels disconnected and returns interrupted requests.