Skip to main content

RoomDriver

Struct RoomDriver 

Source
pub struct RoomDriver { /* private fields */ }
Expand description

Forwards a Durable Object’s four entry points to a module’s RoomHandler.

Implementations§

Source§

impl RoomDriver

Source

pub fn new(handler: Arc<dyn RoomHandler>) -> Self

Source

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.

Source

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.

Source

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.

Source

pub async fn close(&self, state: &State, ws: &WebSocket) -> WorkerResult<()>

The socket closed, by either end.

§Errors

When the module’s handler returns one.

Source

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.

Source

pub async fn alarm(&self, state: &State) -> WorkerResult<Response>

The shared clock ticked.

§Errors

When the module’s handler returns one.

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
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