mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 17:56:11 +02:00
♻️ Make the namespacing independent of the branding.
This commit is contained in:
parent
aaf8b71837
commit
6c67c3c71b
305 changed files with 2399 additions and 2580 deletions
65
frontend/src/app/util/websockets.cljs
Normal file
65
frontend/src/app/util/websockets.cljs
Normal file
|
@ -0,0 +1,65 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs SL
|
||||
|
||||
(ns app.util.websockets
|
||||
"A interface to webworkers exposed functionality."
|
||||
(:require
|
||||
[goog.events :as ev]
|
||||
[app.config :as cfg]
|
||||
[beicon.core :as rx]
|
||||
[potok.core :as ptk])
|
||||
(:import
|
||||
goog.Uri
|
||||
goog.net.WebSocket
|
||||
goog.net.WebSocket.EventType))
|
||||
|
||||
(defprotocol IWebSocket
|
||||
(-stream [_] "Retrienve the message stream")
|
||||
(-send [_ message] "send a message")
|
||||
(-close [_] "close websocket"))
|
||||
|
||||
(defn uri
|
||||
([path] (uri path {}))
|
||||
([path params]
|
||||
(let [uri (.parse ^js Uri cfg/public-uri)]
|
||||
(.setPath ^js uri path)
|
||||
(if (= (.getScheme ^js uri) "http")
|
||||
(.setScheme ^js uri "ws")
|
||||
(.setScheme ^js uri "wss"))
|
||||
(run! (fn [[k v]]
|
||||
(.setParameterValue ^js uri (name k) (str v)))
|
||||
params)
|
||||
(.toString uri))))
|
||||
|
||||
(defn open
|
||||
[uri]
|
||||
(let [sb (rx/subject)
|
||||
ws (WebSocket. #js {:autoReconnect true})
|
||||
lk1 (ev/listen ws EventType.MESSAGE
|
||||
#(rx/push! sb {:type :message :payload (.-message %)}))
|
||||
lk2 (ev/listen ws EventType.ERROR
|
||||
#(rx/push! sb {:type :error :payload %}))
|
||||
lk3 (ev/listen ws EventType.OPENED
|
||||
#(rx/push! sb {:type :opened :payload %}))]
|
||||
(.open ws uri)
|
||||
(reify
|
||||
cljs.core/IDeref
|
||||
(-deref [_] ws)
|
||||
|
||||
IWebSocket
|
||||
(-stream [_] sb)
|
||||
(-send [_ msg]
|
||||
(when (.isOpen ^js ws)
|
||||
(.send ^js ws msg)))
|
||||
(-close [_]
|
||||
(.close ws)
|
||||
(rx/end! sb)
|
||||
(ev/unlistenByKey lk1)
|
||||
(ev/unlistenByKey lk2)
|
||||
(ev/unlistenByKey lk3)))))
|
Loading…
Add table
Add a link
Reference in a new issue