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.52k stars 115 forks source link

Add documentation re: permissions for Electron #378

Closed beaugunderson closed 10 months ago

beaugunderson commented 10 months ago

I could not initialize WebMidi in my Electron renderer process until I figured out that I needed to handle the permissions requests and checks, like so, in the main process:

  mainWindow.webContents.session.setPermissionRequestHandler((webContents, permission, callback, details) => {
    if (permission === 'midi' || permission === 'midiSysex') {
      callback(true);
    } else {
      callback(false);
    }
  })

  mainWindow.webContents.session.setPermissionCheckHandler((webContents, permission, requestingOrigin) => {
    if (permission === 'midi' || permission === 'midiSysex') {
      return true;
    }

    return false;
  });

Documenting this will save the next person some time. :)

djipco commented 10 months ago

That's a good idea. Would you be willing to update the default Electron example to include it? I added an Electron page to the documentation.

beaugunderson commented 10 months ago

Here you go! https://github.com/djipco/webmidi/pull/381

djipco commented 10 months ago

Awesome, thanks!