mirror of
https://github.com/penpot/penpot.git
synced 2025-05-12 23:16:37 +02:00
🐛 Disable broadcast-channel when it is not available (mainly safari)
This commit is contained in:
parent
953607fc4a
commit
5a06749664
1 changed files with 17 additions and 12 deletions
|
@ -19,24 +19,29 @@
|
||||||
|
|
||||||
;; The main broadcast channel instance, used for emit data
|
;; The main broadcast channel instance, used for emit data
|
||||||
(defonce default-channel
|
(defonce default-channel
|
||||||
(js/BroadcastChannel. default-topic))
|
(when (exists? js/BroadcastChannel)
|
||||||
|
(js/BroadcastChannel. default-topic)))
|
||||||
|
|
||||||
(defonce stream
|
(defonce stream
|
||||||
(->> (rx/create (fn [subs]
|
(if (exists? js/BroadcastChannel)
|
||||||
(let [chan (js/BroadcastChannel. default-topic)]
|
(->> (rx/create (fn [subs]
|
||||||
(unchecked-set chan "onmessage" #(rx/push! subs (unchecked-get % "data")))
|
(let [chan (js/BroadcastChannel. default-topic)]
|
||||||
(fn [] (.close ^js chan)))))
|
(unchecked-set chan "onmessage" #(rx/push! subs (unchecked-get % "data")))
|
||||||
(rx/map t/decode-str)
|
(fn [] (.close ^js chan)))))
|
||||||
(rx/map map->BroadcastMessage)
|
(rx/map t/decode-str)
|
||||||
(rx/share)))
|
(rx/map map->BroadcastMessage)
|
||||||
|
(rx/share))
|
||||||
|
(rx/subject)))
|
||||||
|
|
||||||
(defn emit!
|
(defn emit!
|
||||||
([type data]
|
([type data]
|
||||||
(.postMessage ^js default-channel (t/encode-str {:id nil :type type :data data}))
|
(when default-channel
|
||||||
nil)
|
(.postMessage ^js default-channel (t/encode-str {:id nil :type type :data data}))
|
||||||
|
nil))
|
||||||
([id type data]
|
([id type data]
|
||||||
(.postMessage ^js default-channel (t/encode-str {:id id :type type :data data}))
|
(when default-channel
|
||||||
nil))
|
(.postMessage ^js default-channel (t/encode-str {:id id :type type :data data}))
|
||||||
|
nil)))
|
||||||
|
|
||||||
(defn type?
|
(defn type?
|
||||||
([type]
|
([type]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue