node icon indicating copy to clipboard operation
node copied to clipboard

[WebSocket] Add `CloseEvent`

Open regseb opened this issue 1 year ago • 8 comments

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

regseb avatar Oct 19 '23 10:10 regseb

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.

github-actions[bot] avatar Apr 19 '24 01:04 github-actions[bot]

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.

regseb avatar Apr 19 '24 08:04 regseb

@nodejs/undici

redyetidev avatar Apr 25 '24 22:04 redyetidev

This is a actually easy to add.

mcollina avatar Apr 26 '24 14:04 mcollina

once undici is updated it will be

KhafraDev avatar Apr 26 '24 15:04 KhafraDev

Didnt I merge your PR @KhafraDev So it should be already part of the next release ;)

Uzlopak avatar Apr 26 '24 16:04 Uzlopak

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 image

thisis-akash avatar Apr 30 '24 20:04 thisis-akash

Undici has to release a new version. Then nodejs will update the dependency. And then you have to rebase your PR.

Uzlopak avatar Apr 30 '24 21:04 Uzlopak