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§
Sourcefn 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,
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 connectionmessage- The received message
Provided Methods§
Sourcefn 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_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
Sourcefn 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_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
Sourcefn 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_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 connectionerror- The error that occurred
Sourcefn 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_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,
Sourcefn 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,
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 connectionpayload- The pong payload