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

websockets #72

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

websockets #72

wants to merge 12 commits into from

Conversation

bgwdotdev
Copy link

@bgwdotdev bgwdotdev commented May 11, 2024

Here's a first pass, scrappy implementation of mists websockets into wisp. #10

Still figuring out if there's a better way to do this and discussing with rawhat a little on approaches.

This currently works though. Feedback on approach most welcome.

Option was only added due to the test stuff, not sure how do deal with that yet but maybe that's solving the wrong problem.

Copy link
Collaborator

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thank you! This couples Wisp very tightly to Mist, which it carefully does not do so far. We'll need to decouple it, I've left some notes inline.

src/wisp.gleam Outdated Show resolved Hide resolved
src/wisp.gleam Show resolved Hide resolved
src/wisp.gleam Outdated Show resolved Hide resolved
@bgwdotdev
Copy link
Author

I've now created a pure wisp public api for this which mostly wraps the mist types.

Docs (and likely type names/api) still need work but wanted to verify if the approach is more suitable for wisp before attempting to polish things.

Hopefully the Socket type would allow wrapping various connection types that may be required by potentially different backends as appropriate?

Let me know if I'm on the right track or missing a beat.

Thanks :)

Copy link
Collaborator

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Nice!! I like how this is coming along.

There's still some dependency of Mist that needs to be removed. Soon the Mist specific code will be moved to another package, so there can be no dependency here.

Another problem to solve is how do we make it so a Wisp application can only upgrade to a websocket connection if the webserver being used supports it? For example, Elli and CGI don't support websockets, so the programmer must not have the ability to construct a websocket response in those cases. Perhaps it could be that there's some secondary capability value that gets passed in by websocket capable servers, and that is need to upgrade within the application. Whatever the solution the same pattern will need to be usable for server sent events too.

Another thing is how do we write tests for websocket using applications too.

Is there any other problems to solve or other considerations?

src/wisp.gleam Outdated Show resolved Hide resolved
src/wisp.gleam Outdated Show resolved Hide resolved
src/wisp.gleam Outdated Show resolved Hide resolved
@bgwdotdev
Copy link
Author

bgwdotdev commented Jun 18, 2024

Okay. Had a big stab at moving all the mist stuff into a separate module.

I've fully removed the import mist from the main wisp.gleam file.

Websockets are also now implemented with a reference example in the test file.

I've had to make a couple things in the wisp.gleam file public that I'm not sure we want to keep that way (mostly around make_connection).

Everything needs a tidy, documentation and the test cases fleshed out but hopefully it's looking more like how we want it to be ^^?

Definitely not finished working on it (want to try dump mist from internal somehow) but keen to take any feedback generally at this stage!

gleam.toml Outdated Show resolved Hide resolved
@bgwdotdev
Copy link
Author

bgwdotdev commented Jun 25, 2024

Okay! I think I'm feeling happy with the general api design and split of things now and was thinking of moving on to docs.

I was thinking of creating a websocket error type within wisp as well for when wisp_mist.send fails, though looking at the errors provided from mist via glisten, I'm thinking we might want to just cover important ones like Closed and Timeout maybe and then the others can fall under some more generic socket error that left for the user to handle? (here's the variants for reference https://hexdocs.pm/glisten/3.0.0/glisten/socket.html#SocketReason)

@bgwdotdev
Copy link
Author

bgwdotdev commented Jun 26, 2024

left to do:

  • update examples to use wisp_mist.handler
  • write example using websocket

done?

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

Successfully merging this pull request may close these issues.

None yet

2 participants