pub struct EventBus {
watches: Mutex<HashMap<String, WindowWatchData>>,
}Expand description
Global event bus for dispatching WebSocket events to connected clients.
Fields§
§watches: Mutex<HashMap<String, WindowWatchData>>Implementations§
Source§impl EventBus
impl EventBus
pub fn new() -> Self
Sourcepub fn register_ws(&self, conn_id: &str, tab_id: &str) -> WsReceivers
pub fn register_ws(&self, conn_id: &str, tab_id: &str) -> WsReceivers
Register a WebSocket connection for receiving events. Returns the priority + background receiver pair for the connection.
Sourcepub fn unregister_ws(&self, conn_id: &str)
pub fn unregister_ws(&self, conn_id: &str)
Unregister a WebSocket connection.
Sourcepub fn has_connections_for(&self, tab_id: &str) -> bool
pub fn has_connections_for(&self, tab_id: &str) -> bool
Check if any connections exist for a given window/tab ID.
Sourcepub async fn wait_for_connection(&self, tab_id: &str, timeout: Duration) -> bool
pub async fn wait_for_connection(&self, tab_id: &str, timeout: Duration) -> bool
Wait for a connection to appear for the given tab_id (with timeout).
Sourcepub fn send_to_conn(&self, conn_id: &str, event: &WSEventType)
pub fn send_to_conn(&self, conn_id: &str, event: &WSEventType)
Send an event to a single connection by conn_id, on the priority lane. No-op if not found.
Sourcepub fn send_to_conn_lane(&self, conn_id: &str, event: &WSEventType, lane: Lane)
pub fn send_to_conn_lane(&self, conn_id: &str, event: &WSEventType, lane: Lane)
Send an event to a single connection by conn_id on a specific lane. No-op if not found.
Sourcepub fn broadcast_event(&self, event: &WSEventType)
pub fn broadcast_event(&self, event: &WSEventType)
Broadcast an event to all connected WebSocket clients, on the priority lane.
Sourcepub fn broadcast_event_lane(&self, event: &WSEventType, lane: Lane)
pub fn broadcast_event_lane(&self, event: &WSEventType, lane: Lane)
Broadcast an event to all connected WebSocket clients on a specific lane.
Sourcepub fn send_to_tab(&self, tab_id: &str, event: &WSEventType)
pub fn send_to_tab(&self, tab_id: &str, event: &WSEventType)
Send an event to connections matching a specific tab_id.
Sourcepub fn connection_count(&self) -> usize
pub fn connection_count(&self) -> usize
Get the number of active connections.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for EventBus
impl RefUnwindSafe for EventBus
impl Send for EventBus
impl Sync for EventBus
impl Unpin for EventBus
impl UnwindSafe for EventBus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more