pub struct WsSession {
pub url: String,
pub protocol: WsProtocol,
pub domain: String,
/* private fields */
}Expand description
An active WebSocket session.
Wraps a tokio-tungstenite connection with session metadata
(cookies, auth tokens, protocol details).
Fields§
§url: StringThe WebSocket URL this session is connected to.
protocol: WsProtocolThe protocol used (Raw, Socket.IO, SockJS, SignalR).
domain: StringDomain of the connected site.
Implementations§
Source§impl WsSession
impl WsSession
Sourcepub async fn connect(
endpoint: &WsEndpoint,
cookies: &HashMap<String, String>,
) -> Result<Self>
pub async fn connect( endpoint: &WsEndpoint, cookies: &HashMap<String, String>, ) -> Result<Self>
Connect to a WebSocket endpoint.
Builds the connection URL and optional headers (cookies, auth tokens), then opens the WebSocket connection.
Sourcepub async fn send_json<T: Serialize>(&mut self, msg: &T) -> Result<()>
pub async fn send_json<T: Serialize>(&mut self, msg: &T) -> Result<()>
Send a JSON-serializable message over the WebSocket.
For Socket.IO, wraps the message in the appropriate frame format. For raw WebSocket, sends as-is.
Sourcepub async fn receive(&mut self) -> Result<Option<String>>
pub async fn receive(&mut self) -> Result<Option<String>>
Receive the next message from the WebSocket.
Returns None if the connection is closed. Automatically skips
ping/pong control frames and returns the next data message.
Sourcepub async fn watch(&mut self, duration_ms: u64) -> Result<Vec<WsMessage>>
pub async fn watch(&mut self, duration_ms: u64) -> Result<Vec<WsMessage>>
Receive messages for a given duration, returning all collected messages.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Whether the connection is currently open.