pub struct MessageBoxWebSocket { /* private fields */ }Expand description
WebSocket connection to the MessageBox server: the shared authsocket BRC-103 client plus the MessageBox application routing.
Implementations§
Source§impl MessageBoxWebSocket
impl MessageBoxWebSocket
Sourcepub async fn connect<W>(
url: &str,
identity_key: &str,
wallet: W,
originator: Option<String>,
) -> Result<Self, MessageBoxError>
pub async fn connect<W>( url: &str, identity_key: &str, wallet: W, originator: Option<String>, ) -> Result<Self, MessageBoxError>
Connect to the MessageBox Socket.IO server and authenticate via BRC-103.
Performs the full BRC-103 mutual authentication handshake before
returning (the authsocket client blocks until the server’s signed
authenticationSuccess).
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Return true if the connection is currently authenticated.
Sourcepub fn ms_since_last_inbound(&self) -> u64
pub fn ms_since_last_inbound(&self) -> u64
Milliseconds since the last inbound frame of any kind (the read-deadline tracker used for half-open detection).
Sourcepub fn server_identity_key(&self) -> &str
pub fn server_identity_key(&self) -> &str
Return the server’s BRC-103 identity key captured during the handshake.
Sourcepub async fn join_room(&self, room_id: &str) -> Result<(), MessageBoxError>
pub async fn join_room(&self, room_id: &str) -> Result<(), MessageBoxError>
Join a Socket.IO room (idempotent — no-op if already joined).
The joinRoom event is sent as a signed BRC-103 authMessage envelope.
Sourcepub async fn leave_room(&self, room_id: &str) -> Result<(), MessageBoxError>
pub async fn leave_room(&self, room_id: &str) -> Result<(), MessageBoxError>
Leave a Socket.IO room and remove its subscription.
Local subscription state is torn down unconditionally before the wire emit, so a dead socket cannot leave a stale subscription behind.
Sourcepub async fn subscribe(
&self,
event_key: String,
callback: Arc<dyn Fn(AuthenticatedPeerMessage) + Send + Sync>,
)
pub async fn subscribe( &self, event_key: String, callback: Arc<dyn Fn(AuthenticatedPeerMessage) + Send + Sync>, )
Register a callback for incoming messages on a given event key.
event_key is typically "sendMessage-{room_id}".
Sourcepub async fn emit_send_message(
&self,
payload: Value,
ack_key: String,
ack_tx: Sender<bool>,
) -> Result<(), MessageBoxError>
pub async fn emit_send_message( &self, payload: Value, ack_key: String, ack_tx: Sender<bool>, ) -> Result<(), MessageBoxError>
Emit a sendMessage event and register an ack waiter.
The sendMessage event is signed as a BRC-103 general message and emitted
directly on the socket — concurrent calls sign + emit + await their acks
in parallel. The ack waiter is enqueued under sendMessageAck-{ack_key}
and resolved FIFO when the server emits that room-scoped ack.
Sourcepub async fn remove_pending_ack(&self, key: &str)
pub async fn remove_pending_ack(&self, key: &str)
Remove a pending ack entry (called on timeout to prevent leaking channels).
Pops the OLDEST waiter for the key — under FIFO ack matching, a timeout on the oldest in-flight send is the one most likely to have been abandoned.
Sourcepub async fn disconnect(&self) -> Result<(), MessageBoxError>
pub async fn disconnect(&self) -> Result<(), MessageBoxError>
Disconnect from the server and clear all state.
Sends false to all remaining pending ack waiters before dropping them.