web api event
MIDIPort: statechange event
Secure context
The statechange event of the MIDIPort interface is fired when a port changes from open to closed, or closed to open.
Syntax
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("statechange", (event) => { })
onstatechange = (event) => { }
Event type
A MIDIConnectionEvent. Inherits from Event.
Example
In the following example the current state is logged each time it changes.
port.onstatechange = (event) => {
console.log(port.state);
};
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.