pub struct MessageBoxWebSocket { /* private fields */ }Expand description
WebSocket connection to the MessageBox server using Socket.IO v4 protocol
with BRC-103 mutual authentication via Peer<W>.
All application-level Socket.IO events (sendMessage, joinRoom, leaveRoom, etc.)
are sent through cryptographically signed authMessage envelopes. The public API
surface is unchanged from the pre-BRC-103 version.
The wallet type is erased at connection time: Peer<W> lives in a background
Tokio task and is accessed exclusively via the peer_tx command channel.
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 Peer<W> is type-erased into a background task — callers see only the
unchanged public API surface.
Returns an error if the handshake does not complete within 10 seconds, or
if authenticationSuccess is not received within 5 additional seconds.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Return true if the connection is currently authenticated.
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.
This is a 66-character compressed public key hex string. Useful for diagnostics and integration tests to verify the handshake completed successfully and the correct server identity was established.
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 through the BRC-103 Peer channel as a signed 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.
The leaveRoom event is sent through the BRC-103 Peer channel.
Sourcepub async fn subscribe(
&self,
event_key: String,
callback: Arc<dyn Fn(PeerMessage) + Send + Sync>,
)
pub async fn subscribe( &self, event_key: String, callback: Arc<dyn Fn(PeerMessage) + 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 channel.
The sendMessage event is encoded as a BRC-103 payload and sent through
the Peer command channel. The ack channel is triggered when the server
emits sendMessageAck-{ack_key} (primary: via BRC-103 general message,
fallback: via raw Socket.IO event).
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).
Sourcepub async fn disconnect(&self) -> Result<(), MessageBoxError>
pub async fn disconnect(&self) -> Result<(), MessageBoxError>
Disconnect from the server and clear all state.
Signals the peer_task to shut down, then disconnects the Socket.IO client. Sends false to all remaining pending ack channels before dropping them.