-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add clj client support #275
Conversation
Hi there, thanks a lot for this! Since the PR touches so much code, any chance I could ask you to possibly summarise any significant changes that were made so that I know where to focus attention? Will try schedule a look w/in the next week or two. Again, much appreciated - cheers! :-) |
This is easier to review with https://github.com/ptaoussanis/sente/pull/275/files?w=0 as it hides whitespace changes. |
@danielcompton Ooh, wasn't familiar with that feature - thanks! That's a nice time saver. @Frozenlock For clarity: still keen to get an overview of necessary changes, esp. if anything is non-obvious or involved tradeoffs that I should be aware of. The quicker I can evaluate a PR, the more likely that I can get it merged quickly. Thanks, cheers! :-) |
@danielcompton thanks for the link. @ptaoussanis not much has changed; for some reason git doesn't like when we remove the reader conditionals ;-) Most of the work (other than understanding how all that worked) was extracting the JS-only stuff from I would invite you to check the addition into interfaces.clj to know what was my approach for this. Users can provide (let [{:keys [chsk ch-recv send-fn state]}
(sente/make-channel-socket-client! "/chsk"
{:type :ws ; e/o #{:auto :ajax :ws}
:protocol :http
:host "localhost:3444"
:cws-creator al/aleph-create-client-websocket!})]
(def chsk chsk)
(def ch-chsk ch-recv) ; ChannelSocket's receive channel
(def chsk-send! send-fn) ; ChannelSocket's send API fn
(def chsk-state state) ; Watchable, read-only atom
) All of this is very basic - just enough to get it to work. The user has to manually provide the protocol and the host when using the clj client. |
Great, thanks for the details. Will try take a look next week, soon as I can! |
I'll emphasize on how this was just the minimum required to get it to work. I'd appreciate if someone a little more familiar with |
No problem :-) Would welcome feedback if anyone has in the meantime, but I also take a good look at everything myself before merging. Just have my hands very full lately, so try schedule batches on each project. |
Just chiming in to say that I ran into this limitation today, and will be eyeballing this PR. Thanks to you both! |
Sorry for the delay on this, haven't forgotten - just prepping for a move in the next 2 weeks. Will try make this a priority soon as I'm settled again next month. |
Hi - I've got a question regarding this PR since I'm an interested side as well :) - any chance of this getting ajax support as well? |
Any updates on the support for clj client? |
[url {:keys [on-msg on-error on-close]}] | ||
(let [ws (try @(aleph/websocket-client url) | ||
(catch Exception e | ||
(do (errorf e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like errorf
expects a format string as second argument?
(when on-msg (s/consume (fn [msg] | ||
(try (on-msg msg) | ||
(catch Exception e | ||
(when on-error e)))) ws)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean (when on-error (on-error e))
?
It looks like the
I cannot see the metadata effectively used by the new code, is that correct @Frozenlock ? |
(when-let [Websocket (or | ||
(enc/oget goog/global "WebSocket") | ||
(enc/oget goog/global "MozWebSocket") | ||
(enc/oget @?node-npm-webclient-chan_ "w3cwebsocket"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this has been renamed from node-npm-websocket_
? I can't find where this comes from now though.
|
||
(aset "onclose" | ||
(fn [ws-ev] | ||
(on-close ws-evt)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be ws-ev
?
57698af
to
216b166
Compare
This will be addressed in the next release which I'll be pushing w/in the next hour. Closing. |
I tried to separate
sente
's logic from the websocket implementation while changing the least amount of things possible. Ajax is still cljs only.It's probably a little more low-level than the
IServerChanAdapter
. Here we provide a function to letsente
create new websockets when needed.Tested with both cljs and clj (aleph) and it seems to work.