remove the core.async channel for sending client->server messages
This commit is contained in:
parent
83486ef11b
commit
88a212316a
|
@ -13,12 +13,18 @@
|
||||||
|
|
||||||
(defonce incoming-messages (chan))
|
(defonce incoming-messages (chan))
|
||||||
(defonce incoming-messages-pub (pub incoming-messages :topic))
|
(defonce incoming-messages-pub (pub incoming-messages :topic))
|
||||||
(defonce outgoing-messages (chan))
|
|
||||||
|
|
||||||
(defn send
|
(defn send
|
||||||
"sends a browserchannel message to the server asynchronously."
|
"sends a browserchannel message to the server asynchronously."
|
||||||
[topic body]
|
[topic body]
|
||||||
(put! outgoing-messages {:topic topic :body body}))
|
(let [msg {:topic topic
|
||||||
|
:body body}]
|
||||||
|
(run-middleware
|
||||||
|
(:on-send @handler-middleware)
|
||||||
|
(fn [msg]
|
||||||
|
(if-let [encoded (encode-message msg)]
|
||||||
|
(.sendMap browser-channel (clj->js encoded))))
|
||||||
|
msg)))
|
||||||
|
|
||||||
(defn message-handler
|
(defn message-handler
|
||||||
"listens for incoming browserchannel messages with the specified topic.
|
"listens for incoming browserchannel messages with the specified topic.
|
||||||
|
@ -33,17 +39,6 @@
|
||||||
(handler msg)
|
(handler msg)
|
||||||
(recur)))))
|
(recur)))))
|
||||||
|
|
||||||
(defn- handle-outgoing [channel]
|
|
||||||
(go-loop []
|
|
||||||
(when-let [msg (<! outgoing-messages)]
|
|
||||||
(run-middleware
|
|
||||||
(:on-send @handler-middleware)
|
|
||||||
(fn [msg]
|
|
||||||
(if-let [encoded (encode-message msg)]
|
|
||||||
(.sendMap channel (clj->js encoded))))
|
|
||||||
msg)
|
|
||||||
(recur))))
|
|
||||||
|
|
||||||
(defn- handle-incoming [channel msg]
|
(defn- handle-incoming [channel msg]
|
||||||
(when-let [decoded (decode-message (js->clj msg))]
|
(when-let [decoded (decode-message (js->clj msg))]
|
||||||
(run-middleware
|
(run-middleware
|
||||||
|
@ -75,8 +70,7 @@
|
||||||
(let [h (goog.net.BrowserChannel.Handler.)]
|
(let [h (goog.net.BrowserChannel.Handler.)]
|
||||||
(set! (.-channelOpened h)
|
(set! (.-channelOpened h)
|
||||||
(fn [channel]
|
(fn [channel]
|
||||||
(run-middleware (:on-open @handler-middleware) (fn []))
|
(run-middleware (:on-open @handler-middleware) (fn []))))
|
||||||
(handle-outgoing channel)))
|
|
||||||
(set! (.-channelHandleArray h)
|
(set! (.-channelHandleArray h)
|
||||||
(fn [channel msg]
|
(fn [channel msg]
|
||||||
(handle-incoming channel msg)))
|
(handle-incoming channel msg)))
|
||||||
|
|
Reference in a new issue