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 Hyperlane context.
26 ///
27 /// This context is associated with this WebSocket connection.
28 pub(super) context: &'a mut Context,
29 /// The capacity.
30 ///
31 /// This is the capacity of the broadcast sender channel.
32 pub(super) capacity: Capacity,
33 /// The broadcast type.
34 ///
35 /// This defines the type of broadcast this WebSocket connection will participate in
36 /// (point-to-point or point-to-group).
37 pub(super) broadcast_type: BroadcastType<B>,
38 /// The connected hook handler.
39 ///
40 /// This hook is executed when the WebSocket connection is established.
41 pub(super) connected_hook: ServerHookHandler,
42 /// The request hook handler.
43 ///
44 /// This hook is executed when a new request is received on the WebSocket.
45 pub(super) request_hook: ServerHookHandler,
46 /// The sended hook handler.
47 ///
48 /// This hook is executed after a message has been successfully sent over the WebSocket.
49 pub(super) sended_hook: ServerHookHandler,
50 /// The closed hook handler.
51 ///
52 /// This hook is executed when the WebSocket connection is closed.
53 pub(super) closed_hook: ServerHookHandler,
54}