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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Fixed

- `load({ classWorkerURL })` works from the UMD build. It resolves the URL
against the page instead of failing with `Cannot find module`.
- The core's `setTimeout()` no longer replaces the global `setTimeout` inside
the core, which Emscripten's own timers (`poll()` and async callbacks) use.
- The core reads the `wasmURL` hash only when locating the `.wasm` file, and
Expand Down
9 changes: 8 additions & 1 deletion packages/ffmpeg/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ declare const __FFMPEG_WORKER_TYPE__: WorkerType;
const WORKER_TYPE: WorkerType =
typeof __FFMPEG_WORKER_TYPE__ === "undefined" ? "module" : __FFMPEG_WORKER_TYPE__;

// webpack turns `new URL(variable, import.meta.url)` into a module lookup, and
// the UMD build has no module URL, so it resolves against the page instead.
const resolveWorkerURL = (url: string): URL => {
const base = WORKER_TYPE === "classic" ? self.location.href : import.meta.url;
return new URL(url, base);
};

type FFMessageOptions = {
signal?: AbortSignal;
};
Expand Down Expand Up @@ -228,7 +235,7 @@ export class FFmpeg {
): Promise<IsFirst> => {
if (!this.#worker) {
this.#worker = classWorkerURL ?
new Worker(new URL(classWorkerURL, import.meta.url), {
new Worker(resolveWorkerURL(classWorkerURL), {
type: WORKER_TYPE,
}) :
// We need to duplicated the code here to enable webpack
Expand Down
Loading