use std::time::Duration;
#[derive(Clone, Debug)]
pub struct StreamClientConfig {
endpoint: String,
heartbeat_interval: Duration,
disconnect_timeout: Duration,
reconnect_initial_backoff: Duration,
reconnect_max_backoff: Duration,
reconnect_max_attempts: Option<usize>,
}
impl StreamClientConfig {
pub fn new(heartbeat_interval: Duration, disconnect_timeout: Duration) -> Self {
Self {
heartbeat_interval,
disconnect_timeout,
..Default::default()
}
}
pub fn endpoint(&self) -> &str {
&self.endpoint
}
pub fn heartbeat_interval(&self) -> Duration {
self.heartbeat_interval
}
pub fn disconnect_timeout(&self) -> Duration {
self.disconnect_timeout
}
pub fn reconnect_initial_backoff(&self) -> Duration {
self.reconnect_initial_backoff
}
pub fn reconnect_max_backoff(&self) -> Duration {
self.reconnect_max_backoff
}
pub fn reconnect_max_attempts(&self) -> Option<usize> {
self.reconnect_max_attempts
}
pub fn with_endpoint(mut self, endpoint: impl ToString) -> Self {
self.endpoint = endpoint.to_string();
self
}
pub fn with_heartbeat_interval(mut self, heartbeat_interval: Duration) -> Self {
self.heartbeat_interval = heartbeat_interval;
self
}
pub fn with_disconnect_timeout(mut self, disconnect_timeout: Duration) -> Self {
self.disconnect_timeout = disconnect_timeout;
self
}
pub fn with_reconnect_initial_backoff(mut self, reconnect_initial_backoff: Duration) -> Self {
self.reconnect_initial_backoff = reconnect_initial_backoff;
self
}
pub fn with_reconnect_max_backoff(mut self, reconnect_max_backoff: Duration) -> Self {
self.reconnect_max_backoff = reconnect_max_backoff;
self
}
pub fn with_reconnect_max_attempts(mut self, reconnect_max_attempts: Option<usize>) -> Self {
self.reconnect_max_attempts = reconnect_max_attempts;
self
}
}
impl Default for StreamClientConfig {
fn default() -> Self {
Self {
endpoint: "wss://stream.lnmarkets.com/v1".to_string(),
heartbeat_interval: Duration::from_secs(30),
disconnect_timeout: Duration::from_secs(6),
reconnect_initial_backoff: Duration::from_secs(1),
reconnect_max_backoff: Duration::from_secs(30),
reconnect_max_attempts: None,
}
}
}