Fork me on GitHub
#aleph
<
2021-05-12
>
gomosdg08:05:29

I am trying to serve ws connection and html from a single controller using:

(d/catch
                        (http/websocket-connection req)
                        (fn [_] nil))

gomosdg08:05:52

and serving html when conn is nil

gomosdg08:05:51

But when it seems like aleph ends up getting the exception from http/websocket-connection anyways and instead of displaying my html it shows “expected websocket request” on the browser

gomosdg08:05:23

The full handler:

(defn room-handler [req]
  (d/let-flow [room-id (get-in req [:params :room-id])
               username (get-in req [:session :identity])
               room (get @rooms room-id)
               conn (d/catch
                        (http/websocket-connection req)
                        (fn [_] nil))]

              (if conn
                (r/add-user! room {:username username
                                   :stream conn})
                (layouts/main (str "SDG Rooms - " (r/get-name room))
                              (r/get-view room)))))

hiredman17:05:04

the way websockets are usually handled (in netty, not sure about aleph) is you pick a specific url path (route) for websockets

hiredman17:05:08

my guess is the netty websocket stuff returns the “expected websocket request” instead of throwing any kind of exception