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

The ws module no longer exposes the standard API for onmessage/onclose events #25

Closed
ThisIsMissEm opened this issue Jun 3, 2022 · 2 comments

Comments

@ThisIsMissEm
Copy link

See: https://github.com/websockets/ws/releases/tag/8.0.0

Previously it used the same API as the client standard, but now it needs you to specifically decode messages:

websocket.on('message', function message(data, isBinary) {
  const message = isBinary ? data : data.toString();
  // Continue as before.
});
@ThisIsMissEm
Copy link
Author

Actually, looking closer, it looks like the release notes may have been slightly confusing / misleading: it seems only the events emitted are now non-standard, so on("message", (data, isBinary) => {}), but the onmessage handlers are still standard: https://github.com/websockets/ws/blob/5e4149ec6a82e0367a925881abca5667667030e9/lib/event-target.js#L193-L200

@lpinca could you confirm this API change?

@lpinca
Copy link
Contributor

lpinca commented Jun 3, 2022

Correct, and it has always been like this (even before ws@8.0.0). Only listeners added via the EventTarget interface receives "standard" Events.

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

No branches or pull requests

2 participants