-
-
Save dvingo/fce8720a40b2b18fc027c49727f7db25 to your computer and use it in GitHub Desktop.
Access WebSocket session in Pedestal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn ws-listener | |
[_request _response ws-map] | |
(proxy [WebSocketAdapter] [] | |
(onWebSocketConnect [^Session ws-session] | |
(proxy-super onWebSocketConnect ws-session) | |
(when-let [f (:on-connect ws-map)] | |
(f ws-session))) | |
(onWebSocketClose [status-code reason] | |
(when-let [f (:on-close ws-map)] | |
(f (.getSession this) status-code reason))) | |
(onWebSocketError [^Throwable e] | |
(when-let [f (:on-error ws-map)] | |
(f (.getSession this) e))) | |
(onWebSocketText [^String message] | |
(when-let [f (:on-text ws-map)] | |
(f (.getSession this) message))) | |
(onWebSocketBinary [^bytes payload offset length] | |
(when-let [f (:on-binary ws-map)] | |
(f (.getSession this) payload offset length))))) | |
;; in your service map: | |
::http/container-options {:context-configurator #(ws/add-ws-endpoints % ws-paths {:listener-fn ws-listener})} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment