WebSocketHandler

Trait WebSocketHandler 

Source
pub trait WebSocketHandler:
    Send
    + Sync
    + 'static {
    // Required method
    fn on_message<'life0, 'life1, 'async_trait>(
        &'life0 self,
        connection_id: &'life1 str,
        message: Message,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn on_connect<'life0, 'life1, 'async_trait>(
        &'life0 self,
        connection_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_disconnect<'life0, 'life1, 'async_trait>(
        &'life0 self,
        connection_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_error<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        connection_id: &'life1 str,
        error: &'life2 WebSocketError,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_ping<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        connection_id: &'life1 str,
        payload: &'life2 [u8],
    ) -> Pin<Box<dyn Future<Output = Vec<u8>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_pong<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        connection_id: &'life1 str,
        payload: &'life2 [u8],
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Trait for handling WebSocket events.

Implement this trait to define custom behavior for WebSocket connections.

Required Methods§

Source

fn on_message<'life0, 'life1, 'async_trait>( &'life0 self, connection_id: &'life1 str, message: Message, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a message is received from a client.

§Arguments
  • connection_id - The unique identifier for the connection
  • message - The received message

Provided Methods§

Source

fn on_connect<'life0, 'life1, 'async_trait>( &'life0 self, connection_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a new client connects.

§Arguments
  • connection_id - The unique identifier for the connection
Source

fn on_disconnect<'life0, 'life1, 'async_trait>( &'life0 self, connection_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a client disconnects.

§Arguments
  • connection_id - The unique identifier for the connection
Source

fn on_error<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, connection_id: &'life1 str, error: &'life2 WebSocketError, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when an error occurs on a connection.

§Arguments
  • connection_id - The unique identifier for the connection
  • error - The error that occurred
Source

fn on_ping<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, connection_id: &'life1 str, payload: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Vec<u8>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when a ping is received. Return the pong payload.

§Arguments
  • connection_id - The unique identifier for the connection
  • payload - The ping payload
§Returns

The payload to send in the pong response

Source

fn on_pong<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, connection_id: &'life1 str, payload: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when a pong is received.

§Arguments
  • connection_id - The unique identifier for the connection
  • payload - The pong payload

Implementors§