cwilso / WebMIDIAPIShim

Polyfill using the Jazz NPAPI MIDI plugin to implement the Web MIDI API on Mac and Windows.
380 stars 53 forks source link

Broken in Chrome 33? #42

Closed bjornm closed 9 years ago

bjornm commented 10 years ago

The demo index.html works in Safari but not in 33.0.1750.70 beta.

Got it to work again by introducing window.setTimeout between creating the plugin object elements and checking for .isJazz. Maybe Chrome changed plugin initialization to a more async nature? Here's a quick-n-dirty patch, you probably want to clean it up a little bit:

diff --git a/WebMIDIAPI.js b/WebMIDIAPI.js index d06b09a..eb4ceb6 100755 --- a/WebMIDIAPI.js +++ b/WebMIDIAPI.js @@ -16,7 +16,7 @@ // Initialize the MIDI library. (function (global) { 'use strict';

@@ -78,18 +78,20 @@ document.body.appendChild(insertionPoint); } insertionPoint.appendChild(o1);

bjornm commented 10 years ago

The patch above was buggy. Here's a better one. Note that it is not possible to maintain a synchronous shim where the underlying behavior is async. It just "happens" to work as long as you do not expect the Midinput / MidiOutput to work until after a few ms. Here goes:

--- a/dartclient/web/js/WebMIDIAPI.js +++ b/dartclient/web/js/WebMIDIAPI.js @@ -16,7 +16,7 @@ // Initialize the MIDI library. (function (global) { 'use strict';

@@ -78,18 +78,29 @@ document.body.appendChild(insertionPoint); } insertionPoint.appendChild(o1);

- inputInstance.inputInUse = true;

- outputInstance.outputInUse = true;

bjornm commented 10 years ago

Sorry about the spamming - the code above looks like a mess so I sent a pull request instead.