pub struct WebSocketConfig {
pub url: String,
pub authorization: Option<String>,
pub auto_reconnect: bool,
pub reconnect_interval: Duration,
pub ping_interval: Duration,
pub ping_timeout: Duration,
pub max_reconnect_attempts: Option<u32>,
pub filtered_events: Option<Vec<String>>,
}Expand description
WebSocket-specific configuration.
Fields§
§url: StringWebsocket event channel URL. eg: ws://192.168.1.2:3000/ws
Optional Websocket authorization header token.
auto_reconnect: boolShould the websocket connection automatically reconnect if disconnected.
reconnect_interval: DurationInterval to use between reconnection attempts.
ping_interval: DurationThe interval between sending websocket pings.
ping_timeout: DurationTimeout duration for missing pings.
max_reconnect_attempts: Option<u32>Maximum reconnection attempts (None = unlimited).
filtered_events: Option<Vec<String>>Optional set of events that should be listened to. This is added to the websocket connection URI, and the server filters out events before sending them. By default, all events are sent when none are selected.
Implementations§
Source§impl WebSocketConfig
impl WebSocketConfig
Sourcepub const WS_DEFAULT_RECONNECT_INTERVAL: u64 = 5u64
pub const WS_DEFAULT_RECONNECT_INTERVAL: u64 = 5u64
The default interval to use between connection attempts. Sequential attempts use a backoff up to 60 seconds.
Sourcepub const WS_DEFAULT_PING_INTERVAL: u64 = 10u64
pub const WS_DEFAULT_PING_INTERVAL: u64 = 10u64
The interval between sending ping messages.
Sourcepub const WS_DEFAULT_PING_TIMEOUT: u64 = 30u64
pub const WS_DEFAULT_PING_TIMEOUT: u64 = 30u64
The duration between the last ping to count as a timeout.
Sourcepub fn new(url: impl Into<String>) -> Self
pub fn new(url: impl Into<String>) -> Self
Create a new WebSocket configuration with default settings.
Sourcepub fn with_auto_reconnect(self, enabled: bool) -> Self
pub fn with_auto_reconnect(self, enabled: bool) -> Self
Enable or disable auto-reconnection.
Sourcepub fn with_reconnect_interval(self, interval: Duration) -> Self
pub fn with_reconnect_interval(self, interval: Duration) -> Self
Set the reconnection interval.
Sourcepub fn with_ping_interval(self, interval: Duration) -> Self
pub fn with_ping_interval(self, interval: Duration) -> Self
Set the ping interval.
Sourcepub fn with_ping_timeout(self, timeout: Duration) -> Self
pub fn with_ping_timeout(self, timeout: Duration) -> Self
Set the ping timeout.
Sourcepub fn with_max_reconnect_attempts(self, max_attempts: Option<u32>) -> Self
pub fn with_max_reconnect_attempts(self, max_attempts: Option<u32>) -> Self
Set maximum reconnection attempts (None = unlimited).
Sourcepub fn with_filtered_events(
self,
events: Option<Vec<impl Into<String>>>,
) -> Self
pub fn with_filtered_events( self, events: Option<Vec<impl Into<String>>>, ) -> Self
Set filtered listen events, this is included in the connection query-string. The provided Vec should contain every event name that should be sent by the server. If None, filtering is disabled so all events are sent.
Trait Implementations§
Source§impl Clone for WebSocketConfig
impl Clone for WebSocketConfig
Source§fn clone(&self) -> WebSocketConfig
fn clone(&self) -> WebSocketConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WebSocketConfig
impl Debug for WebSocketConfig
Source§impl Default for WebSocketConfig
Available on crate feature websocket only.
impl Default for WebSocketConfig
websocket only.Source§impl From<WebSocketConfig> for ClientConfig
Available on crate feature websocket only.
impl From<WebSocketConfig> for ClientConfig
websocket only.