Browse Source

enhance(rtc): try to restart rtc if stop reason is ws-timeout

rcmerci 5 months ago
parent
commit
dbb20dea4b

+ 5 - 0
src/main/frontend/handler/db_based/rtc_flows.cljs

@@ -1,6 +1,7 @@
 (ns frontend.handler.db-based.rtc-flows
   "Flows related to RTC"
   (:require [frontend.common.missionary :as c.m]
+            [frontend.common.thread-api :as thread-api :refer [def-thread-api]]
             [frontend.flows :as flows]
             [frontend.mobile.flows :as mobile-flows]
             [frontend.state :as state]
@@ -94,6 +95,10 @@ conditions:
   (assert (some? repo))
   (reset! *rtc-start-trigger repo))
 
+(def-thread-api :thread-api/rtc-start-request
+  [repo]
+  (trigger-rtc-start repo))
+
 (def ^:private document-visible&rtc-not-running-flow
   (m/ap
     (let [visibility (m/?< flows/document-visibility-state-flow)]

+ 1 - 1
src/main/frontend/log.cljs

@@ -10,4 +10,4 @@
 
 (if config/dev?
   (log/set-levels {:glogi/root :info})
-  (log/set-levels {:glogi/root :warn}))
+  (log/set-levels {:glogi/root :info}))

+ 2 - 0
src/main/frontend/worker/db_worker.cljs

@@ -33,6 +33,7 @@
             [frontend.worker.thread-atom]
             [frontend.worker.util :as worker-util]
             [goog.object :as gobj]
+            [lambdaisland.glogi :as log]
             [lambdaisland.glogi.console :as glogi-console]
             [logseq.common.util :as common-util]
             [logseq.db :as ldb]
@@ -841,6 +842,7 @@
                       (into {})
                       bean/->js)]
     (glogi-console/install!)
+    (log/set-levels {:glogi/root :info})
     (check-worker-scope!)
     (outliner-register-op-handlers!)
     (<ratelimit-file-writes!)

+ 5 - 1
src/main/frontend/worker/rtc/core.cljs

@@ -247,6 +247,7 @@
       started-dfv
       (m/sp
         (try
+          (log/info :rtc :loop-starting)
           ;; init run to open a ws
           (m/? get-ws-create-task)
           (started-dfv true)
@@ -368,7 +369,10 @@
                          rtc-loop-task
                          :fail (fn [e]
                                  (reset! *last-stop-exception e)
-                                 (log/info :rtc-loop-task e)))
+                                 (log/info :rtc-loop-task e)
+                                 (when (= :rtc.exception/ws-timeout (some-> e ex-data :type))
+                                   ;; if fail reason is websocket-timeout, try to restart rtc
+                                   (worker-state/<invoke-main-thread :thread-api/rtc-start-request repo))))
               start-ex (m/? onstarted-task)]
           (if (instance? ExceptionInfo start-ex)
             (do