mirror of
https://github.com/penpot/penpot.git
synced 2025-06-15 13:01:39 +02:00
🎉 Add more reliable presence mechanism.
This commit is contained in:
parent
4b31a147a9
commit
817c22dc3c
8 changed files with 105 additions and 49 deletions
|
@ -28,6 +28,7 @@
|
|||
(declare handle-pointer-update)
|
||||
(declare handle-page-change)
|
||||
(declare handle-pointer-send)
|
||||
(declare send-keepalive)
|
||||
|
||||
(s/def ::type keyword?)
|
||||
(s/def ::message
|
||||
|
@ -46,8 +47,11 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [wsession (get-in state [:ws file-id])
|
||||
stoper (rx/filter #(= ::finalize %) stream)]
|
||||
stoper (rx/filter #(= ::finalize %) stream)
|
||||
interval (* 1000 60)]
|
||||
(->> (rx/merge
|
||||
(->> (rx/timer interval interval)
|
||||
(rx/map #(send-keepalive file-id)))
|
||||
(->> (ws/-stream wsession)
|
||||
(rx/filter #(= :message (:type %)))
|
||||
(rx/map (comp t/decode :payload))
|
||||
|
@ -66,6 +70,15 @@
|
|||
|
||||
(rx/take-until stoper))))))
|
||||
|
||||
(defn send-keepalive
|
||||
[file-id]
|
||||
(ptk/reify ::send-keepalive
|
||||
ptk/EffectEvent
|
||||
(effect [_ state stream]
|
||||
(prn "send-keepalive" file-id)
|
||||
(when-let [ws (get-in state [:ws file-id])]
|
||||
(ws/-send ws (t/encode {:type :keepalive}))))))
|
||||
|
||||
;; --- Finalize Websocket
|
||||
|
||||
(defn finalize
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue