sword_layers/socketio/
config.rs1use crate::{DisplayConfig, utils::*};
2use console::style;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6#[serde(default)]
7pub struct SocketIoServerConfig {
8 pub enabled: bool,
11
12 pub ack_timeout: Option<TimeConfig>,
17
18 pub connect_timeout: Option<TimeConfig>,
23
24 pub max_buffer_size: Option<usize>,
30
31 pub max_payload: Option<ByteConfig>,
36
37 pub ping_interval: Option<TimeConfig>,
40
41 pub ping_timeout: Option<TimeConfig>,
46
47 pub req_path: Option<String>,
50
51 pub transports: Option<Vec<String>>,
54
55 pub parser: Option<String>,
58
59 pub ws_read_buffer_size: Option<usize>,
67
68 pub display: bool,
70}
71
72impl DisplayConfig for SocketIoServerConfig {
73 fn display(&self) {
74 if !self.enabled {
75 return;
76 }
77
78 println!("\n{}", style("Socket.IO Server Configuration:").bold());
79 println!(" ↳ Enabled: {}", self.enabled);
80
81 let mut timeout_parts = Vec::new();
82
83 if let Some(ack) = &self.ack_timeout {
84 timeout_parts.push(format!("ack: {}", ack.raw));
85 }
86 if let Some(connect) = &self.connect_timeout {
87 timeout_parts.push(format!("connect: {}", connect.raw));
88 }
89 if let Some(ping) = &self.ping_timeout {
90 timeout_parts.push(format!("ping: {}", ping.raw));
91 }
92 if !timeout_parts.is_empty() {
93 println!(" ↳ Timeouts: {}", timeout_parts.join(" - "));
94 }
95
96 let mut limit_parts = Vec::new();
97
98 if let Some(buffer) = &self.max_buffer_size {
99 limit_parts.push(format!("buffer: {} packets", buffer));
100 }
101 if let Some(payload) = &self.max_payload {
102 limit_parts.push(format!("payload: {}", payload.raw));
103 }
104 if !limit_parts.is_empty() {
105 println!(" ↳ Limits: {}", limit_parts.join(" - "));
106 }
107
108 let mut connection_parts = Vec::new();
109
110 if let Some(interval) = &self.ping_interval {
111 connection_parts.push(format!("ping interval: {}", interval.raw));
112 }
113 if let Some(path) = &self.req_path {
114 connection_parts.push(format!("path: {}", path));
115 }
116 if let Some(transports) = &self.transports {
117 connection_parts.push(format!("transports: {}", transports.join(", ")));
118 }
119 if let Some(parser) = &self.parser {
120 connection_parts.push(format!("parser: {}", parser));
121 }
122 if !connection_parts.is_empty() {
123 println!(" ↳ Connection: {}", connection_parts.join(" - "));
124 }
125
126 if let Some(ws_size) = &self.ws_read_buffer_size {
127 println!(" ↳ WebSocket: read buffer {} bytes", ws_size);
128 }
129 }
130}