taoensso / sente

Realtime web comms library for Clojure/Script
https://www.taoensso.com/sente
Eclipse Public License 1.0
1.74k stars 193 forks source link

Allow channel setup without connecting #313

Open michihuber opened 6 years ago

michihuber commented 6 years ago

Hi,

Thank you very much for sente, it really does save a lot of work!

I have two somewhat related issues: 1) It would be useful if I could set up the channel without connecting immediately. 2) When reconnecting, it would be useful to be able to pass new params.

The usecase for 1) would be to set up the channel as part of the system (and get hold of :ch-recv and :send-fn) but not connect just yet if the user needs to authenticate first (e.g., fetch an authentication token through ajax). This would avoid errors being logged while authentication fails in the websocket requests.

Then, when reconnecting (or in this case, connecting), it would be great to be able to pass new params (e.g. in this case, the fetched authentication token).

Right now, I work around this by connecting immediately (which logs errors), and when the token was acquired doing:

(sente/chsk-reconnect!
  (-> chsk
      (assoc-in [:ws-chsk-opts :params :auth-token] token)
      (assoc-in [:ajax-chsk-opts :params :auth-token] token)))

Would you accept a patch for this functionality?

ptaoussanis commented 6 years ago

Hi Michi,

Would be happy to look at a PR (maybe 2 separate PRs for the 2 items mentioned above?)- thanks! :+1:

Edit to add: Otherwise please 👍 if someone else is reading this and interested in the feature.