pub struct RoomDriver { /* private fields */ }Expand description
Forwards a Durable Object’s four entry points to a module’s RoomHandler.
Implementations§
Source§impl RoomDriver
impl RoomDriver
pub fn new(handler: Arc<dyn RoomHandler>) -> Self
Sourcepub fn route(&self) -> &'static str
pub fn route(&self) -> &'static str
The path prefix this driver’s handler declares, so a venture mounts the upgrade where the module says rather than where the venture guessed.
RoomHandler::route() documents itself as “the path prefix the runtime
mounts the upgrade endpoint under”, and nothing read it: a module that
overrode it compiled, documented its own prefix, and never received an
upgrade. One place now decides.
Sourcepub async fn upgrade(
&self,
state: &State,
member: &Member,
) -> WorkerResult<Response>
pub async fn upgrade( &self, state: &State, member: &Member, ) -> WorkerResult<Response>
Accept the upgrade and join member to the room.
accept_websocket_with_tags rather than accept_web_socket: the tag is
the member id, and it is the only thing that survives hibernation.
§Errors
When the socket pair cannot be created, or the handler refuses the join — in which case the socket is closed before the error is returned, because the client is already holding one end of an open pair.
Sourcepub async fn message(
&self,
state: &State,
ws: &WebSocket,
message: WebSocketIncomingMessage,
) -> WorkerResult<()>
pub async fn message( &self, state: &State, ws: &WebSocket, message: WebSocketIncomingMessage, ) -> WorkerResult<()>
A frame arrived. Text and binary both reach the handler as bytes; the module owns the protocol, so the framing distinction is not its business.
§Errors
When the module’s handler returns one. A frame from a socket carrying no member tag is dropped rather than failed: it is one this driver never accepted.
Sourcepub async fn error(&self, state: &State, ws: &WebSocket) -> WorkerResult<()>
pub async fn error(&self, state: &State, ws: &WebSocket) -> WorkerResult<()>
A socket failed, which is a leave by another name.
The class must forward this or the room dies. #[durable_object]
binds every handler including webSocketError, and the trait’s default
body is unimplemented!() — so one member’s phone dropping off mid-
session panics the object and takes every other socket in the room with
it. It is also the path where on_leave would otherwise never run.
§Errors
When the module’s handler returns one.