notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit e082e76640ecf9031066996e53f41d37938c79a1
parent b6ee66ee174d2d0a872c155f39bf3beeed828fa2
Author: kernelkind <kernelkind@gmail.com>
Date:   Sun,  1 Feb 2026 21:56:19 -0500

refactor(websocket): add comments & helper

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/enostr/src/relay/mod.rs | 2+-
Mcrates/enostr/src/relay/websocket.rs | 10++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/crates/enostr/src/relay/mod.rs b/crates/enostr/src/relay/mod.rs @@ -6,7 +6,7 @@ mod websocket; pub use websocket::{WebsocketConn, WebsocketRelay}; -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum RelayStatus { Connected, Connecting, diff --git a/crates/enostr/src/relay/websocket.rs b/crates/enostr/src/relay/websocket.rs @@ -9,6 +9,7 @@ use std::{ use ewebsock::{Options, WsMessage, WsReceiver, WsSender}; use tracing::{debug, error}; +/// WebsocketConn owns an outbound websocket connection to a relay. pub struct WebsocketConn { pub url: nostr::RelayUrl, pub status: RelayStatus, @@ -83,8 +84,13 @@ impl WebsocketConn { let msg = WsMessage::Ping(vec![]); self.sender.send(msg); } + + pub fn set_status(&mut self, status: RelayStatus) { + self.status = status; + } } +/// WebsocketRelay wraps WebsocketConn with reconnect/keepalive metadata. pub struct WebsocketRelay { pub conn: WebsocketConn, pub last_ping: Instant, @@ -105,4 +111,8 @@ impl WebsocketRelay { pub fn initial_reconnect_duration() -> Duration { Duration::from_secs(5) } + + pub fn is_connected(&self) -> bool { + self.conn.status == RelayStatus::Connected + } }