pub struct WsServer { /* private fields */ }Expand description
WebSocket server adapter that accepts inbound connections.
Listens on a TCP port and spawns a WsConn actor for each incoming
WebSocket connection. Optionally serves a web UI on port + 1 for
peer ID discovery.
Implementations§
Source§impl WsServer
impl WsServer
Sourcepub fn new_with_config(config: Config, ws_config: WsServerConfig) -> Self
pub fn new_with_config(config: Config, ws_config: WsServerConfig) -> Self
Creates a new WebSocket server with custom config.
§Arguments
config- Node configurationws_config- WebSocket server config (port, TLS)
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Returns the current number of connected WebSocket peers.
Test-only helper to poll mesh readiness without relying on
blind sleeps. The count reflects the number of WsConn
actors that have completed the WebSocket handshake and
registered themselves in the server’s client set.
§Use
// Wait for both peers to connect before broadcasting a Put.
while ws_server.peer_count() < 2 {
sleep(Duration::from_millis(50)).await;
}Trait Implementations§
Source§impl Actor for WsServer
impl Actor for WsServer
Source§fn handle<'life0, 'life1, 'async_trait>(
&'life0 mut self,
msg: Arc<Message>,
_ctx: &'life1 ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle<'life0, 'life1, 'async_trait>(
&'life0 mut self,
msg: Arc<Message>,
_ctx: &'life1 ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Relays wire-format messages (Put, Get, Hi, BatchPut, Flush, RtcSignal) to all connected WebSocket clients except the sender. Internal messages (CheckQuorumTimeouts, RegisterQuorum) are never relayed — they are router-internal and would produce empty or malformed frames on the wire.
Source§fn subscribe_to_everything(&self) -> bool
fn subscribe_to_everything(&self) -> bool
WsServer is a relay adapter — it fans out Puts to all connected
WebSocket clients. Must return true so the Router adds it to
server_peers and relays Put messages through it.
Source§fn is_relay_server(&self) -> bool
fn is_relay_server(&self) -> bool
WsServer is a relay server — it accepts incoming connections and
fans out to individual WsConn clients. The Router always relays
to WsServer (even for messages from remote peers) because the
WsServer handles per-connection echo-back via msg.is_from(conn).