taoensso / sente

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

Ring 1.11 adoption #443

Open sunng87 opened 5 months ago

sunng87 commented 5 months ago

The newly released Ring 1.11 has standardized websocket APIs for its application: https://github.com/ring-clojure/ring/blob/master/SPEC.md#3-websockets. So I think it is also possible to make sente standardized by adoption of the websocket api.

My https://github.com/sunng87/ring-jetty9-adapter has an implementation of Ring 1.11 for both http and websocket. If we can build sente fully on Ring 1.11, theoretically it should be able to run on any webserver that is compatible.

This also expires #424, we don't need to build an implementation for rj9a specifically any more.

enspritz commented 5 months ago

This improvement perfectly fits our use case. While we are at it, if we can specify JS WebSocket API option values like #js {:rejectUnauthorized false}.

ptaoussanis commented 5 months ago

@sunng87 Hi Ning, I hope you're well!

I'll definitely take a look at this when I'm next doing batched work on Sente. If I recall correctly though, the problem blocking a Ring Jetty9 adapter wasn't the WebSocket API - Sente already provided an interface for this that different servers can interop with easily enough.

The problem was on the HTTP (not WebSocket) side. Sente's Ajax mode needs the server to support an async callback or other method, so that Sente can track requests and respond to them on demand.

The Ring Jetty adapter didn't seem to support this use case if I understood correctly? There was some discussion and work on this here and here - though no one at that time was able to provide an adapter that could support Ajax correctly.

As part of that work I added experimental support to Sente for Ring's 3-arity async handlers, but couldn't get a confirmation in the end if that was helpful in Ring Jetty's case. And because of the way Ring's async API works, it's a bit of a nuisance to try test since it's incompatible with the standard (1-arity) case.

So unless I'm misunderstanding something, Sente adopting Ring 1.11 likely won't change anything for any users. The only change I'm anticipating is internal: with Ring providing an official WebSocket interface, server authors don't need to invent their own. If they all use the same WebSocket interface, it means the WebSocket part of any Sente adapter can use the same code. But that's never really been a big issue to be honest, since it's normally only a couple lines of code to adapt.

Hope that makes some sense!

ptaoussanis commented 5 months ago

@enspritz Hi there! I don't believe what you're asking for here is related to Ring 1.11's WebSocket API. Could you please create a separate issue and explain in some more detail what your specific use case is?

Thanks!

enspritz commented 5 months ago

@enspritz Hi there! I don't believe what you're asking for here is related to Ring 1.11's WebSocket API. Could you please create a separate issue and explain in some more detail what your specific use case is?

Thanks!

Got it!