pub trait StateroomContext {
    // Required methods
    fn send_message(&self, recipient: impl Into<MessageRecipient>, message: &str);
    fn send_binary(&self, recipient: impl Into<MessageRecipient>, message: &[u8]);
    fn set_timer(&self, ms_delay: u32);
}
Expand description

Provides an interface for a StateroomService instance to send messages back to its host environment.

Required Methods§

source

fn send_message(&self, recipient: impl Into<MessageRecipient>, message: &str)

Sends a message to a currently connected user, or broadcast a message to all users.

Recipient can be a u32 representing an individual user to send a message to, or MessageRecipient::Broadcast to broadcast a message to all connected users. The message is a string which is sent verbatim to the user(s) indicated.

source

fn send_binary(&self, recipient: impl Into<MessageRecipient>, message: &[u8])

Sends a binary message to a currently connected user, or broadcast a message to all users.

See StateroomContext::send_message for details on the semantics of recipient.

source

fn set_timer(&self, ms_delay: u32)

Sets a timer to wake up the service in the given number of milliseconds by invoking timer().

Each instance of a service can only have one (or zero) timer outstanding at any time; if this is called before an existing timer expires, the previous timer is replaced. This provides a very basic primitive that more complex timer behavior can be built on, using state and logic stored in your service. For example, you could implement multiple concurrent timers using a priority queue and ensuring that the environment timer always reflects the head of the queue.

Implementors§