|
|
@@ -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)))
|
|
|
|