Skip to main content

MessageBoxWebSocket

Struct MessageBoxWebSocket 

Source
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

Source

pub async fn connect<W>( url: &str, identity_key: &str, wallet: W, originator: Option<String>, ) -> Result<Self, MessageBoxError>
where W: WalletInterface + Clone + Send + Sync + 'static,

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.

Source

pub fn is_connected(&self) -> bool

Return true if the connection is currently authenticated.

Source

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.

Source

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.

Source

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.

Source

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}".

Source

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).

Source

pub async fn remove_pending_ack(&self, key: &str)

Remove a pending ack entry (called on timeout to prevent leaking channels).

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more