From 47f6a6d94644ff7af52ecb1e0a219f7356268782 Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 15 May 2016 11:52:13 -0400 Subject: [PATCH] allow data to be sent included in the new session forward ch request this is part of the browserchannel protocol and can be an optimization for some applications (less round trips to the server when the app is establishing the browserchannel session) --- .../src/net/thegeez/browserchannel/server.clj | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/clj-browserchannel/src/net/thegeez/browserchannel/server.clj b/clj-browserchannel/src/net/thegeez/browserchannel/server.clj index ad8af8a..5ee3b01 100644 --- a/clj-browserchannel/src/net/thegeez/browserchannel/server.clj +++ b/clj-browserchannel/src/net/thegeez/browserchannel/server.clj @@ -707,6 +707,14 @@ [(create-session-agent req options) true]) ;; maps contains whatever the messages to the server maps (get-maps req)] + ;; if maps were received in this request, we should forward to listeners + ;; (client is allowed to send requests in the new session request as well, + ;; so for both existing sessions and new sessions we do this) + (if (and (seq maps) + session-agent) + (doseq [m maps] + (let [decoded (decode-map m)] + (notify-listeners (:id @session-agent) req :map decoded)))) (if is-new-session ;; first post after a new session is a message with the session ;; details. @@ -721,19 +729,14 @@ :headers (assoc (:headers options) "Content-Type" "application/javascript") :body (size-json-str (json/generate-string [[0, ["c", session-id, host-prefix, protocol-version]]]))}) ;; For existing sessions: - ;; Forward sent data by client to listeners ;; reply with ;; [backchannelPresent,lastPostResponseArrayId_,numOutstandingBackchannelBytes] ;; backchannelPresent = 0 for false, 1 for true ;; send as json for XHR and IE - (do - (doseq [m maps] - (let [decoded (decode-map m)] - (notify-listeners (:id @session-agent) req :map decoded))) - (let [status (session-status @session-agent)] - {:status 200 - :headers (:headers options) - :body (size-json-str (json/generate-string status))}))))) + (let [status (session-status @session-agent)] + {:status 200 + :headers (:headers options) + :body (size-json-str (json/generate-string status))})))) ;; GET req server->client is a backwardchannel opened by client (defn- handle-backward-channel