pub trait WebSocketHandlerwhere
    Arc<Self>: Sync,{
    type Context: Send + Sync;

    // Required methods
    fn handshake<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        self: &'life0 Arc<Self>,
        peer: &'life1 SocketAddr,
        sender: &'life2 mut WebSocketSender,
        receiver: &'life3 mut WebSocketReceiver,
        sink: &'life4 WebSocketSink
    ) -> Pin<Box<dyn Future<Output = Result<Self::Context>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait;
    fn message<'life0, 'life1, 'life2, 'async_trait>(
        self: &'life0 Arc<Self>,
        ctx: &'life1 Self::Context,
        msg: Message,
        sink: &'life2 WebSocketSink
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn connect<'life0, 'life1, 'async_trait>(
        self: &'life0 Arc<Self>,
        _peer: &'life1 SocketAddr
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn disconnect<'life0, 'async_trait>(
        self: &'life0 Arc<Self>,
        _ctx: Self::Context,
        _result: Result<()>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
    fn ctl<'life0, 'life1, 'async_trait>(
        self: &'life0 Arc<Self>,
        _msg: Message,
        _sender: &'life1 mut WebSocketSender
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

WebSocketHandler trait that represents the WebSocket processor functionality. This trait is supplied to the WebSocket which subsequently invokes it’s functions during websocket connection and messages. The trait can override with_handshake() method to enable invocation of the handshake() method upon receipt of the first valid websocket message from the incoming connection.

Required Associated Types§

source

type Context: Send + Sync

Context type used by impl trait to represent websocket connection

Required Methods§

source

fn handshake<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( self: &'life0 Arc<Self>, peer: &'life1 SocketAddr, sender: &'life2 mut WebSocketSender, receiver: &'life3 mut WebSocketReceiver, sink: &'life4 WebSocketSink ) -> Pin<Box<dyn Future<Output = Result<Self::Context>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Called after Self::connect(), after creating the tokio::sync::mpsc sender sink channel, allowing the server to execute additional handshake communication phase, or retain the sink for external message dispatch (such as server-side notifications).

source

fn message<'life0, 'life1, 'life2, 'async_trait>( self: &'life0 Arc<Self>, ctx: &'life1 Self::Context, msg: Message, sink: &'life2 WebSocketSink ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called for every websocket message This function can return an error to terminate the connection

Provided Methods§

source

fn connect<'life0, 'life1, 'async_trait>( self: &'life0 Arc<Self>, _peer: &'life1 SocketAddr ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called immediately when connection is established. This function should return an error to terminate the connection. If the server manages a client ban list, it should process it in this function and return an Error to prevent further processing.

source

fn disconnect<'life0, 'async_trait>( self: &'life0 Arc<Self>, _ctx: Self::Context, _result: Result<()> ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait,

Called upon websocket disconnection

source

fn ctl<'life0, 'life1, 'async_trait>( self: &'life0 Arc<Self>, _msg: Message, _sender: &'life1 mut WebSocketSender ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§