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

WebSocketLike : Add onclose method #4725

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

FournyP
Copy link

@FournyP FournyP commented May 7, 2024

Hi everyone,

I've tried to add a onclose listener on my websocket but the interface didn't allow me.

After verifying that underlying websocket class own a onclose method I decide to make this little PR to extends the interface.

Have a nice day.

@ricmoo
Copy link
Member

ricmoo commented May 7, 2024

Unfortunately this change isn’t backwards compatible.

The goal of the interface is to specify as broad a component as necessary, so that other things that can be “shaped” like a WebSocket can be used. It wasn’t meant to expose the WebSocket for other things to consume. In future versions I can add the event listener API, but this is difficult too due to the differences between WebSocket API beyond the most lowest-common-denominator.

Ideally, NodeJS will just add WebSocket to their core API. But that might still be a ways off.

For now, I recommend casting the WebSocket to whatever your WebSocket is. Usually <WebSocket> should get you to whatever your environment’s shape is although I would say it’s better practice to add the environment-specific calls to the initial object you construct, and then pass that in to the WebSocketProvider.

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