pub trait WebSocketHandler: Send + Sync {
// Required methods
fn paths(&self) -> Vec<&'static str>;
fn on_open<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn on_message<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn on_error<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
error: Box<dyn Error + Send + Sync>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn on_close<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
close: Option<CloseFrame>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}
Expand description
Required Methods§
Sourcefn on_open<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_open<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
When the socket connection enters, this method will be entered first
Sourcefn on_message<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_message<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
When the client sends a message, it will enter the following method
Sourcefn on_error<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
error: Box<dyn Error + Send + Sync>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_error<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
error: Box<dyn Error + Send + Sync>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
When an error occurs during the connection process or message transmission, the following methods will be executed
Sourcefn on_close<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
close: Option<CloseFrame>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_close<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 WebSocketSession,
close: Option<CloseFrame>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
After handling the error, close the connection and proceed to the following method