Browse Source

refactor: remove usages of navigator.onLine, window.ononline

rcmerci 4 months ago
parent
commit
b486bde595

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

@@ -21,7 +21,7 @@
 (def ^:private current-login-user-validator (ma/validator current-login-user-schema))
 (def *current-login-user (atom nil :validator current-login-user-validator))
 
-(def *network-online? (atom nil))
+(def *network-online? (atom true))
 
 ;; Public Flows
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

+ 0 - 1
src/main/frontend/handler.cljs

@@ -149,7 +149,6 @@
   (render)
   (i18n/start)
   (instrument/init)
-  (state/set-online! js/navigator.onLine)
 
   (-> (util/indexeddb-check?)
       (p/catch (fn [_e]

+ 8 - 19
src/main/frontend/handler/db_based/rtc_flows.cljs

@@ -47,39 +47,28 @@
     (dedupe)
     rtc-state-flow)))
 
-(def ^:private network-online-change-flow
-  (m/stream
-   (m/relieve
-    (m/observe
-     (fn ctor [emit!]
-       (let [origin-callback js/window.ononline]
-         (set! js/window.ononline emit!)
-         (emit! nil)
-         (fn dtor []
-           (set! js/window.ononline origin-callback))))))))
-
 (def rtc-try-restart-flow
   "emit an event when it's time to restart rtc loop.
 conditions:
 - user logged in
 - no rtc loop running now
 - last rtc stop-reason is websocket message timeout
-- current js/navigator.onLine=true
+- online
 - throttle 5000ms"
   (->> (m/latest
-        (fn [rtc-state _ login-user]
-          (assoc rtc-state :login-user login-user))
+        (fn [rtc-state online? login-user]
+          (assoc rtc-state :login-user login-user :online? online?))
         rtc-state-flow
-        (c.m/continue-flow network-online-change-flow)
+        flows/network-online-event-flow
         flows/current-login-user-flow)
        (m/eduction
         (keep (fn [m]
-                (let [{:keys [rtc-lock last-stop-exception-ex-data graph-uuid login-user]} m]
-                  (when (and (some? (:email login-user))
+                (let [{:keys [rtc-lock last-stop-exception-ex-data graph-uuid login-user online?]} m]
+                  (when (and online?
+                             (some? (:email login-user))
                              (some? graph-uuid)
                              (not rtc-lock) ; no rtc loop now
-                             (= :rtc.exception/ws-timeout (:type last-stop-exception-ex-data))
-                             (true? js/navigator.onLine))
+                             (= :rtc.exception/ws-timeout (:type last-stop-exception-ex-data)))
                     {:graph-uuid graph-uuid :t (common-util/time-ms)})))))
        (c.m/throttle 5000)))