Skip to main content

hyperlane_plugin_websocket/
struct.rs

1use crate::*;
2
3/// Represents a WebSocket instance.
4///
5/// This struct manages broadcast capabilities and holds the internal broadcast map
6/// responsible for handling message distribution to various WebSocket connections.
7#[derive(Clone, Debug, Default)]
8pub struct WebSocket {
9    /// The internal broadcast map.
10    ///
11    /// This map is used for managing WebSocket message distribution.
12    pub(super) broadcast_map: BroadcastMap<Vec<u8>>,
13}
14
15/// Configuration for a WebSocket connection.
16///
17/// This struct encapsulates all necessary parameters for setting up and managing
18/// a WebSocket connection, including context, buffer sizes, capacity, broadcast type,
19/// and hook handlers for different lifecycle events.
20///
21/// # Type Parameters
22///
23/// - `B`: The type used for broadcast keys, which must implement `BroadcastTypeTrait`.
24pub struct WebSocketConfig<'a, B: BroadcastTypeTrait> {
25    /// The underlying stream for this WebSocket connection.
26    pub(super) stream: &'a mut Stream,
27    /// The Hyperlane context.
28    ///
29    /// This context is associated with this WebSocket connection.
30    pub(super) context: &'a mut Context,
31    /// The capacity.
32    ///
33    /// This is the capacity of the broadcast sender channel.
34    pub(super) capacity: Capacity,
35    /// The broadcast type.
36    ///
37    /// This defines the type of broadcast this WebSocket connection will participate in
38    /// (point-to-point or point-to-group).
39    pub(super) broadcast_type: BroadcastType<B>,
40    /// The connected hook handler.
41    ///
42    /// This hook is executed when the WebSocket connection is established.
43    pub(super) connected_hook: ServerHookHandler,
44    /// The request hook handler.
45    ///
46    /// This hook is executed when a new request is received on the WebSocket.
47    pub(super) request_hook: ServerHookHandler,
48    /// The sended hook handler.
49    ///
50    /// This hook is executed after a message has been successfully sent over the WebSocket.
51    pub(super) sended_hook: ServerHookHandler,
52    /// The closed hook handler.
53    ///
54    /// This hook is executed when the WebSocket connection is closed.
55    pub(super) closed_hook: ServerHookHandler,
56}