pub trait WebsocketHandler {
type Err: Display + Debug + Send + Sync;
// Required methods
fn open_ws(&self) -> WsConfig;
fn on_message(
&mut self,
msg: Vec<u8>,
) -> Result<Option<ActionOutput>, Self::Err>;
// Provided methods
fn on_open(&mut self) -> Result<Option<ActionOutput>, Self::Err> { ... }
fn on_error(&mut self) -> Result<Option<ActionOutput>, Self::Err> { ... }
fn on_close(&mut self) -> Result<Option<ActionOutput>, Self::Err> { ... }
fn send_ws_msg(&self, msg: Vec<u8>) -> Result<(), Error> { ... }
}Required Associated Types§
Required Methods§
Sourcefn open_ws(&self) -> WsConfig
fn open_ws(&self) -> WsConfig
Constructor function that is called before the connection is opened.
This function returns all required information to establish the websocket connection.
Sourcefn on_message(
&mut self,
msg: Vec<u8>,
) -> Result<Option<ActionOutput>, Self::Err>
fn on_message( &mut self, msg: Vec<u8>, ) -> Result<Option<ActionOutput>, Self::Err>
Called whenever a message is received from the client.
Provided Methods§
Sourcefn on_open(&mut self) -> Result<Option<ActionOutput>, Self::Err>
fn on_open(&mut self) -> Result<Option<ActionOutput>, Self::Err>
Called when a new connection is established (before any messages are exchanged).
Sourcefn on_error(&mut self) -> Result<Option<ActionOutput>, Self::Err>
fn on_error(&mut self) -> Result<Option<ActionOutput>, Self::Err>
Called when an error occurs on the connection.