1use std::time::Duration;
2
3pub const DEFAULT_PING_INTERVAL: Duration = Duration::from_secs(20);
4pub const DEFAULT_PONG_TIMEOUT: Duration = Duration::from_secs(10);
5
6#[derive(Debug, Clone)]
7pub struct Config {
8 pub url: String,
10
11 pub command_queue_size: usize,
13
14 pub event_queue_size: usize,
16
17 pub max_reconnect_attempts: u32,
19
20 pub reconnect_base_delay: Duration,
22
23 pub reconnect_max_delay: Duration,
25
26 pub close_timeout: Duration,
28
29 pub ping_interval: Option<Duration>,
32
33 pub pong_timeout: Duration,
37}
38
39impl Default for Config {
40 fn default() -> Self {
41 Self {
42 url: String::new(),
43 command_queue_size: 64,
44 event_queue_size: 256,
45 max_reconnect_attempts: 5,
46 reconnect_base_delay: Duration::from_millis(500),
47 reconnect_max_delay: Duration::from_secs(30),
48 close_timeout: Duration::from_secs(5),
49 ping_interval: Some(DEFAULT_PING_INTERVAL),
50 pong_timeout: DEFAULT_PONG_TIMEOUT,
51 }
52 }
53}
54
55impl Config {
56 pub fn new(url: impl Into<String>) -> Self {
57 Self {
58 url: url.into(),
59 ..Default::default()
60 }
61 }
62
63 pub fn command_queue_size(mut self, n: usize) -> Self {
64 self.command_queue_size = n;
65 self
66 }
67
68 pub fn event_queue_size(mut self, n: usize) -> Self {
69 self.event_queue_size = n;
70 self
71 }
72
73 pub fn max_reconnect_attempts(mut self, n: u32) -> Self {
74 self.max_reconnect_attempts = n;
75 self
76 }
77
78 pub fn reconnect_base_delay(mut self, d: Duration) -> Self {
79 self.reconnect_base_delay = d;
80 self
81 }
82
83 pub fn reconnect_max_delay(mut self, d: Duration) -> Self {
84 self.reconnect_max_delay = d;
85 self
86 }
87
88 pub fn close_timeout(mut self, d: Duration) -> Self {
89 self.close_timeout = d;
90 self
91 }
92
93 pub fn ping_interval(mut self, d: Option<Duration>) -> Self {
94 self.ping_interval = d;
95 self
96 }
97
98 pub fn pong_timeout(mut self, d: Duration) -> Self {
99 self.pong_timeout = d;
100 self
101 }
102}