Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for websocket-connection options #390

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/taoensso/sente/server_adapters/aleph.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
(when-let [s (get-in ring-req [:headers "upgrade"])]
(= "websocket" (str/lower-case s))))

(deftype AlephAsyncNetworkChannelAdapter []
(deftype AlephAsyncNetworkChannelAdapter [options]
i/IServerChanAdapter
(ring-req->server-ch-resp [sch-adapter ring-req callbacks-map]
(let [{:keys [on-open on-close on-msg _on-error]} callbacks-map
ws? (websocket-req? ring-req)]
(if ws?
(d/chain (aleph/websocket-connection ring-req)
(d/chain (aleph/websocket-connection ring-req options)
(fn [s] ; sch
(when on-msg (s/consume (fn [msg] (on-msg s ws? msg)) s))
(when on-close (s/on-closed s (fn [] (on-close s ws? nil))))
Expand All @@ -41,4 +41,8 @@
(when on-open (do (on-open s ws?)))
{:body s})))))

(defn get-sch-adapter [] (AlephAsyncNetworkChannelAdapter.))
(defn get-sch-adapter
"Supports websocket-connection options in aleph.http. If no option map is provided,
the default options apply."
([] (AlephAsyncNetworkChannelAdapter. nil))
([options] (AlephAsyncNetworkChannelAdapter. options)))