Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/WebMidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions typescript/webmidi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5570,6 +5570,7 @@ declare class WebMidi extends EventEmitter {
sysex?: boolean;
validation?: boolean;
software?: boolean;
requestMIDIAccessFunction?: Function;
}): Promise<WebMidi>;

/**
Expand Down