File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,11 @@ class WebMidi extends EventEmitter {
218218 * @param [options.software=false] {boolean} Whether to request access to software synthesizers on
219219 * the host system. This is part of the spec but has not yet been implemented by most browsers as
220220 * of April 2020.
221+ *
222+ * @param [options.requestMIDIAccessFunction] {function} A custom function to use to return
223+ * the MIDIAccess object. This is useful if you want to use a polyfill for the Web MIDI API
224+ * or if you want to use a custom implementation of the Web MIDI API - probably for testing
225+ * purposes.
221226 *
222227 * @async
223228 *
@@ -360,9 +365,15 @@ class WebMidi extends EventEmitter {
360365
361366 // Request MIDI access (this iw where the prompt will appear)
362367 try {
363- this . interface = await navigator . requestMIDIAccess (
364- { sysex : options . sysex , software : options . software }
365- ) ;
368+ if ( typeof options . requestMIDIAccessFunction === "function" ) {
369+ this . interface = await options . requestMIDIAccessFunction (
370+ { sysex : options . sysex , software : options . software }
371+ ) ;
372+ } else {
373+ this . interface = await navigator . requestMIDIAccess (
374+ { sysex : options . sysex , software : options . software }
375+ ) ;
376+ }
366377 } catch ( err ) {
367378 errorEvent . error = err ;
368379 this . emit ( "error" , errorEvent ) ;
Original file line number Diff line number Diff line change @@ -5540,6 +5540,7 @@ declare class WebMidi extends EventEmitter {
55405540 sysex ?: boolean ;
55415541 validation ?: boolean ;
55425542 software ?: boolean ;
5543+ requestMIDIAccessFunction ?: Function ;
55435544 } ) : Promise < WebMidi > ;
55445545
55455546 /**
You can’t perform that action at this time.
0 commit comments