-
Notifications
You must be signed in to change notification settings - Fork 540
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
WebSocket #932
Comments
cc @lpinca |
This should be quite easy. Reference: https://github.com/szmarczak/http2-wrapper/blob/master/examples/ws/index.js |
@szmarczak I know it is a demo but that example basically skips the opening handshake. There is no validation and no subprotocol/extension negotiation. |
Interested in this one. Would try to implement if it is availabe! |
Are there any advantages in building websockets here on top of undici compared to what exists in https://github.com/websockets/ws? (maybe performance?) |
I'm totally ok in using ws for this. It's a great module by @lpinca and I hope we will emebed it in core one day. |
@mcollina this would be really a great opportunity for me to learn more about WS. Can I start working on this? |
I don't think we should do another implementation, I think the |
ws is great but I think the implementation is too different from the spec WebSocket. There's also outstanding issues where it uses a custom EventTarget (websockets/ws#1818). Then there's a bunch of webidl issues I could spot with a cursory glance (Websocket extends EventEmitter, underscore indexed properties) and the fact that WPTs aren't being run. Undici (or maybe the nodejs org) should fork or add ws as a git submodule where we could make breaking changes from the ws api & run WPTs, to ensure cross compatibility. Basically I see this as another spec fetch vs. node-fetch issue. Both might share a similar API but are different enough that there isn't a cross-compatibility guarantee. |
Following the https://websockets.spec.whatwg.org/ spec in every single detail is a non-goal for I think |
I think we should have our own implementation then. Maybe reusing ws or some parts of it under the hood. |
@mcollina i will give it a try and formulate a plan before implementing so that we don't waste time |
I'm still not quite sure about how we want to implement it. Do we wanna use ws as a dependency inside undici or do we want to implement WS from scratch and maybe get some ideas from ws? |
Wdyt @KhafraDev? |
Using ws:
Creating our own:
If possible, having our own implementation that borrows from ws would be the ideal solution. We would need to implement the entirety of the WebSocket class in either case, for the reasons mentioned above ("Following the ... spec ... is a non-goal for ws"). |
The WebSocket protocol has nothing to do with HTTP apart from the initial handshake. Once the initial connection is established the work is done against a
Yes, they do, but not all HTTP proxies can proxy WebSocket.
Other
|
I took a shot at it and got close (I think) to a working initial handshake. If anyone wants a place to start, it might be worth checking my branch out https://github.com/KhafraDev/undici/tree/ws/lib/websocket. |
👍 for rolling our own that is more spec compatible with wpt tests and webidl stuff I would really much like it if it where possible to get a blob from the file system, send it with |
I took another stab at the initial handshake and got it working! The mistake was really dumb on my part ( import { WebSocket } from './lib/websocket/websocket.js'
import { getGlobalDispatcher } from './index.js'
new WebSocket('wss://echo.websocket.events/') Anyone is free to work/contribute to my branch - help would be appreciated(!!). I'm making some progress, but there is still a lot left to do. Fetch is now integrated with the websocket spec & the initial handshake has been rewritten to follow the websocket spec where applicable. |
Hi @KhafraDev, great start! I'm really interested in working with you on this. I hope I can make some progress today; I'll try to leave some handovers in the PR comments |
Hi @KhafraDev, I was able to implement sending TEXT data and do the masking logic; we are currently able to send and receive text messages through WS:
please have a look at my PR: KhafraDev#30 |
https://fetch.spec.whatwg.org/#websocket-protocol
The text was updated successfully, but these errors were encountered: