The connection read-only property of the MIDIPort interface returns the connection state of the port.
connection
MDN Reference