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)]
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 various hook functions 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 buffer size.
31 ///
32 /// This is the size of the buffer used for reading from the WebSocket stream.
33 pub(super) buffer_size: usize,
34 /// The capacity.
35 ///
36 /// This is the capacity of the broadcast sender channel.
37 pub(super) capacity: Capacity,
38 /// The broadcast type.
39 ///
40 /// This defines the type of broadcast this WebSocket connection will participate in
41 /// (point-to-point or point-to-group).
42 pub(super) broadcast_type: BroadcastType<B>,
43 /// The request hook function.
44 ///
45 /// This hook is executed when a new request is received on the WebSocket.
46 pub(super) request_hook: ArcFnContextPinBoxSendSync<()>,
47 /// The sended hook function.
48 ///
49 /// This hook is executed after a message has been successfully sent over the WebSocket.
50 pub(super) sended_hook: ArcFnContextPinBoxSendSync<()>,
51 /// The closed hook function.
52 ///
53 /// This hook is executed when the WebSocket connection is closed.
54 pub(super) closed_hook: ArcFnContextPinBoxSendSync<()>,
55}