djipco / webmidi

Tame the Web MIDI API. Send and receive MIDI messages with ease. Control instruments with user-friendly functions (playNote, sendPitchBend, etc.). React to MIDI input with simple event listeners (noteon, pitchbend, controlchange, etc.).
Apache License 2.0
1.54k stars 115 forks source link

Checking for existing Listener doesn't work #423

Closed aphleps closed 3 months ago

aphleps commented 4 months ago

Description Adding new listeners works as expected

  function noteListener(e: NoteMessageEvent) {
    console.log(e);
  }

device.addListener("noteon", noteListener)

Removing listeners also works

device.removeListener("noteon");

However, the following functions do not seem to work for me

device.hasListener("noteon", noteListener) always returns false

device.getListenerCount("noteon") always returns 0

Environment: React 18.2.0 Vite 5.0.8 webmidi 3.1.9

djipco commented 4 months ago

There are unit tests that check if hasListener() is working properly and, as far as I can tell, everything is working as it should. If you can provide a code example that reproduces this problem, that would be helpful. It would also help to know if device references an Input or an InputChannel object.