Skip to content

Commit

Permalink
fixup! [mod] [taoensso#424] reintroduce fixed jetty9-ring-adapter s…
Browse files Browse the repository at this point in the history
…upport
  • Loading branch information
TimoKramer committed Mar 21, 2023
1 parent fef4bc0 commit fd6a1cc
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,41 @@
(server-ch-resp (jetty9.websocket/ws-upgrade-request? req) callbacks-map))))

(defn get-sch-adapter [] (JettyServerChanAdapter.))

(comment
(require '[ring.adapter.jetty9 :refer [run-jetty stop-server]]
'[taoensso.sente :as sente]
'[compojure.core :refer :all])

(let [{:keys [ch-recv send-fn connected-uids
ajax-post-fn ajax-get-or-ws-handshake-fn]}
(sente/make-channel-socket! (get-sch-adapter) {})]
(def ring-ajax-post ajax-post-fn)
(def ring-ajax-get-or-ws-handshake ajax-get-or-ws-handshake-fn)
(def ch-chsk ch-recv) ; ChannelSocket's receive channel
(def chsk-send! send-fn) ; ChannelSocket's send API fn
(def connected-uids connected-uids)) ; Watchable, read-only atom

(defroutes my-app-routes
;; <other stuff>

;;; Add these 2 entries: --->
(GET "/chsk" req (ring-ajax-get-or-ws-handshake req))
(POST "/chsk" req (ring-ajax-post req)))

(def server (atom nil))
(reset! server (run-jetty my-app-routes {:port 50505
:join? false
:async? true}))
(stop-server @server)

(let [{:keys [chsk ch-recv send-fn state]}
(sente/make-channel-socket-client!
"/chsk" ; Note the same path as before
"foo"
{:type :ws})] ; e/o #{:auto :ajax :ws}

(def chsk chsk)
(def ch-chsk ch-recv) ; ChannelSocket's receive channel
(def chsk-send! send-fn) ; ChannelSocket's send API fn
(def chsk-state state))) ; Watchable, read-only atom

0 comments on commit fd6a1cc

Please sign in to comment.