pub struct Client {
    sender: Arc<Mutex<SplitSink<WebSocket, Message>>>,
    room_id: Option<String>,
}
Expand description

Struct representing a WebSocket client.

This struct contains a WebSocket sender and an optional room ID. The sender is used to send messages to the WebSocket connection, while the room ID is used to identify the client’s room.

Fields§

§sender: Arc<Mutex<SplitSink<WebSocket, Message>>>

The WebSocket sender for sending messages.

§room_id: Option<String>

The optional room ID of the client.

This is used to identify the client’s room.

Implementations§

source§

impl Client

source

pub fn new(sender: Arc<Mutex<SplitSink<WebSocket, Message>>>) -> Client

Creates a new WebSocket client.

§Arguments
  • sender - A synchronized WebSocket sender.
§Returns

A new WebSocket client instance.

source

async fn send( &self, sender: Arc<Mutex<SplitSink<WebSocket, Message>>>, message: Message )

Sends a message to the WebSocket connection.

§Arguments
  • sender - A synchronized WebSocket sender.
  • message - The message to send.
§Errors

If the message fails to be sent.

source

async fn send_packet( &self, sender: Arc<Mutex<SplitSink<WebSocket, Message>>>, packet: ResponsePacket )

Sends a serialized packet to the WebSocket connection.

§Arguments
  • sender - A synchronized WebSocket sender.
  • packet - The packet to send.
§Errors

If the serialized packet fails to be sent.

source

async fn send_error_packet( &self, sender: Arc<Mutex<SplitSink<WebSocket, Message>>>, message: String )

Sends an error message to the WebSocket connection.

§Arguments
  • sender - A synchronized WebSocket sender.
  • message - The error message to send.
§Errors

If the error message fails to be sent.

source

async fn handle_create_room( &mut self, server: &RwLock<AppState>, id: Option<String> )

Handles the “create_room” request from a client.

§Arguments
  • server - A lock guard of the AppState.
  • id - An optional string representing the room identifier.
§Errors

If the room already exists or if the room creation fails.

source

async fn handle_join_room(&mut self, server: &RwLock<AppState>, room_id: String)

Handles the “join_room” request from a client.

§Arguments
  • server - A lock guard of the AppState.
  • room_id - A string representing the room identifier.
§Errors

If the room does not exist or if the room is full.

source

async fn handle_leave_room(&mut self, server: &RwLock<AppState>)

Handle the leave room request from the client.

This function removes the client from the current room and notifies the other clients in the room about the client’s departure.

§Arguments
  • server - A read-write lock guard for the server state.
§Returns

This function does not return anything.

source

pub async fn handle_message( &mut self, server: &RwLock<AppState>, message: Message )

Handles incoming messages from the client.

This function interprets the incoming message and performs the corresponding action.

§Arguments
  • server - A RwLock guard containing the state of the server.
  • message - The incoming message from the client.
source

pub async fn handle_close(&mut self, server: &RwLock<AppState>)

Trait Implementations§

source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,