diff --git a/damus/Nostr/RelayConnection.swift b/damus/Nostr/RelayConnection.swift index b2b8312d..f09931ee 100644 --- a/damus/Nostr/RelayConnection.swift +++ b/damus/Nostr/RelayConnection.swift @@ -56,18 +56,15 @@ final class RelayConnection: ObservableObject { } func ping() { - Task { - do { - try await socket.ping() - } catch { - print("pong failed (\(error)), reconnecting \(self.url.id)") + socket.ping { err in + if err == nil { + self.last_pong = .now + } else { + print("pong failed, reconnecting \(self.url.id)") self.isConnected = false self.isConnecting = false self.reconnect_with_backoff() - return } - - self.last_pong = .now } } diff --git a/damus/Nostr/WebSocket.swift b/damus/Nostr/WebSocket.swift index bf58dc12..f25d5ffd 100644 --- a/damus/Nostr/WebSocket.swift +++ b/damus/Nostr/WebSocket.swift @@ -45,16 +45,8 @@ final class WebSocket: NSObject, URLSessionWebSocketDelegate { self.session = session } - func ping() async throws -> () { - return try await withCheckedThrowingContinuation { cont in - self.webSocketTask.sendPing { err in - if let err { - cont.resume(throwing: err) - } else { - cont.resume(returning: ()) - } - } - } + func ping(receiveHandler: @escaping (Error?) -> Void) { + self.webSocketTask.sendPing(pongReceiveHandler: receiveHandler) } func connect() {