I'm trying to interface with Slack's RTM API with Aleph.
Currently I have this code:
(defn connect-socket []
(let [conn @(http/websocket-client (get-websocket-url))]
(s/consume #(prn %) conn)
(send-message conn {:type "ping"}) ;; just to check if send-message works
(s/on-closed conn (prn "closed"))))
It works well for the first few times, and then conn
stops receiving messages from Slack after some inactivity. Neither does it print "closed", which seems to signify that the stream isn't closed. I'm not quite sure what is happening here.
How can I keep-alive the websocket connection, or auto-reconnect if disconnected? I've seen some code in the wild doing pings, but I don't think I understand the code well enough to adapt it.
I think that you have to send ping messages because :
sente
to support Aleph).Therefore you have to do some "pings" regularly.
Regarding the code, on-closed
wants a function as second argument, so :
(s/on-closed! conn #(prn "closed"))