pub struct WsContext {
pub connection_id: ConnectionId,
pub path: String,
/* private fields */
}Expand description
Context provided to handlers for each connection
Fields§
§connection_id: ConnectionIdUnique connection ID
path: StringWebSocket path
Implementations§
Source§impl WsContext
impl WsContext
Sourcepub fn new(
connection_id: ConnectionId,
path: String,
room_manager: RoomManager,
message_tx: UnboundedSender<Message>,
) -> Self
pub fn new( connection_id: ConnectionId, path: String, room_manager: RoomManager, message_tx: UnboundedSender<Message>, ) -> Self
Create a new WebSocket context
Sourcepub async fn send_text(&self, text: &str) -> HandlerResult<()>
pub async fn send_text(&self, text: &str) -> HandlerResult<()>
Send a text message
Sourcepub async fn send_binary(&self, data: Vec<u8>) -> HandlerResult<()>
pub async fn send_binary(&self, data: Vec<u8>) -> HandlerResult<()>
Send a binary message
Sourcepub async fn send_json(&self, value: &Value) -> HandlerResult<()>
pub async fn send_json(&self, value: &Value) -> HandlerResult<()>
Send a JSON message
Sourcepub async fn join_room(&self, room: &str) -> HandlerResult<()>
pub async fn join_room(&self, room: &str) -> HandlerResult<()>
Join a room
Sourcepub async fn leave_room(&self, room: &str) -> HandlerResult<()>
pub async fn leave_room(&self, room: &str) -> HandlerResult<()>
Leave a room
Sourcepub async fn broadcast_to_room(
&self,
room: &str,
text: &str,
) -> HandlerResult<()>
pub async fn broadcast_to_room( &self, room: &str, text: &str, ) -> HandlerResult<()>
Broadcast text to all members in a room
Sourcepub async fn set_metadata(&self, key: &str, value: Value)
pub async fn set_metadata(&self, key: &str, value: Value)
Set metadata value
Sourcepub async fn get_metadata(&self, key: &str) -> Option<Value>
pub async fn get_metadata(&self, key: &str) -> Option<Value>
Get metadata value
Auto Trait Implementations§
impl Freeze for WsContext
impl !RefUnwindSafe for WsContext
impl Send for WsContext
impl Sync for WsContext
impl Unpin for WsContext
impl !UnwindSafe for WsContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request