bandit icon indicating copy to clipboard operation
bandit copied to clipboard

WebSocket integration

Open moogle19 opened this issue 2 years ago • 1 comments

Are there any concrete plans on how to integrate WebSockets?

Currently bandit doesn't do any routing and delegates everything to Plug (which doesn't support WebSockets (yet?)).

Will bandit handle the routing for the WebSockets or are there any plans on integrating WebSockets into the Plug.Router (either via adding it to Plug directly or injecting it via macro)?

moogle19 avatar Feb 01 '22 09:02 moogle19

Funny you should ask. I've been turning my attention to this over the past couple of weeks, starting to sketch out some ideas.

The scope and mandate of Plug is squarely focused on HTTP semantics, and I don't think there's really reason for that to change. It's a tight API that does one thing really well and I'd like for it to stay that way. My thoughts lately have been that WebSockets would be exposed via an API similar to (but distinct from) Plug, with semantics more appropriate for WebSockets. In that spirit, I'd been assuming that routing concerns would be outside of Bandit's purview, much as they are for HTTP. To the extent we may want to generalize WebSocket routing & connection concerns, I think middleware included with this new project would be the most sensible place to implement it (similar to how Plug-the-library comprises both 'Plug-the-API' and 'Plug-the-bundled-set-of-middleware').

From a practical perspective, there's still a a lot to figure out here, and I'll admit to not having my arms completely around it just yet. My plan was to fork Phoenix and spend some informal time doing an adhoc buildout of lib/phoenix/endpoint/bandit_{adapter, handler}.ex to line up all the moving parts in my mind before making some more concrete decisions.

mtrudel avatar Feb 01 '22 15:02 mtrudel

One feature that I will be looking for woulde be support for serving HTTP requests on the same URI as WebSocket. This is something Phoenix doesn't and probably won't support and it is requried to support some protocols build on top of WebSockets.

Phoenix issue https://github.com/phoenixframework/phoenix/issues/4652 Example of a protocol serving HTTP on the same URI as WebSockets https://github.com/nostr-protocol/nips/blob/master/11.md

Sgiath avatar Sep 02 '22 13:09 Sgiath

Support for this is already present in the working branch for websocket support! Expect some serious progress on this later on this month; I'll be spending an entire week on it during our company hack week!

mtrudel avatar Sep 02 '22 16:09 mtrudel

Yeah I already started playing with it and seems to be working fine :) thank you for your work 👍🏻

Sgiath avatar Sep 03 '22 06:09 Sgiath

Work on #26 (shortly being merged into main) is well in hand; this ticket no longer reflects the current state of the project.

mtrudel avatar Sep 20 '22 01:09 mtrudel