Trait workflow_rpc::server::WebSocketHandler

source ·
pub trait WebSocketHandler
where 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 SplitSink<WebSocketStream<TcpStream>, Message>, receiver: &'life3 mut SplitStream<WebSocketStream<TcpStream>>, sink: &'life4 UnboundedSender<Message>, ) -> Pin<Box<dyn Future<Output = Result<Self::Context, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, Self: 'async_trait; fn message<'life0, 'life1, 'life2, 'async_trait>( self: &'life0 Arc<Self>, ctx: &'life1 Self::Context, msg: Message, sink: &'life2 UnboundedSender<Message>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait; // Provided methods fn accept(&self, _peer: &SocketAddr) -> bool { ... } fn connect<'life0, 'life1, 'async_trait>( self: &'life0 Arc<Self>, _peer: &'life1 SocketAddr, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + 'async_trait { ... } fn disconnect<'life0, 'async_trait>( self: &'life0 Arc<Self>, _ctx: Self::Context, _result: Result<(), Error>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, Self: Sync + 'async_trait { ... } fn ctl<'life0, 'life1, 'async_trait>( self: &'life0 Arc<Self>, msg: Message, sender: &'life1 mut SplitSink<WebSocketStream<TcpStream>, Message>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + '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 SplitSink<WebSocketStream<TcpStream>, Message>, receiver: &'life3 mut SplitStream<WebSocketStream<TcpStream>>, sink: &'life4 UnboundedSender<Message>, ) -> Pin<Box<dyn Future<Output = Result<Self::Context, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, Self: '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 UnboundedSender<Message>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

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

Provided Methods§

source

fn accept(&self, _peer: &SocketAddr) -> bool

Called to determine if the connection should be accepted.

source

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

Called upon websocket disconnection

source

fn ctl<'life0, 'life1, 'async_trait>( self: &'life0 Arc<Self>, msg: Message, sender: &'life1 mut SplitSink<WebSocketStream<TcpStream>, Message>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + 'async_trait,

Object Safety§

This trait is not object safe.

Implementors§