Skip to content

Commit

Permalink
[mod] [Aleph adapter] [#350] Experimental change to support Ring midd…
Browse files Browse the repository at this point in the history
…leware (@g7s)
  • Loading branch information
ptaoussanis committed Mar 7, 2023
1 parent 0b37e4c commit 76b8abc
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/taoensso/sente/server_adapters/aleph.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
(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 opts)
(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))))
(when on-open (do (on-open s ws?)))
{:body s}))
(if-let [s (and ws? (try @(aleph/websocket-connection ring-req opts)
(catch Exception e nil)))]
(do
(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))))
(when on-open (do (on-open s ws?)))
{:body s})

(let [s (s/stream)] ; sch
(when on-close (s/on-closed s (fn [] (on-close s ws? nil))))
(when on-open (do (on-open s ws?)))
Expand Down

0 comments on commit 76b8abc

Please sign in to comment.