Skip to content

Commit

Permalink
[#390] [Aleph adapter] Add support for websocket-connection options (@…
Browse files Browse the repository at this point in the history
…KaliszAd)

The use-case is e.g. if you want to send larger WS messages.
The max-frame-payload is 65536 bytes and max-frame-size is 1048576 bytes by default.
It seems, the disassembly/ reassembly of frames isn't supported in some scenarios but
there is still need for larger data transfer over WS. Therefore the easiest solution
is to just increase the max-frame-payload size. Aleph currently has 7 options to
configure more appropriate settings in less common circumstances.

If no map of options is provided, the code works as before and is therefore to the
best of my knowledge backwards compatible.
  • Loading branch information
KaliszAd authored and ptaoussanis committed May 31, 2022
1 parent 040048b commit fd28e58
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/taoensso/sente/server_adapters/aleph.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@
(when-let [s (get-in ring-req [:headers "upgrade"])]
(= "websocket" (str/lower-case s))))

(deftype AlephAsyncNetworkChannelAdapter []
(deftype AlephAsyncNetworkChannelAdapter [opts]
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 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?)))
(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?)))
(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))
([opts] (AlephAsyncNetworkChannelAdapter. opts)))

0 comments on commit fd28e58

Please sign in to comment.