pub struct Session<T> { /* private fields */ }Expand description
A sequential, runtime-neutral Phoenix Channels session.
Session owns a transport and preserves server events that arrive while a
join, push, leave, or heartbeat reply is being awaited. Applications that
need commands from multiple tasks should own the session in one task and
communicate with it over their executor’s channel type.
Implementations§
Source§impl<T: Transport> Session<T>
impl<T: Transport> Session<T>
Sourcepub fn with_codec(transport: T, codec: impl Codec + 'static) -> Self
pub fn with_codec(transport: T, codec: impl Codec + 'static) -> Self
Creates a session with an application-provided codec.
Sourcepub fn protocol_mut(&mut self) -> &mut Protocol
pub fn protocol_mut(&mut self) -> &mut Protocol
Mutably borrows the session’s protocol state.
Sourcepub fn transport_mut(&mut self) -> &mut T
pub fn transport_mut(&mut self) -> &mut T
Mutably borrows the underlying transport.
Sourcepub fn into_parts(self) -> (Protocol, T)
pub fn into_parts(self) -> (Protocol, T)
Consumes the session and returns its protocol and transport.
Sourcepub async fn join(
&mut self,
topic: impl Into<String>,
params: Value,
) -> Result<ProtocolEvent, SessionError>
pub async fn join( &mut self, topic: impl Into<String>, params: Value, ) -> Result<ProtocolEvent, SessionError>
Sends a join and waits for its correlated reply.
Sourcepub async fn rejoin(
&mut self,
topic: impl Into<String>,
refreshed_params: Value,
) -> Result<ProtocolEvent, SessionError>
pub async fn rejoin( &mut self, topic: impl Into<String>, refreshed_params: Value, ) -> Result<ProtocolEvent, SessionError>
Sends a rejoin with refreshed parameters and waits for its reply.
Sourcepub async fn push(
&mut self,
topic: &str,
event: impl Into<String>,
payload: impl Into<Payload>,
) -> Result<ProtocolEvent, SessionError>
pub async fn push( &mut self, topic: &str, event: impl Into<String>, payload: impl Into<Payload>, ) -> Result<ProtocolEvent, SessionError>
Sends an application event and waits for its correlated reply.
Sourcepub async fn leave(
&mut self,
topic: &str,
) -> Result<ProtocolEvent, SessionError>
pub async fn leave( &mut self, topic: &str, ) -> Result<ProtocolEvent, SessionError>
Leaves a joined topic and waits for its reply.
Sourcepub async fn heartbeat(&mut self) -> Result<ProtocolEvent, SessionError>
pub async fn heartbeat(&mut self) -> Result<ProtocolEvent, SessionError>
Sends a Phoenix heartbeat and waits for its acknowledgement.
Sourcepub async fn next_event(&mut self) -> Result<ProtocolEvent, SessionError>
pub async fn next_event(&mut self) -> Result<ProtocolEvent, SessionError>
Returns the next buffered or transport event.
Sourcepub fn reset_connection(&mut self) -> Vec<ProtocolEvent>
pub fn reset_connection(&mut self) -> Vec<ProtocolEvent>
Marks all channels disconnected and returns the requests interrupted by
transport loss. The caller can then reconnect a transport and call
rejoin with refreshed authentication parameters.
Sourcepub async fn close(&mut self) -> Result<(), SessionError>
pub async fn close(&mut self) -> Result<(), SessionError>
Closes the underlying transport.