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,
) -> UnboundedReceiver<Value>
pub fn register_ws( &self, conn_id: &str, tab_id: &str, ) -> UnboundedReceiver<Value>
Register a WebSocket connection for receiving events. Returns a receiver channel 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 broadcast_event(&self, event: &WSEventType)
pub fn broadcast_event(&self, event: &WSEventType)
Send an event to all connected WebSocket clients.
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
Mutably borrows from an owned value. Read more
§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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.