hyperlane_plugin_websocket/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(Debug, Clone, 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`.
24#[derive(Clone)]
25pub struct WebSocketConfig<B: BroadcastTypeTrait> {
26 /// The Hyperlane context.
27 ///
28 /// This context is associated with this WebSocket connection.
29 pub(super) context: Context,
30 /// The request config.
31 ///
32 /// This configuration is used for managing WebSocket request processing,
33 /// including connection upgrade handling and request lifecycle management.
34 pub(super) request_config: RequestConfig,
35 /// The capacity.
36 ///
37 /// This is the capacity of the broadcast sender channel.
38 pub(super) capacity: Capacity,
39 /// The broadcast type.
40 ///
41 /// This defines the type of broadcast this WebSocket connection will participate in
42 /// (point-to-point or point-to-group).
43 pub(super) broadcast_type: BroadcastType<B>,
44 /// The connected hook handler.
45 ///
46 /// This hook is executed when the WebSocket connection is established.
47 pub(super) connected_hook: ServerHookHandler,
48 /// The request hook handler.
49 ///
50 /// This hook is executed when a new request is received on the WebSocket.
51 pub(super) request_hook: ServerHookHandler,
52 /// The sended hook handler.
53 ///
54 /// This hook is executed after a message has been successfully sent over the WebSocket.
55 pub(super) sended_hook: ServerHookHandler,
56 /// The closed hook handler.
57 ///
58 /// This hook is executed when the WebSocket connection is closed.
59 pub(super) closed_hook: ServerHookHandler,
60}