pub trait WebSocketHandler: Send + 'static {
    // Required method
    fn handle_message(
        &mut self,
        message: WebSocketMessage
    ) -> Vec<WebSocketMessage>;

    // Provided methods
    fn websocket_config(&self) -> WebSocketConfig { ... }
    fn handle_start(&mut self) -> Vec<WebSocketMessage> { ... }
    fn handle_close(&mut self, reconnect: bool) { ... }
}
Expand description

A trait which is used to handle events on the WebSocketConnection.

The struct implementing this trait is required to be Send and 'static because it will be sent between threads.

Required Methods§

source

fn handle_message(&mut self, message: WebSocketMessage) -> Vec<WebSocketMessage>

Called when the WebSocketConnection received a message, returns messages to be sent to the server.

Provided Methods§

source

fn websocket_config(&self) -> WebSocketConfig

Returns a WebSocketConfig that will be applied for all WebSocket connections handled by this handler.

source

fn handle_start(&mut self) -> Vec<WebSocketMessage>

Called when a new connection has been started, and returns messages that should be sent to the server.

This could be called multiple times because the connection can be reconnected.

source

fn handle_close(&mut self, reconnect: bool)

Called when a websocket connection is closed.

If the parameter reconnect is:

  • true, it means that the connection is being reconnected for some reason.
  • false, it means that the connection will not be reconnected, because the WebSocketConnection was dropped.

Implementors§