Trait jamsocket_wasm::prelude::JamsocketContext [−][src]
pub trait JamsocketContext: 'static + Unpin + Send + Sync {
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
Re-exports useful items from jamsocket
and jamsocket_wasm_macro
.
Provides an interface for a JamsocketService instance to send messages back to its host environment.
Required methods
fn send_message(&self, recipient: impl Into<MessageRecipient>, message: &str)
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.
fn send_binary(&self, recipient: impl Into<MessageRecipient>, message: &[u8])
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 JamsocketContext::send_message for details on the semantics of recipient
.
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.