fix(playground/audio): compile AudioWorklet via ?worker&url
addModule() was handed new URL('./nisps-processor.ts', import.meta.url), which
Vite copies as raw TypeScript (served as video/mp2t) instead of compiling it —
that pattern only bundles for new Worker(). Import the worklet with
?worker&url so Vite emits compiled, hashed .js. Fixes the synth engine failing
to load on meml.lnfinitemonkeys.org.
This commit is contained in:
parent
3c67d86019
commit
f2562176fc
1 changed files with 9 additions and 4 deletions
|
|
@ -19,6 +19,12 @@
|
|||
|
||||
import type { EngineId } from '../ml/types';
|
||||
|
||||
// `?worker&url` makes Vite COMPILE the worklet TS→JS, bundle its imports, and
|
||||
// hand back a hashed .js URL. Plain `new URL('./x.ts', import.meta.url)` does
|
||||
// NOT work for audioWorklet.addModule (Vite only treats that as a worker entry
|
||||
// for `new Worker(...)`) — it copies raw .ts, which the browser rejects.
|
||||
import workletUrl from './worklet/nisps-processor.ts?worker&url';
|
||||
|
||||
const NISPS_WASM_URL = '/nisps.wasm';
|
||||
const PROCESSOR_NAME = 'nisps-processor';
|
||||
|
||||
|
|
@ -102,10 +108,9 @@ export class EngineHost {
|
|||
this.wasmBytes = await this.fetchWasm_();
|
||||
}
|
||||
|
||||
// Register the processor module. Vite's `new URL(..., import.meta.url)`
|
||||
// pattern bundles the worklet file correctly.
|
||||
const procUrl = this.options.processorUrl ??
|
||||
new URL('./worklet/nisps-processor.ts', import.meta.url).toString();
|
||||
// Register the processor module. `workletUrl` is the Vite-compiled,
|
||||
// bundled .js (see import note at top); addModule needs real JS, not raw TS.
|
||||
const procUrl = this.options.processorUrl ?? workletUrl;
|
||||
await this.ctx.audioWorklet.addModule(procUrl);
|
||||
|
||||
this.node = new AudioWorkletNode(this.ctx, PROCESSOR_NAME, {
|
||||
|
|
|
|||
Loading…
Reference in a new issue