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