From 88a212316ae09c3719f1b3330685323d84c4b92f Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 27 Dec 2014 17:54:35 -0500 Subject: [PATCH] remove the core.async channel for sending client->server messages --- .../clj_browserchannel_messaging/client.cljs | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/cljs/clj_browserchannel_messaging/client.cljs b/src/cljs/clj_browserchannel_messaging/client.cljs index b0bab6b..b5be427 100644 --- a/src/cljs/clj_browserchannel_messaging/client.cljs +++ b/src/cljs/clj_browserchannel_messaging/client.cljs @@ -13,12 +13,18 @@ (defonce incoming-messages (chan)) (defonce incoming-messages-pub (pub incoming-messages :topic)) -(defonce outgoing-messages (chan)) (defn send "sends a browserchannel message to the server asynchronously." [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 "listens for incoming browserchannel messages with the specified topic. @@ -33,17 +39,6 @@ (handler msg) (recur))))) -(defn- handle-outgoing [channel] - (go-loop [] - (when-let [msg (js encoded)))) - msg) - (recur)))) - (defn- handle-incoming [channel msg] (when-let [decoded (decode-message (js->clj msg))] (run-middleware @@ -75,8 +70,7 @@ (let [h (goog.net.BrowserChannel.Handler.)] (set! (.-channelOpened h) (fn [channel] - (run-middleware (:on-open @handler-middleware) (fn [])) - (handle-outgoing channel))) + (run-middleware (:on-open @handler-middleware) (fn [])))) (set! (.-channelHandleArray h) (fn [channel msg] (handle-incoming channel msg)))