WebsocketHandler

Trait WebsocketHandler 

Source
pub trait WebsocketHandler
where Self: Sized,
{ type Message: Receivable; // Required methods fn accept( address: SocketAddr, request: &WebsocketRequest, response: WebsocketResponse, ) -> Result<(WebsocketResponse, Self), ExitReason>; fn websocket_handle( &mut self, message: WebsocketMessage, ) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send; // Provided methods fn websocket_init( &mut self, ) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send { ... } fn websocket_info( &mut self, info: Message<Self::Message>, ) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send { ... } fn terminate( &mut self, reason: ExitReason, ) -> impl Future<Output = ()> + Send { ... } }
Expand description

A process that handles websocket messages.

Required Associated Types§

Source

type Message: Receivable

The message type that this handler will use.

Required Methods§

Source

fn accept( address: SocketAddr, request: &WebsocketRequest, response: WebsocketResponse, ) -> Result<(WebsocketResponse, Self), ExitReason>

A callback used to accept or deny a request for a websocket upgrade.

You can extract information from the request and put it in your handler state.

Source

fn websocket_handle( &mut self, message: WebsocketMessage, ) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send

Invoked to handle messages received from the websocket.

Provided Methods§

Source

fn websocket_init( &mut self, ) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send

An optional callback that happens before the first message is sent/received from the websocket.

This is the first callback that happens in the process responsible for the websocket.

Source

fn websocket_info( &mut self, info: Message<Self::Message>, ) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send

Invoked to handle messages from processes and system messages.

Source

fn terminate(&mut self, reason: ExitReason) -> impl Future<Output = ()> + Send

Invoked when the handler is about to exit. It should do any cleanup required.

terminate is useful for cleanup that requires access to the WebsocketHandler’s state. However, it is not guaranteed that terminate is called when a WebsocketHandler exits. Therefore, important cleanup should be done using process links and/or monitors. A monitoring process will receive the same reason that would be passed to terminate.

terminate is called if:

  • The websocket connection closes for whatever reason.
  • A callback (except accept) returns stop with a given reason.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§