pub struct WsSession { /* private fields */ }Expand description
An established JMAP WebSocket session (RFC 8887).
Call next_frame in a loop to receive events.
Use send_request to transmit JMAP requests.
The caller is responsible for reconnecting after the stream ends or returns a transport error. Use exponential backoff.
Implementations§
Source§impl WsSession
impl WsSession
Sourcepub async fn next_frame(&mut self) -> Option<Result<WsFrame, ClientError>>
pub async fn next_frame(&mut self) -> Option<Result<WsFrame, ClientError>>
Receive the next parsed frame from the server.
Returns None when the server has cleanly closed the connection.
Returns Some(Err(...)) on parse failure, transport error, RFC 8887
§4.1 violation (Binary frame), or starvation cap (more than 64
consecutive Ping/Pong/Frame messages — see the private
MAX_CONSECUTIVE_NON_TEXT_FRAMES constant for the exact value).
After a transport error the connection is broken and next_frame
must not be called again. After an UnexpectedResponse error the
underlying stream is still healthy — the caller may choose to
ignore it and retry, or to disconnect.
Sourcepub async fn send_text(&mut self, text: String) -> Result<(), ClientError>
pub async fn send_text(&mut self, text: String) -> Result<(), ClientError>
Send a raw text frame over the WebSocket connection.
Used by extension crates to send non-JMAP frames (e.g., JMAP Chat ephemeral stream control messages).
Sourcepub async fn send_request(
&mut self,
req: &JmapRequest,
id: Option<&str>,
) -> Result<(), ClientError>
pub async fn send_request( &mut self, req: &JmapRequest, id: Option<&str>, ) -> Result<(), ClientError>
Send a JMAP request over the WebSocket connection.
Serializes req and injects "@type": "Request" into the outgoing
JSON object as required by RFC 8887 §4.3.2. The optional id is
echoed back in the corresponding Response frame, enabling out-of-order
correlation.
§Errors
Returns ClientError::Serialize if req cannot be serialized, or
ClientError::WebSocket on a transport failure.