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

Implement WebSocket's onMessage, onError, onOpen, onClose #23

Closed
wants to merge 1 commit into from

Conversation

olegbespalov
Copy link
Contributor

@olegbespalov olegbespalov commented Nov 16, 2022

What?

Implementing the WebSocket's on*

Build on top of the #22

Why?

Resolves #11

@olegbespalov olegbespalov self-assigned this Nov 16, 2022
Comment on lines +150 to +157
must(rt, w.obj.DefineDataProperty(
"onMessage", rt.ToValue(w.generateEventListener(MESSAGE)), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE))
must(rt, w.obj.DefineDataProperty(
"onError", rt.ToValue(w.generateEventListener(ERROR)), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE))
must(rt, w.obj.DefineDataProperty(
"onOpen", rt.ToValue(w.generateEventListener(OPEN)), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE))
must(rt, w.obj.DefineDataProperty(
"onClose", rt.ToValue(w.generateEventListener(CLOSE)), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really immediately obvious from the specification but one of the main differences between onerror and AddEventLisetner with error is that the second can add multiple while the first one can only add one eventHandler. If you set it a second time it overwrites it.

I can't find the exact place where it was also talked on which one was fired first, but we likely can not use the addEventListener underlying mechanics and instead will have to add a field to the WebSocket struct per each of those.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, now I see that. Thanks! 👍

@olegbespalov
Copy link
Contributor Author

The code will be absolutely different 🙈

@olegbespalov olegbespalov deleted the feat/on branch November 24, 2022 11:49
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