pub trait RoomHandler: Send + Sync {
// Required method
fn on_message<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
member: &'life2 Member,
message: &'life3 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
// Provided methods
fn route(&self) -> &'static str { ... }
fn on_join<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
member: &'life2 Member,
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn on_leave<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
member: &'life2 Member,
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn on_alarm<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
The protocol for one kind of room. A module implements it; the runtime owns the sockets and calls these as events arrive.
Implementations must be stateless — all room state lives in the room and
is reached through RoomContext — so a hibernating Durable Object can
reconstruct the handler on the next event. route() is the path prefix the
runtime mounts the upgrade endpoint under (GET <route>/<room_id>).
Required Methods§
Sourcefn on_message<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
member: &'life2 Member,
message: &'life3 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn on_message<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
member: &'life2 Member,
message: &'life3 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
A message arrived from a member’s socket.
Provided Methods§
Sourcefn route(&self) -> &'static str
fn route(&self) -> &'static str
The path prefix for this room’s upgrade endpoint, e.g. "/rooms". The
runtime serves GET <route>/<room_id> as the WebSocket upgrade.
Sourcefn on_join<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
member: &'life2 Member,
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_join<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
member: &'life2 Member,
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
A member’s socket has opened and joined the room.
Sourcefn on_leave<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
member: &'life2 Member,
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_leave<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
member: &'life2 Member,
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
A member’s socket has closed and left the room.
Sourcefn on_alarm<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_alarm<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 dyn RoomContext,
) -> Pin<Box<dyn Future<Output = Result<(), RealtimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
A previously scheduled alarm fired (the shared clock tick).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".