files/en-us/web/api/midiconnectionevent/index.md
{{securecontext_header}}{{APIRef("Web MIDI API")}}
The MIDIConnectionEvent interface of the Web MIDI API is the event passed to the {{domxref("MIDIAccess.statechange_event","statechange")}} event of the {{domxref("MIDIAccess")}} interface and the {{domxref("MIDIPort.statechange_event","statechange")}} event of the {{domxref("MIDIPort")}} 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.
{{InheritanceDiagram}}
MIDIConnectionEvent object.The {{domxref("Navigator.requestMIDIAccess()")}} method returns a promise that resolves with a {{domxref("MIDIAccess")}} object. When a port changes state, a MIDIConnectionEvent is passed to {{domxref("MIDIAccess.statechange_event", "statechange")}} 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}}
{{Compat}}