Skip to main content

hyperlane_plugin_websocket/
struct.rs

1use super::*;
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, Data, Debug, Default)]
8pub struct WebSocket {
9    /// The internal broadcast map.
10    ///
11    /// This map is used for managing WebSocket message distribution.
12    pub 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`.
24#[derive(Data)]
25pub struct WebSocketConfig<'a, B: BroadcastTypeTrait> {
26    /// The underlying stream for this WebSocket connection.
27    #[set(skip)]
28    pub stream: &'a mut Stream,
29    /// The Hyperlane context.
30    ///
31    /// This context is associated with this WebSocket connection.
32    #[set(skip)]
33    pub context: &'a mut Context,
34    /// The capacity.
35    ///
36    /// This is the capacity of the broadcast sender channel.
37    #[get(type(copy))]
38    #[set(skip)]
39    pub capacity: Capacity,
40    /// The broadcast type.
41    ///
42    /// This defines the type of broadcast this WebSocket connection will participate in
43    /// (point-to-point or point-to-group).
44    #[set(skip)]
45    pub broadcast_type: BroadcastType<B>,
46    /// The connected hook handler.
47    ///
48    /// This hook is executed when the WebSocket connection is established.
49    #[set(skip)]
50    pub connected_hook: ServerHookHandler,
51    /// The request hook handler.
52    ///
53    /// This hook is executed when a new request is received on the WebSocket.
54    #[set(skip)]
55    pub request_hook: ServerHookHandler,
56    /// The sended hook handler.
57    ///
58    /// This hook is executed after a message has been successfully sent over the WebSocket.
59    #[set(skip)]
60    pub sended_hook: ServerHookHandler,
61    /// The closed hook handler.
62    ///
63    /// This hook is executed when the WebSocket connection is closed.
64    #[set(skip)]
65    pub closed_hook: ServerHookHandler,
66}