Skip to main content

WsSession

Struct WsSession 

Source
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

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn handle_message(&mut self, msg: ClientMessage)

Handle a parsed ClientMessage.

Source

pub fn forward_hub_event(&self, event: HubEvent)

Forward a hub event to the WebSocket client as a ServerMessage::Event.

Source

pub fn send_ping(&self)

Send a Ping to the client. Called periodically by the transport layer.

Source

pub fn is_alive(&self) -> bool

Check if the connection is alive (received a pong within timeout).

Source

pub fn send_error(&self, message: String)

Send an error message to the client.

Source

pub fn subscriber_id(&self) -> Option<u64>

Get the subscriber ID (if subscribed).

Source

pub fn config(&self) -> &WsSessionConfig

Get the configuration.

Source

pub fn cleanup(&mut self)

Clean up on disconnect — unsubscribe from the hub.

Trait Implementations§

Source§

impl Drop for WsSession

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more