Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A little problem with assigning value to 'coreURL' #602

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 15 additions & 10 deletions packages/ffmpeg/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,24 @@ interface ImportedFFmpegCoreModuleFactory {
let ffmpeg: FFmpegCoreModule;

const load = async ({
coreURL: _coreURL = CORE_URL,
coreURL: _coreURL,
wasmURL: _wasmURL,
workerURL: _workerURL,
}: FFMessageLoadConfig): Promise<IsFirst> => {
const first = !ffmpeg;
const coreURL = _coreURL;
const wasmURL = _wasmURL ? _wasmURL : _coreURL.replace(/.js$/g, ".wasm");
const workerURL = _workerURL
? _workerURL
: _coreURL.replace(/.js$/g, ".worker.js");

try {
let tempCoreURL = _coreURL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason we need to use tempCoreURL here?

if (!tempCoreURL) tempCoreURL = CORE_URL;
// when web worker type is `classic`.
importScripts(coreURL);
importScripts(tempCoreURL);
_coreURL = tempCoreURL;
} catch {
if (!_coreURL) _coreURL = CORE_URL.replace('/umd/', '/esm/');
// when web worker type is `module`.
(self as WorkerGlobalScope).createFFmpegCore = (
(await import(
/* @vite-ignore */ coreURL
/* @vite-ignore */ _coreURL
)) as ImportedFFmpegCoreModuleFactory
).default;

Expand All @@ -70,6 +69,12 @@ const load = async ({
}
}

const coreURL = _coreURL;
const wasmURL = _wasmURL ? _wasmURL : _coreURL.replace(/.js$/g, ".wasm");
const workerURL = _workerURL
? _workerURL
: _coreURL.replace(/.js$/g, ".worker.js");

ffmpeg = await (self as WorkerGlobalScope).createFFmpegCore({
// Fix `Overload resolution failed.` when using multi-threaded ffmpeg-core.
// Encoded wasmURL and workerURL in the URL as a hack to fix locateFile issue.
Expand Down Expand Up @@ -140,8 +145,8 @@ const deleteDir = ({ path }: FFMessageDeleteDirData): OK => {
};

const mount = ({ fsType, options, mountPoint }: FFMessageMountData): OK => {
let str = fsType as keyof typeof ffmpeg.FS.filesystems;
let fs = ffmpeg.FS.filesystems[str];
const str = fsType as keyof typeof ffmpeg.FS.filesystems;
const fs = ffmpeg.FS.filesystems[str];
if (!fs) return false;
ffmpeg.FS.mount(fs, options, mountPoint);
return true;
Expand Down