node
node copied to clipboard
[WebSocket] Add `CloseEvent`
What is the problem this feature will solve?
In Node.js v21 with --experimental-websocket
, the CloseEvent
class isn't defined. This event is sent to clients using WebSockets when the connection is closed.
What is the feature you are proposing to solve the problem?
Add the CloseEvent
class in the global scope (behind --experimental-websocket
flags). I found it in undici but it isn't exported. Or add the CloseEvent
class next to MessageEvent
(directly in Node.js).
What alternatives have you considered?
No response
Related issues
- https://github.com/nodejs/node/issues/19308
- https://github.com/nodejs/node/issues/46880
- https://github.com/nodejs/node/pull/51594
- https://github.com/nodejs/undici/issues/2084
- https://github.com/nodejs/undici/pull/2217
- https://github.com/nodejs/undici/pull/3167
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the https://github.com/nodejs/node/labels/never-stale label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document.
CloseEvent
is part of the WebSockets specification. I think we need to keep this issue open if we want Node.js to be compliant with this specification.
@nodejs/undici
This is a actually easy to add.
once undici is updated it will be
Didnt I merge your PR @KhafraDev So it should be already part of the next release ;)
I was digging around this issue in hopes that it could be my first open source contribution. I forked the repo and cloned it on my local. Haven't really gone further than that. The IDE configs and understanding the build process is a work in progress.
After spending a good amount of time, I am having an understanding that the issue is related to code in the dep: undici. The issue suggested to either fix it there or add that event directly in here. The fix is merged in the dep repo 5 days ago. Am I correct?
Is there anything still required here in this repo? I mean as per my understanding undici implements websocket and its defined on the globalThis and if CloseEvent is now exported from there (thanks to KhafraDev), then it should be available through globalThis.WebSocket. I can even see the CloseEvent
Undici has to release a new version. Then nodejs will update the dependency. And then you have to rebase your PR.