From 9b99e0080477d4aea24da8fdee13b29885967bf6 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sun, 7 May 2023 12:00:37 -0700 Subject: [PATCH] Reconnect on failed ping and remove reconnect timer I think this does it --- damus/ContentView.swift | 6 ------ damus/Nostr/RelayConnection.swift | 7 ++++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index cf7c468c..4288956c 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -81,9 +81,6 @@ struct ContentView: View { @SceneStorage("ContentView.filter_state") var filter_state : FilterState = .posts_and_replies @State private var isSideBarOpened = false @StateObject var home: HomeModel = HomeModel() - - // connect retry timer - let timer = Timer.publish(every: 4, on: .main, in: .common).autoconnect() let sub_id = UUID().description @@ -393,9 +390,6 @@ struct ContentView: View { self.active_sheet = nil } } - .onReceive(timer) { n in - self.damus_state?.pool.connect_to_disconnected() - } .onReceive(handle_notify(.new_mutes)) { notif in home.filter_events() } diff --git a/damus/Nostr/RelayConnection.swift b/damus/Nostr/RelayConnection.swift index 58d34324..b4587257 100644 --- a/damus/Nostr/RelayConnection.swift +++ b/damus/Nostr/RelayConnection.swift @@ -57,8 +57,13 @@ final class RelayConnection { func ping() { socket.ping { err in - if err != nil { + 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() } } }