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 or transport error. After a
transport error the connection is broken; do not call next_frame again.
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.