fix: use ?worker&url import so Vite compiles the worklet TypeScript

new URL('./file.ts', import.meta.url) copies the file verbatim — the
browser gets raw TypeScript and addModule() throws DOMException. Using
?worker&url tells Vite to bundle and compile the file, producing a .js
output that the browser can actually execute.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mk
2026-03-24 22:03:25 -03:00
parent c42274a511
commit ea44b04bb3

View File

@@ -7,6 +7,9 @@ Please see LICENSE in the repository root for full details.
import { type Track } from "livekit-client"; import { type Track } from "livekit-client";
import { logger } from "matrix-js-sdk/lib/logger"; import { logger } from "matrix-js-sdk/lib/logger";
// ?worker&url tells Vite to compile the TypeScript worklet and return its URL.
// Without this, Vite copies the .ts file verbatim and the browser rejects it.
import compiledWorkletUrl from "./NoiseGateProcessor.worklet.ts?worker&url";
const log = logger.getChild("[NoiseGateTransformer]"); const log = logger.getChild("[NoiseGateTransformer]");
@@ -106,12 +109,8 @@ export class NoiseGateTransformer implements AudioTrackProcessor {
log.warn("TEN-VAD WASM module unavailable — VAD disabled:", e); log.warn("TEN-VAD WASM module unavailable — VAD disabled:", e);
} }
const workletUrl = new URL( log.info("loading worklet from:", compiledWorkletUrl);
"./NoiseGateProcessor.worklet.ts", await audioContext.audioWorklet.addModule(compiledWorkletUrl);
import.meta.url,
);
log.info("loading worklet from:", workletUrl.href);
await audioContext.audioWorklet.addModule(workletUrl);
log.info("worklet module loaded"); log.info("worklet module loaded");
this.workletNode = new AudioWorkletNode( this.workletNode = new AudioWorkletNode(