Trait WebsocketHandler

Source
pub trait WebsocketHandler:
    Send
    + Sync
    + 'static {
    // Required methods
    fn on_open<'life0, 'async_trait>(
        &'life0 self,
        url: String,
        connection: Arc<WebsocketConnection>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn on_message<'life0, 'async_trait>(
        &'life0 self,
        data: String,
        connection: Arc<WebsocketConnection>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_reconnect_url<'life0, 'async_trait>(
        &'life0 self,
        default_url: String,
        connection: Arc<WebsocketConnection>,
    ) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A trait defining the lifecycle and behavior of a WebSocket connection.

This trait provides methods for handling WebSocket connection events, including connection opening, message handling, and reconnection URL retrieval.

§Methods

  • on_open: Called when a WebSocket connection is established
  • on_message: Called when a message is received over the WebSocket
  • get_reconnect_url: Determines the URL to use for reconnecting

§Thread Safety

Implementors must be safely shareable across threads, as indicated by the Send + Sync + 'static bounds.

Required Methods§

Source

fn on_open<'life0, 'async_trait>( &'life0 self, url: String, connection: Arc<WebsocketConnection>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_message<'life0, 'async_trait>( &'life0 self, data: String, connection: Arc<WebsocketConnection>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn get_reconnect_url<'life0, 'async_trait>( &'life0 self, default_url: String, connection: Arc<WebsocketConnection>, ) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§