pub struct RoomClient {
pub namespace: String,
pub room_id: String,
/* private fields */
}Fields§
§namespace: StringRoom namespace (e.g. “game”, “chat”)
room_id: StringRoom instance ID within the namespace
Implementations§
Source§impl RoomClient
impl RoomClient
Sourcepub fn new(
base_url: &str,
namespace: &str,
room_id: &str,
token_fn: impl Fn() -> String + Send + Sync + 'static,
opts: Option<RoomOptions>,
) -> Arc<Self>
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 namespacetoken_fn- Closure that returns the current access tokenopts- Optional RoomOptions for reconnect and timeout configuration
Get current shared state (read-only snapshot).
Sourcepub fn get_player_state(&self) -> Value
pub fn get_player_state(&self) -> Value
Get current player state (read-only snapshot).
Sourcepub fn list_members(&self) -> Value
pub fn list_members(&self) -> Value
Get the current logical room members snapshot.
Sourcepub fn list_media_members(&self) -> Value
pub fn list_media_members(&self) -> Value
Get the current media member snapshot.
Sourcepub fn connection_state(&self) -> String
pub fn connection_state(&self) -> String
Get the current session connection state.
pub fn state(self: &Arc<Self>) -> RoomStateNamespace
pub fn meta(self: &Arc<Self>) -> RoomMetaNamespace
pub fn signals(self: &Arc<Self>) -> RoomSignalsNamespace
pub fn members(self: &Arc<Self>) -> RoomMembersNamespace
pub fn admin(self: &Arc<Self>) -> RoomAdminNamespace
pub fn media(self: &Arc<Self>) -> RoomMediaNamespace
pub fn session(self: &Arc<Self>) -> RoomSessionNamespace
Sourcepub async fn get_metadata(&self) -> Result<Value, Error>
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.
Sourcepub async fn get_metadata_static(
base_url: &str,
namespace: &str,
room_id: &str,
) -> Result<Value, Error>
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.
Sourcepub async fn join(self: &Arc<Self>) -> Result<(), Error>
pub async fn join(self: &Arc<Self>) -> Result<(), Error>
Connect to the room, authenticate, and join.
Sourcepub async fn leave(&self)
pub async fn leave(&self)
Leave the room and disconnect. Cleans up all pending send() requests.
Sourcepub async fn send(
&self,
action_type: &str,
payload: Option<Value>,
) -> Result<Value, Error>
pub async fn send( &self, action_type: &str, payload: Option<Value>, ) -> Result<Value, Error>
Subscribe to shared state changes. Handler receives (full_state, changes) on each sync/delta.
Sourcepub fn on_player_state(
&self,
handler: impl Fn(&Value, &Value) + Send + Sync + 'static,
) -> Subscription
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.
Sourcepub fn on_message(
&self,
msg_type: &str,
handler: impl Fn(&Value) + Send + Sync + 'static,
) -> Subscription
pub fn on_message( &self, msg_type: &str, handler: impl Fn(&Value) + Send + Sync + 'static, ) -> Subscription
Sourcepub fn on_error(
&self,
handler: impl Fn(&str, &str) + Send + Sync + 'static,
) -> Subscription
pub fn on_error( &self, handler: impl Fn(&str, &str) + Send + Sync + 'static, ) -> Subscription
Subscribe to error events.
Sourcepub fn on_kicked(
&self,
handler: impl Fn() + Send + Sync + 'static,
) -> Subscription
pub fn on_kicked( &self, handler: impl Fn() + Send + Sync + 'static, ) -> Subscription
Subscribe to kick events. After being kicked, auto-reconnect is disabled.