Browse Source

fix(rtc): don't start-rtc when current state isn't :closed

rcmerci 1 year ago
parent
commit
e489a78479
1 changed files with 11 additions and 8 deletions
  1. 11 8
      src/main/frontend/worker/rtc/core.cljs

+ 11 - 8
src/main/frontend/worker/rtc/core.cljs

@@ -1129,14 +1129,17 @@
   [repo conn token dev-mode?]
   (go
     (if-let [graph-uuid (ldb/get-graph-rtc-uuid @conn)]
-      (let [state (<! (<init-state repo token true {:dev-mode? dev-mode?}))
-            state-for-asset-sync (asset-sync/init-state-from-rtc-state state)
-            _ (reset! asset-sync/*asset-sync-state state-for-asset-sync)
-            config (worker-state/get-config repo)
-            c1 (<loop-for-rtc state graph-uuid repo conn (common-config/get-date-formatter config))
-            c2 (asset-sync/<loop-for-assets-sync state-for-asset-sync graph-uuid repo conn)]
-        (<! c1)
-        (<! c2))
+      (do (assert (and (#{:closed nil} (some-> @*state :*ws deref ws/get-state))
+                       (#{:closed nil} (some-> @*state :*rtc-state deref)))
+                  "*state should be :closed")
+          (let [state (<! (<init-state repo token true {:dev-mode? dev-mode?}))
+                state-for-asset-sync (asset-sync/init-state-from-rtc-state state)
+                _ (reset! asset-sync/*asset-sync-state state-for-asset-sync)
+                config (worker-state/get-config repo)
+                c1 (<loop-for-rtc state graph-uuid repo conn (common-config/get-date-formatter config))
+                c2 (asset-sync/<loop-for-assets-sync state-for-asset-sync graph-uuid repo conn)]
+            (<! c1)
+            (<! c2)))
       (worker-util/post-message :notification
                                 [[:div
                                   [:p "RTC is not supported for this graph"]]