Fix worker import in Safari and Firefox
This commit is contained in:
parent
f22c3076df
commit
07b39072c3
2
package-lock.json
generated
2
package-lock.json
generated
@ -17569,7 +17569,7 @@
|
|||||||
},
|
},
|
||||||
"packages/ffmpeg": {
|
"packages/ffmpeg": {
|
||||||
"name": "@ffmpeg/ffmpeg",
|
"name": "@ffmpeg/ffmpeg",
|
||||||
"version": "0.12.1",
|
"version": "0.12.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ffmpeg/types": "^0.12.0"
|
"@ffmpeg/types": "^0.12.0"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ffmpeg/ffmpeg",
|
"name": "@ffmpeg/ffmpeg",
|
||||||
"version": "0.12.1",
|
"version": "0.12.2",
|
||||||
"description": "FFmpeg WebAssembly version for browser",
|
"description": "FFmpeg WebAssembly version for browser",
|
||||||
"main": "./dist/umd/ffmpeg.js",
|
"main": "./dist/umd/ffmpeg.js",
|
||||||
"types": "./dist/esm/index.d.ts",
|
"types": "./dist/esm/index.d.ts",
|
||||||
@ -17,7 +17,8 @@
|
|||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"build:esm": "tsc -p tsconfig.esm.json",
|
"build:esm": "tsc -p tsconfig.esm.json",
|
||||||
"build:umd": "webpack",
|
"build:umd": "webpack",
|
||||||
"build": "npm run clean && npm run build:esm && npm run build:umd"
|
"build": "npm run clean && npm run build:esm && npm run build:umd",
|
||||||
|
"prepublishOnly": "npm run build"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
|
@ -5,7 +5,7 @@ export const CORE_VERSION = "0.12.1";
|
|||||||
export const CORE_URL = `https://unpkg.com/@ffmpeg/core@${CORE_VERSION}/dist/umd/ffmpeg-core.js`;
|
export const CORE_URL = `https://unpkg.com/@ffmpeg/core@${CORE_VERSION}/dist/umd/ffmpeg-core.js`;
|
||||||
|
|
||||||
export enum FFMessageType {
|
export enum FFMessageType {
|
||||||
LOAD = "load",
|
LOAD = "LOAD",
|
||||||
EXEC = "EXEC",
|
EXEC = "EXEC",
|
||||||
WRITE_FILE = "WRITE_FILE",
|
WRITE_FILE = "WRITE_FILE",
|
||||||
READ_FILE = "READ_FILE",
|
READ_FILE = "READ_FILE",
|
||||||
|
@ -3,3 +3,6 @@ export const ERROR_NOT_LOADED = new Error(
|
|||||||
"ffmpeg is not loaded, call `await ffmpeg.load()` first"
|
"ffmpeg is not loaded, call `await ffmpeg.load()` first"
|
||||||
);
|
);
|
||||||
export const ERROR_TERMINATED = new Error("called FFmpeg.terminate()");
|
export const ERROR_TERMINATED = new Error("called FFmpeg.terminate()");
|
||||||
|
export const ERROR_IMPORT_FAILURE = new Error(
|
||||||
|
"failed to import ffmpeg-core.js"
|
||||||
|
);
|
||||||
|
@ -22,13 +22,6 @@ export interface FFMessageLoadConfig {
|
|||||||
* @defaultValue `https://unpkg.com/@ffmpeg/core-mt@${CORE_VERSION}/dist/umd/ffmpeg-core.worker.js`;
|
* @defaultValue `https://unpkg.com/@ffmpeg/core-mt@${CORE_VERSION}/dist/umd/ffmpeg-core.worker.js`;
|
||||||
*/
|
*/
|
||||||
workerURL?: string;
|
workerURL?: string;
|
||||||
/**
|
|
||||||
* When `thread` is true, ffmpeg imports `ffmpeg-core.worker.js` and thus
|
|
||||||
* makes multi-threaded core work.
|
|
||||||
*
|
|
||||||
* @defaultValue `false`
|
|
||||||
*/
|
|
||||||
thread?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FFMessageExecData {
|
export interface FFMessageExecData {
|
||||||
|
@ -22,7 +22,11 @@ import type {
|
|||||||
FileData,
|
FileData,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import { CORE_URL, FFMessageType } from "./const.js";
|
import { CORE_URL, FFMessageType } from "./const.js";
|
||||||
import { ERROR_UNKNOWN_MESSAGE_TYPE, ERROR_NOT_LOADED } from "./errors.js";
|
import {
|
||||||
|
ERROR_UNKNOWN_MESSAGE_TYPE,
|
||||||
|
ERROR_NOT_LOADED,
|
||||||
|
ERROR_IMPORT_FAILURE,
|
||||||
|
} from "./errors.js";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface WorkerGlobalScope {
|
interface WorkerGlobalScope {
|
||||||
@ -51,13 +55,17 @@ const load = async ({
|
|||||||
try {
|
try {
|
||||||
// when web worker type is `classic`.
|
// when web worker type is `classic`.
|
||||||
importScripts(coreURL);
|
importScripts(coreURL);
|
||||||
} catch (e: unknown) {
|
} catch {
|
||||||
// when web worker type is `module`.
|
// when web worker type is `module`.
|
||||||
if (e instanceof TypeError && e.toString().includes("Module scripts")) {
|
(self as WorkerGlobalScope).createFFmpegCore = (
|
||||||
(self as WorkerGlobalScope).createFFmpegCore = (
|
(await import(
|
||||||
(await import(coreURL)) as ImportedFFmpegCoreModuleFactory
|
/* @vite-ignore */ coreURL
|
||||||
).default;
|
)) as ImportedFFmpegCoreModuleFactory
|
||||||
} else throw e;
|
).default;
|
||||||
|
|
||||||
|
if (!(self as WorkerGlobalScope).createFFmpegCore) {
|
||||||
|
throw ERROR_IMPORT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ffmpeg = await (self as WorkerGlobalScope).createFFmpegCore({
|
ffmpeg = await (self as WorkerGlobalScope).createFFmpegCore({
|
||||||
|
@ -17,7 +17,8 @@
|
|||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"build:esm": "tsc -p tsconfig.esm.json",
|
"build:esm": "tsc -p tsconfig.esm.json",
|
||||||
"build:umd": "tsc -p tsconfig.cjs.json && webpack",
|
"build:umd": "tsc -p tsconfig.cjs.json && webpack",
|
||||||
"build": "npm run clean && npm run build:esm && npm run build:umd"
|
"build": "npm run clean && npm run build:esm && npm run build:umd",
|
||||||
|
"prepublishOnly": "npm run build"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
|
Loading…
Reference in New Issue
Block a user