rename "browserchannel-session-id" to the much shorter "client-id"
This commit is contained in:
parent
17f15b797b
commit
83486ef11b
|
@ -12,24 +12,24 @@
|
||||||
|
|
||||||
(defn send
|
(defn send
|
||||||
"sends a browserchannel message to a client identified by the given
|
"sends a browserchannel message to a client identified by the given
|
||||||
browserchannel session id. topic should be a keyword, while body can be
|
browserchannel client id. topic should be a keyword, while body can be
|
||||||
anything. returns nil if the message was not sent."
|
anything. returns nil if the message was not sent."
|
||||||
[browserchannel-session-id topic body]
|
[client-id topic body]
|
||||||
(let [msg {:topic topic
|
(let [msg {:topic topic
|
||||||
:body body}]
|
:body body}]
|
||||||
(run-middleware
|
(run-middleware
|
||||||
(:on-send @handler-middleware)
|
(:on-send @handler-middleware)
|
||||||
(fn [browserchannel-session-id msg]
|
(fn [client-id msg]
|
||||||
(if-let [encoded (encode-message msg)]
|
(if-let [encoded (encode-message msg)]
|
||||||
(browserchannel/send-map browserchannel-session-id encoded)))
|
(browserchannel/send-map client-id encoded)))
|
||||||
browserchannel-session-id msg)))
|
client-id 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.
|
||||||
executes the passed handler function when any are received. handler should
|
executes the passed handler function when any are received. handler should
|
||||||
be a function which accepts the received decoded message. the decoded
|
be a function which accepts the received decoded message. the decoded
|
||||||
message will contain the browserchannel session id of the client that
|
message will contain the browserchannel client id of the client that
|
||||||
sent the message under :browserchannel-session-id.
|
sent the message under :client-id.
|
||||||
note that the handler is executed asynchronously."
|
note that the handler is executed asynchronously."
|
||||||
[topic handler]
|
[topic handler]
|
||||||
(let [incoming-topic-messages (chan)]
|
(let [incoming-topic-messages (chan)]
|
||||||
|
@ -39,37 +39,37 @@
|
||||||
(handler msg)
|
(handler msg)
|
||||||
(recur)))))
|
(recur)))))
|
||||||
|
|
||||||
(defn- handle-session [browserchannel-session-id req]
|
(defn- handle-session [client-id req]
|
||||||
(run-middleware
|
(run-middleware
|
||||||
(:on-open @handler-middleware)
|
(:on-open @handler-middleware)
|
||||||
(fn [browserchannel-session-id request]
|
(fn [client-id request]
|
||||||
; no-op
|
; no-op
|
||||||
)
|
)
|
||||||
browserchannel-session-id req)
|
client-id req)
|
||||||
|
|
||||||
(browserchannel/add-listener
|
(browserchannel/add-listener
|
||||||
browserchannel-session-id
|
client-id
|
||||||
:close
|
:close
|
||||||
(fn [request reason]
|
(fn [request reason]
|
||||||
(run-middleware
|
(run-middleware
|
||||||
(:on-close @handler-middleware)
|
(:on-close @handler-middleware)
|
||||||
(fn [browserchannel-session-id request reason]
|
(fn [client-id request reason]
|
||||||
; no-op
|
; no-op
|
||||||
)
|
)
|
||||||
browserchannel-session-id request reason)))
|
client-id request reason)))
|
||||||
|
|
||||||
(browserchannel/add-listener
|
(browserchannel/add-listener
|
||||||
browserchannel-session-id
|
client-id
|
||||||
:map
|
:map
|
||||||
(fn [request m]
|
(fn [request m]
|
||||||
(if-let [decoded (decode-message m)]
|
(if-let [decoded (decode-message m)]
|
||||||
(let [msg (assoc decoded :browserchannel-session-id browserchannel-session-id)]
|
(let [msg (assoc decoded :client-id client-id)]
|
||||||
(run-middleware
|
(run-middleware
|
||||||
(:on-receive @handler-middleware)
|
(:on-receive @handler-middleware)
|
||||||
(fn [browserchannel-session-id request msg]
|
(fn [client-id request msg]
|
||||||
(if msg
|
(if msg
|
||||||
(put! incoming-messages msg)))
|
(put! incoming-messages msg)))
|
||||||
browserchannel-session-id request msg))))))
|
client-id request msg))))))
|
||||||
|
|
||||||
(defn wrap-browserchannel
|
(defn wrap-browserchannel
|
||||||
"Middleware to handle server-side browserchannel session and message
|
"Middleware to handle server-side browserchannel session and message
|
||||||
|
@ -97,8 +97,8 @@
|
||||||
(assoc
|
(assoc
|
||||||
opts
|
opts
|
||||||
:on-session
|
:on-session
|
||||||
(fn [browserchannel-session-id request]
|
(fn [client-id request]
|
||||||
(handle-session browserchannel-session-id request)))))))
|
(handle-session client-id request)))))))
|
||||||
|
|
||||||
(defn init!
|
(defn init!
|
||||||
"Sets up browserchannel for server-side use. This function should be called
|
"Sets up browserchannel for server-side use. This function should be called
|
||||||
|
@ -118,9 +118,9 @@
|
||||||
the chain of middleware. e.g.
|
the chain of middleware. e.g.
|
||||||
|
|
||||||
{:on-send (fn [handler]
|
{:on-send (fn [handler]
|
||||||
(fn [session-id request {:keys [topic body] :as msg]
|
(fn [client-id request {:keys [topic body] :as msg]
|
||||||
; do something here with the message to be sent
|
; do something here with the message to be sent
|
||||||
(handler session-id request msg)))}
|
(handler client-id request msg)))}
|
||||||
|
|
||||||
Remember that middleware is run in the reverse order that they appear
|
Remember that middleware is run in the reverse order that they appear
|
||||||
in the vector you pass in.
|
in the vector you pass in.
|
||||||
|
@ -129,24 +129,24 @@
|
||||||
|
|
||||||
:on-open
|
:on-open
|
||||||
Occurs when a new browserchannel session has been established. Receives 2
|
Occurs when a new browserchannel session has been established. Receives 2
|
||||||
arguments: the browserchannel session id and the request map (for the
|
arguments: the browserchannel client id and the request map (for the
|
||||||
request that resulted in the browserchannel session being established) as
|
request that resulted in the browserchannel session being established) as
|
||||||
arguments.
|
arguments.
|
||||||
|
|
||||||
:on-receive
|
:on-receive
|
||||||
Occurs when a new message is received from a client. Receives 3 arguments:
|
Occurs when a new message is received from a client. Receives 3 arguments:
|
||||||
the browserchannel session id, the request map (for the client request that
|
the browserchannel client id, the request map (for the client request that
|
||||||
the message was sent with), and the actual decoded message as arguments.
|
the message was sent with), and the actual decoded message as arguments.
|
||||||
the browserchannel session id of the client that sent the message is
|
the browserchannel client id of the client that sent the message is
|
||||||
automatically added to the message under :browserchannel-session-id.
|
automatically added to the message under :client-id.
|
||||||
|
|
||||||
:on-send
|
:on-send
|
||||||
Occurs when a message is to be sent to a client. Receives 2 arguments:
|
Occurs when a message is to be sent to a client. Receives 2 arguments:
|
||||||
the browserchannel session id and the actual message to be sent.
|
the browserchannel client id and the actual message to be sent.
|
||||||
|
|
||||||
:on-close
|
:on-close
|
||||||
Occurs when the browserchannel session is closed. Receives 3 arguments: the
|
Occurs when the browserchannel session is closed. Receives 3 arguments: the
|
||||||
browserchannel session id, the request map (for the request sent by the
|
browserchannel client id, the request map (for the request sent by the
|
||||||
client causing the session to be closed, if any), and a string containing
|
client causing the session to be closed, if any), and a string containing
|
||||||
the reason for the session close. Note that, this may or may not be
|
the reason for the session close. Note that, this may or may not be
|
||||||
initiated directly by the client. The request argument will be nil if the
|
initiated directly by the client. The request argument will be nil if the
|
||||||
|
|
Reference in a new issue