pub struct WebChat { /* private fields */ }Expand description
WebSocket-based chat client for the browser.
Connects to a rift-ws-relay server and provides encrypted text chat.
Implementations§
Source§impl WebChat
impl WebChat
Sourcepub fn new(relay_url: &str, invite_url: &str) -> Result<WebChat, JsValue>
pub fn new(relay_url: &str, invite_url: &str) -> Result<WebChat, JsValue>
Create a new WebChat client and connect to the relay.
§Arguments
relay_url- WebSocket URL of the relay (e.g., “ws://localhost:8787/ws”)invite_url- Rift invite URL (e.g., “rift://z/…”)
Sourcepub fn send(&mut self, text: &str) -> Result<(), JsValue>
pub fn send(&mut self, text: &str) -> Result<(), JsValue>
Send a text message to the chat room.
Sourcepub fn on_message(&mut self, callback: Function)
pub fn on_message(&mut self, callback: Function)
Set callback for incoming chat messages.
Callback receives: { from: string, timestamp: number, text: string }
Sourcepub fn on_peer_event(&mut self, callback: Function)
pub fn on_peer_event(&mut self, callback: Function)
Set callback for peer join/leave events.
Callback receives: { peer_id: string, event: "join" | "leave" }
Sourcepub fn on_connect(&mut self, callback: Function)
pub fn on_connect(&mut self, callback: Function)
Set callback for successful connection.
Callback receives: { state: "connected", error: null }
Sourcepub fn on_disconnect(&mut self, callback: Function)
pub fn on_disconnect(&mut self, callback: Function)
Set callback for disconnection.
Callback receives: { state: "disconnected", error: null }
Sourcepub fn on_error(&mut self, callback: Function)
pub fn on_error(&mut self, callback: Function)
Set callback for errors.
Callback receives: { state: "error", error: string }
Sourcepub fn session_id(&self) -> String
pub fn session_id(&self) -> String
Get the session ID (hex-encoded).
Sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Disconnect from the relay.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if the WebSocket is open.
Trait Implementations§
Source§impl FromWasmAbi for WebChat
impl FromWasmAbi for WebChat
Source§impl IntoWasmAbi for WebChat
impl IntoWasmAbi for WebChat
Source§impl LongRefFromWasmAbi for WebChat
impl LongRefFromWasmAbi for WebChat
Source§impl OptionFromWasmAbi for WebChat
impl OptionFromWasmAbi for WebChat
Source§impl OptionIntoWasmAbi for WebChat
impl OptionIntoWasmAbi for WebChat
Source§impl RefFromWasmAbi for WebChat
impl RefFromWasmAbi for WebChat
Source§impl RefMutFromWasmAbi for WebChat
impl RefMutFromWasmAbi for WebChat
Source§impl TryFromJsValue for WebChat
impl TryFromJsValue for WebChat
Source§impl VectorFromWasmAbi for WebChat
impl VectorFromWasmAbi for WebChat
Source§impl VectorIntoWasmAbi for WebChat
impl VectorIntoWasmAbi for WebChat
impl SupportsConstructor for WebChat
impl SupportsInstanceProperty for WebChat
impl SupportsStaticProperty for WebChat
Auto Trait Implementations§
impl Freeze for WebChat
impl !RefUnwindSafe for WebChat
impl !Send for WebChat
impl !Sync for WebChat
impl Unpin for WebChat
impl !UnwindSafe for WebChat
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
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.