diff --git a/src/WebMidi.js b/src/WebMidi.js index 1a6a6ae0f..63e32af5f 100644 --- a/src/WebMidi.js +++ b/src/WebMidi.js @@ -218,6 +218,11 @@ class WebMidi extends EventEmitter { * @param [options.software=false] {boolean} Whether to request access to software synthesizers on * the host system. This is part of the spec but has not yet been implemented by most browsers as * of April 2020. + * + * @param [options.requestMIDIAccessFunction] {function} A custom function to use to return + * the MIDIAccess object. This is useful if you want to use a polyfill for the Web MIDI API + * or if you want to use a custom implementation of the Web MIDI API - probably for testing + * purposes. * * @async * @@ -360,9 +365,15 @@ class WebMidi extends EventEmitter { // Request MIDI access (this iw where the prompt will appear) try { - this.interface = await navigator.requestMIDIAccess( - {sysex: options.sysex, software: options.software} - ); + if (typeof options.requestMIDIAccessFunction === "function") { + this.interface = await options.requestMIDIAccessFunction( + {sysex: options.sysex, software: options.software} + ); + } else { + this.interface = await navigator.requestMIDIAccess( + {sysex: options.sysex, software: options.software} + ); + } } catch(err) { errorEvent.error = err; this.emit("error", errorEvent); diff --git a/typescript/webmidi.d.ts b/typescript/webmidi.d.ts index 2da52c543..e01799293 100644 --- a/typescript/webmidi.d.ts +++ b/typescript/webmidi.d.ts @@ -5570,6 +5570,7 @@ declare class WebMidi extends EventEmitter { sysex?: boolean; validation?: boolean; software?: boolean; + requestMIDIAccessFunction?: Function; }): Promise; /**