pub trait WebSocketMiddleware<S: AppState>:
Send
+ Sync
+ 'static {
// Provided methods
fn on_send<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 Message,
context: &'life2 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn on_receive<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 Message,
context: &'life2 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn on_connect<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_disconnect<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_connection_attempt<'life0, 'life1, 'async_trait>(
&'life0 self,
_context: &'life1 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_connection_failure<'life0, 'life1, 'async_trait>(
&'life0 self,
_context: &'life1 MiddlewareContext<S>,
_reason: Option<String>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
Trait for implementing WebSocket middleware.
Middleware can observe and react to WebSocket messages being sent and received. This trait provides hooks for both outgoing and incoming messages.
§Type Parameters
S: The application state type that implementsAppState
§Methods
- [
on_send]: Called before a message is sent to the WebSocket - [
on_receive]: Called after a message is received from the WebSocket - [
on_connect]: Called when a WebSocket connection is established - [
on_disconnect]: Called when a WebSocket connection is lost
§Error Handling
Middleware should be designed to be resilient. If middleware returns an error, it will be logged but will not prevent the message from being processed or other middleware from running.
Provided Methods§
Sourcefn on_send<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 Message,
context: &'life2 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_send<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 Message,
context: &'life2 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn on_receive<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 Message,
context: &'life2 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_receive<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 Message,
context: &'life2 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn on_connect<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_connect<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn on_disconnect<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_disconnect<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn on_connection_attempt<'life0, 'life1, 'async_trait>(
&'life0 self,
_context: &'life1 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_connection_attempt<'life0, 'life1, 'async_trait>(
&'life0 self,
_context: &'life1 MiddlewareContext<S>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a connection attempt is made (before actual connection)
Sourcefn on_connection_failure<'life0, 'life1, 'async_trait>(
&'life0 self,
_context: &'life1 MiddlewareContext<S>,
_reason: Option<String>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_connection_failure<'life0, 'life1, 'async_trait>(
&'life0 self,
_context: &'life1 MiddlewareContext<S>,
_reason: Option<String>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a connection attempt fails