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

Event Handlers vs. Event Listener and implicit call to open() #225

Open
padenot opened this issue Nov 29, 2021 · 4 comments
Open

Event Handlers vs. Event Listener and implicit call to open() #225

padenot opened this issue Nov 29, 2021 · 4 comments
Labels
class: substantive https://www.w3.org/2023/Process-20230612/#correction-classes status: ready for editing Enough information should be available to implement this change in the spec
Milestone

Comments

@padenot
Copy link
Member

padenot commented Nov 29, 2021

The spec currently states the following (emphasis mine):

Note that this call is NOT required in order to use the MIDIPort- calling send() on a MIDIOutput or attaching a MIDIMessageEvent handler on a MIDIInput will cause an implicit open().

This means that, if output is a MIDIOutput object, the following snippet (setting an event handler) opens the port:

output.onmidimessage = (m) => { console.log(m); }

but the following (adding an event listener) doesn't:

output.addEventListener("midimessage", () => { console.log(m); });

It seems like we need to state that both ways open the port, for Web Compat reasons.

https://html.spec.whatwg.org/multipage/webappapis.html#event-handlers
https://dom.spec.whatwg.org/#concept-event-listener

@chrisguttandin
Copy link

Without knowing this for sure I would imagine the distinction between setting an event handler and adding an event handler is made on purpose.

The description of MIDIOutput.open() is surprisingly close to the one for MessagePort.start(). Calling start() on a MessagePort is also not necessary when using onmessage. But it's necessary when adding an event handler with addEventListener().

@padenot
Copy link
Member Author

padenot commented Nov 30, 2021

Yes, but this is not what has been shipped for as long as Web MIDI has been shipped, and not doing it breaks lots of websites ("for Web Compat reasons").

@chrisguttandin
Copy link

Sorry, I misunderstood the issue. Because of the links I thought you meant onevent and addEventListener('event', ...) should generally do the same thing.

I didn't even know that start() gets called automatically in Chrome when using addEventListener(). I always did it manually. :-)

@mjwilson-google mjwilson-google added the class: substantive https://www.w3.org/2023/Process-20230612/#correction-classes label Sep 13, 2023
@mjwilson-google mjwilson-google added this to the CR milestone Sep 14, 2023
@mjwilson-google mjwilson-google added the status: needs WG review Needs to be discussed with the Audio Working Group before proceeding label Sep 30, 2023
@mjwilson-google
Copy link
Contributor

Audio Working Group 2023-10-05 meeting conclusions:

  • We should add the requirement for addEventListener as well
  • If possible, copy language directly fro the spec links in the first comment on this issue

@mjwilson-google mjwilson-google added status: ready for editing Enough information should be available to implement this change in the spec and removed status: needs WG review Needs to be discussed with the Audio Working Group before proceeding labels Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
class: substantive https://www.w3.org/2023/Process-20230612/#correction-classes status: ready for editing Enough information should be available to implement this change in the spec
Projects
None yet
Development

No branches or pull requests

3 participants