diff --git a/damus/Nostr/RelayConnection.swift b/damus/Nostr/RelayConnection.swift index ab292fff..926e6415 100644 --- a/damus/Nostr/RelayConnection.swift +++ b/damus/Nostr/RelayConnection.swift @@ -49,6 +49,7 @@ final class RelayConnection: ObservableObject { private var handleEvent: (NostrConnectionEvent) -> () private let url: RelayURL + var log: RelayLog? init(url: RelayURL, handleEvent: @escaping (NostrConnectionEvent) -> ()) { self.url = url @@ -59,11 +60,13 @@ final class RelayConnection: ObservableObject { socket.ping { err in if err == nil { self.last_pong = .now + self.log?.add("Successful ping") } else { print("pong failed, reconnecting \(self.url.id)") self.isConnected = false self.isConnecting = false self.reconnect_with_backoff() + self.log?.add("Ping failed") } } } @@ -153,6 +156,10 @@ final class RelayConnection: ObservableObject { DispatchQueue.main.async { self.handleEvent(.ws_event(event)) } + + if let description = event.description { + log?.add(description) + } } func reconnect_with_backoff() { @@ -166,6 +173,7 @@ final class RelayConnection: ObservableObject { } disconnect() connect() + log?.add("Reconnecting...") } func reconnect_in(after: TimeInterval) { diff --git a/damus/Nostr/WebSocket.swift b/damus/Nostr/WebSocket.swift index f25d5ffd..15d6c705 100644 --- a/damus/Nostr/WebSocket.swift +++ b/damus/Nostr/WebSocket.swift @@ -19,7 +19,7 @@ enum WebSocketEvent { case .connected: return "Connected" case .message(_): - return "Received message" + return nil // adding this to the RelayLog was too noisy case .disconnected(let close_code, let reason): return "Disconnected: Close code: \(close_code), reason: \(reason ?? "unknown")" case .error(let error):