Skip to main content

WebChat

Struct WebChat 

Source
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

Source

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/…”)
Source

pub fn send(&mut self, text: &str) -> Result<(), JsValue>

Send a text message to the chat room.

Source

pub fn on_message(&mut self, callback: Function)

Set callback for incoming chat messages.

Callback receives: { from: string, timestamp: number, text: string }

Source

pub fn on_peer_event(&mut self, callback: Function)

Set callback for peer join/leave events.

Callback receives: { peer_id: string, event: "join" | "leave" }

Source

pub fn on_connect(&mut self, callback: Function)

Set callback for successful connection.

Callback receives: { state: "connected", error: null }

Source

pub fn on_disconnect(&mut self, callback: Function)

Set callback for disconnection.

Callback receives: { state: "disconnected", error: null }

Source

pub fn on_error(&mut self, callback: Function)

Set callback for errors.

Callback receives: { state: "error", error: string }

Source

pub fn peer_id(&self) -> String

Get this client’s peer ID (hex-encoded).

Source

pub fn room(&self) -> String

Get the room/channel name.

Source

pub fn session_id(&self) -> String

Get the session ID (hex-encoded).

Source

pub fn disconnect(&self)

Disconnect from the relay.

Source

pub fn is_connected(&self) -> bool

Check if the WebSocket is open.

Trait Implementations§

Source§

impl From<WebChat> for JsValue

Source§

fn from(value: WebChat) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for WebChat

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for WebChat

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for WebChat

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<WebChat>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for WebChat

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for WebChat

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for WebChat

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<WebChat>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for WebChat

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<WebChat>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl SupportsConstructor for WebChat

Source§

impl SupportsInstanceProperty for WebChat

Source§

impl SupportsStaticProperty for WebChat

Source§

impl TryFromJsValue for WebChat

Source§

fn try_from_js_value(value: JsValue) -> Result<Self, JsValue>

Performs the conversion.
Source§

fn try_from_js_value_ref(value: &JsValue) -> Option<Self>

Performs the conversion.
Source§

impl VectorFromWasmAbi for WebChat

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

Source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[WebChat]>

Source§

impl VectorIntoWasmAbi for WebChat

Source§

impl WasmDescribe for WebChat

Source§

impl WasmDescribeVector for WebChat

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, 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> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
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