MIDIConnectionEvent
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
TheMIDIConnectionEvent interface of theWeb MIDI API is the event passed to thestatechange event of theMIDIAccess interface and thestatechange event of theMIDIPort interface. This occurs any time a new port becomes available, or when a previously available port becomes unavailable. For example, this event is fired whenever a MIDI device is either plugged in to or unplugged from a computer.
In this article
Constructor
MIDIConnectionEvent()Creates a new
MIDIConnectionEventobject.
Instance properties
MIDIConnectionEvent.portRead onlyReturns a reference to a
MIDIPortinstance for a port that has been connected or disconnected.
Examples
TheNavigator.requestMIDIAccess() method returns a promise that resolves with aMIDIAccess object. When a port changes state, aMIDIConnectionEvent is passed tostatechange event. Information about the port can then be printed to the console.
navigator.requestMIDIAccess().then((access) => { access.onstatechange = (event) => { console.log(event.port.name, event.port.manufacturer, event.port.state); };});Specifications
| Specification |
|---|
| Web MIDI API> # midiconnectionevent-interface> |