Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

Frozenlock
Copy link

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 let sente create new websockets when needed.

Tested with both cljs and clj (aleph) and it seems to work.

@ptaoussanis
Copy link
Member

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! :-)

@ptaoussanis ptaoussanis self-assigned this Oct 14, 2016
@danielcompton
Copy link
Collaborator

This is easier to review with https://github.com/ptaoussanis/sente/pull/275/files?w=0 as it hides whitespace changes.

@ptaoussanis
Copy link
Member

@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! :-)

@Frozenlock
Copy link
Author

@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 ChWebSocket and putting it in JSDefaultWebSocket.

I would invite you to check the addition into interfaces.clj to know what was my approach for this.

Users can provide :cws-creator like this:

(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.

@ptaoussanis
Copy link
Member

Great, thanks for the details. Will try take a look next week, soon as I can!

@Frozenlock
Copy link
Author

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 sente could polish it to be more sente-like.

@ptaoussanis
Copy link
Member

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.

@robert-spurrier
Copy link

Just chiming in to say that I ran into this limitation today, and will be eyeballing this PR. Thanks to you both!

@ptaoussanis
Copy link
Member

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.

@nha nha mentioned this pull request Nov 28, 2016
@ignorabilis
Copy link

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?

@Frozenlock
Copy link
Author

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)
Copy link

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))
Copy link

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))?

@nha
Copy link

nha commented Dec 9, 2017

It looks like the meta argument of the packer has been removed since this PR.

(pack packer (meta resp-clj) resp-clj) ;; (meta resp-clj) should be removed

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"))]
Copy link

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))))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be ws-ev?

@ptaoussanis
Copy link
Member

This will be addressed in the next release which I'll be pushing w/in the next hour. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants