damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit c6a226fff8af479c8d168c7a753ed8df33a0f3f2
parent e023d1e9cb22136b4bae6de266f03d8d7ce4b4e5
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 23 Jun 2023 09:53:13 +0200

Revert "ping: switch to async style"

This was causing crashes =/

Diffstat:
Mdamus/Nostr/RelayConnection.swift | 13+++++--------
Mdamus/Nostr/WebSocket.swift | 12++----------
2 files changed, 7 insertions(+), 18 deletions(-)

diff --git 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 @@ -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() {