Skip to content

Commit 76b8abc

Browse files
committed
[mod] [Aleph adapter] [#350] Experimental change to support Ring middleware (@g7s)
1 parent 0b37e4c commit 76b8abc

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/taoensso/sente/server_adapters/aleph.clj

+8-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
(ring-req->server-ch-resp [sch-adapter ring-req callbacks-map]
3030
(let [{:keys [on-open on-close on-msg _on-error]} callbacks-map
3131
ws? (websocket-req? ring-req)]
32-
(if ws?
33-
(d/chain (aleph/websocket-connection ring-req opts)
34-
(fn [s] ; sch
35-
(when on-msg (s/consume (fn [msg] (on-msg s ws? msg)) s))
36-
(when on-close (s/on-closed s (fn [] (on-close s ws? nil))))
37-
(when on-open (do (on-open s ws?)))
38-
{:body s}))
32+
(if-let [s (and ws? (try @(aleph/websocket-connection ring-req opts)
33+
(catch Exception e nil)))]
34+
(do
35+
(when on-msg (s/consume (fn [msg] (on-msg s ws? msg)) s))
36+
(when on-close (s/on-closed s (fn [] (on-close s ws? nil))))
37+
(when on-open (do (on-open s ws?)))
38+
{:body s})
39+
3940
(let [s (s/stream)] ; sch
4041
(when on-close (s/on-closed s (fn [] (on-close s ws? nil))))
4142
(when on-open (do (on-open s ws?)))

0 commit comments

Comments
 (0)