Skip to main content

RoomClient

Struct RoomClient 

Source
pub struct RoomClient {
    pub namespace: String,
    pub room_id: String,
    /* private fields */
}

Fields§

§namespace: String

Room namespace (e.g. “game”, “chat”)

§room_id: String

Room instance ID within the namespace

Implementations§

Source§

impl RoomClient

Source

pub fn new( base_url: &str, namespace: &str, room_id: &str, token_fn: impl Fn() -> String + Send + Sync + 'static, opts: Option<RoomOptions>, ) -> Arc<Self>

Create a new v2 RoomClient.

§Arguments
  • base_url - EdgeBase server URL (http or https)
  • namespace - Room namespace (e.g. “game”, “chat”)
  • room_id - Room instance ID within the namespace
  • token_fn - Closure that returns the current access token
  • opts - Optional RoomOptions for reconnect and timeout configuration
Source

pub fn get_shared_state(&self) -> Value

Get current shared state (read-only snapshot).

Source

pub fn get_player_state(&self) -> Value

Get current player state (read-only snapshot).

Source

pub fn list_members(&self) -> Value

Get the current logical room members snapshot.

Source

pub fn list_media_members(&self) -> Value

Get the current media member snapshot.

Source

pub fn connection_state(&self) -> String

Get the current session connection state.

Source

pub fn state(self: &Arc<Self>) -> RoomStateNamespace

Source

pub fn meta(self: &Arc<Self>) -> RoomMetaNamespace

Source

pub fn signals(self: &Arc<Self>) -> RoomSignalsNamespace

Source

pub fn members(self: &Arc<Self>) -> RoomMembersNamespace

Source

pub fn admin(self: &Arc<Self>) -> RoomAdminNamespace

Source

pub fn media(self: &Arc<Self>) -> RoomMediaNamespace

Source

pub fn session(self: &Arc<Self>) -> RoomSessionNamespace

Source

pub async fn get_metadata(&self) -> Result<Value, Error>

Get room metadata without joining (HTTP GET). Returns developer-defined metadata set by room.setMetadata() on the server.

Source

pub async fn get_metadata_static( base_url: &str, namespace: &str, room_id: &str, ) -> Result<Value, Error>

Static: Get room metadata without creating a RoomClient instance. Useful for lobby screens where you need room info before joining.

Source

pub async fn join(self: &Arc<Self>) -> Result<(), Error>

Connect to the room, authenticate, and join.

Source

pub async fn leave(&self)

Leave the room and disconnect. Cleans up all pending send() requests.

Source

pub async fn send( &self, action_type: &str, payload: Option<Value>, ) -> Result<Value, Error>

Send an action to the server. Returns a Result that resolves with the action result from the server.

§Example
let result = room.send("SET_SCORE", Some(json!({"score": 42}))).await?;
Source

pub fn on_shared_state( &self, handler: impl Fn(&Value, &Value) + Send + Sync + 'static, ) -> Subscription

Subscribe to shared state changes. Handler receives (full_state, changes) on each sync/delta.

Source

pub fn on_player_state( &self, handler: impl Fn(&Value, &Value) + Send + Sync + 'static, ) -> Subscription

Subscribe to player state changes. Handler receives (full_state, changes) on each sync/delta.

Source

pub fn on_message( &self, msg_type: &str, handler: impl Fn(&Value) + Send + Sync + 'static, ) -> Subscription

Subscribe to messages of a specific type sent by room.sendMessage().

§Example
let sub = room.on_message("game_over", |data| { println!("{:?}", data); });
Source

pub fn on_error( &self, handler: impl Fn(&str, &str) + Send + Sync + 'static, ) -> Subscription

Subscribe to error events.

Source

pub fn on_kicked( &self, handler: impl Fn() + Send + Sync + 'static, ) -> Subscription

Subscribe to kick events. After being kicked, auto-reconnect is disabled.

Source

pub fn on_members_sync( &self, handler: impl Fn(&Value) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_member_join( &self, handler: impl Fn(&Value) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_member_leave( &self, handler: impl Fn(&Value, &str) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_member_state_change( &self, handler: impl Fn(&Value, &Value) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_signal( &self, event: &str, handler: impl Fn(&Value, &Value) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_any_signal( &self, handler: impl Fn(&str, &Value, &Value) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_media_track( &self, handler: impl Fn(&Value, &Value) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_media_track_removed( &self, handler: impl Fn(&Value, &Value) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_media_state_change( &self, handler: impl Fn(&Value, &Value) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_media_device_change( &self, handler: impl Fn(&Value, &Value) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_reconnect( &self, handler: impl Fn(&Value) + Send + Sync + 'static, ) -> Subscription

Source

pub fn on_connection_state_change( &self, handler: impl Fn(&str) + Send + Sync + 'static, ) -> Subscription

Source

pub async fn send_signal( &self, event: &str, payload: Option<Value>, options: Option<Value>, ) -> Result<(), Error>

Source

pub async fn send_member_state(&self, state: Value) -> Result<(), Error>

Source

pub async fn clear_member_state(&self) -> Result<(), Error>

Source

pub async fn send_admin( &self, operation: &str, member_id: &str, payload: Option<Value>, ) -> Result<(), Error>

Source

pub async fn send_media( &self, operation: &str, kind: &str, payload: Option<Value>, ) -> Result<(), Error>

Source

pub async fn switch_media_devices(&self, payload: Value) -> Result<(), Error>

Source

pub async fn destroy(self: &Arc<Self>)

Leave the room, clear all handler lists, and release resources. After calling destroy(), this RoomClient instance should not be reused.

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: 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: 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