pub struct WsSession { /* private fields */ }Expand description
Manages one WebSocket connection’s lifecycle and message routing.
This struct doesn’t own the WebSocket transport directly — it provides
the logic layer. The transport integration (e.g. actix-web, tungstenite)
calls into WsSession methods.
Implementations§
Source§impl WsSession
impl WsSession
Sourcepub fn new(hub: Arc<BextHub>, config: WsSessionConfig) -> Self
pub fn new(hub: Arc<BextHub>, config: WsSessionConfig) -> Self
Create a new WebSocket session.
Call take_outbound_receiver() to get the stream of messages to send
to the WebSocket client.
Sourcepub fn take_outbound_receiver(&mut self) -> Option<Receiver<ServerMessage>>
pub fn take_outbound_receiver(&mut self) -> Option<Receiver<ServerMessage>>
Take the outbound message receiver.
The transport layer reads from this to send messages over the WebSocket. Can only be called once.
Sourcepub fn take_hub_receiver(&mut self) -> Option<Receiver<HubEvent>>
pub fn take_hub_receiver(&mut self) -> Option<Receiver<HubEvent>>
Take the hub event receiver.
The transport layer reads from this and calls forward_hub_event for each.
Can only be called once (after at least one subscribe).
Sourcepub fn handle_text(&mut self, text: &str) -> Result<(), String>
pub fn handle_text(&mut self, text: &str) -> Result<(), String>
Handle an incoming text message from the WebSocket client.
Parses JSON into ClientMessage and dispatches accordingly.
Returns an error string if parsing fails.
Sourcepub fn handle_message(&mut self, msg: ClientMessage)
pub fn handle_message(&mut self, msg: ClientMessage)
Handle a parsed ClientMessage.
Sourcepub fn forward_hub_event(&self, event: HubEvent)
pub fn forward_hub_event(&self, event: HubEvent)
Forward a hub event to the WebSocket client as a ServerMessage::Event.
Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Check if the connection is alive (received a pong within timeout).
Sourcepub fn send_error(&self, message: String)
pub fn send_error(&self, message: String)
Send an error message to the client.
Sourcepub fn subscriber_id(&self) -> Option<u64>
pub fn subscriber_id(&self) -> Option<u64>
Get the subscriber ID (if subscribed).
Sourcepub fn config(&self) -> &WsSessionConfig
pub fn config(&self) -> &WsSessionConfig
Get the configuration.