superpoweredSDK/web-audio-javascript-webassembly-SDK-interactive-audio

superpowered.js can't be loaded in Worklet (without experimental flag)

svenoaks opened this issue · 13 comments

The only way I could get Superpowered to load in a Worklet script is to enable "Experimental Web Platform features" in Chrome, use
const fileSaveWorker = new Worker("file-saving-worker.js", { type : 'module' }); //that's what requires the flag

when creating the Worker, and add

import SuperpoweredModule from './superpowered.js'

at top of file-saving-worker-js

WIthout the flag, worker can't be loaded as module and can't load modules. Using importScripts() in the worker gives error, as does trying to pass in Superpowered instance as a message.

So, it doesn't look like Superpowered can be used in a Worker yet?

I will try checking this in this month. Did you try importScripts instead of import SuperpoweredModule?

importScripts will work if I make another copy of superpowered.js (say, superpowered-no-module.js), then importScripts('superpowered-no-module.js). In this copy I comment out the last line: export default SuperpoweredModule;

Not the most elegant solution, but I don't think it will have any bad effects for now, right?

No bad effects i guess. Does it really work that way? Because if it does, i will change superpowered.js.

If you just take out that line you can't load the module with the import statement like you are in the examples, so I have two superpowered.js files at the moment.

Removing the line and using importScripts in the Worklet with two files works in Chrome, but alas it's not working in Firefox, it gives SyntaxError: dynamic module import is not implemented. This issue needs to be reworked on Superpowered end in order to be able to use it in a Worklet.

Yes, there is another import call inside. Now i have an idea what and how to change.

Please try this. Please note you need to remove the last line (export) still.

superpowered.js.zip

It still gives

SyntaxError: dynamic module import is not implemented superpowered-no-module.js:8:828

in Firefox when I load it with importScripts in a Worklet. Made sure new file with last line removed is getting loaded.

what code is around line 8 char 828?
or can you send your project so i can debug?

Minimum project: https://github.com/svenoaks/superpowered-worklet , run it on local server or look at it https://musicspeedchanger.com/superpowered-worklet/ in Firefox.

Observed behavior in Console: "SyntaxError: dynamic module import is not implemented superpowered.js:8:828"

Expected behavior: No error

I hope final solution doesn't have to be using two superpowered.js files (one for loading it as a module and for loading as regular script)....that's kind of ugly.

Any update on this?

Test the attached test builds please and let me know.
Try superpowered-worker.js for your Worker stuff, and superpowered.js otherwise.
Archive.zip

A Worker source may look like this:

importScripts('../superpowered-worker.js');

var Superpowered = SuperpoweredModule({
    licenseKey: 'ExampleLicenseKey-WillExpire-OnNextUpdate',
    enableAudioEffects: true,
    enableAudioAnalysis: true,

    onReady: function() {
        let reverb = Superpowered.new('Reverb', 48000, 48000);
        console.log(reverb);
        console.log(reverb.wet);
        reverb.destruct();
    }
});

It works

Update is coming soon.