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§
sourcefn handle_message(&mut self, message: WebSocketMessage) -> Vec<WebSocketMessage>
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§
sourcefn websocket_config(&self) -> WebSocketConfig
fn websocket_config(&self) -> WebSocketConfig
Returns a prefix that will be appended to the URL of all the websocket connections being started using this handler.
sourcefn handle_start(&mut self) -> Vec<WebSocketMessage>
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.
sourcefn handle_close(&mut self, reconnect: bool)
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.