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": {
 | 
			
		||||
      "name": "@ffmpeg/ffmpeg",
 | 
			
		||||
      "version": "0.12.1",
 | 
			
		||||
      "version": "0.12.2",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@ffmpeg/types": "^0.12.0"
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "@ffmpeg/ffmpeg",
 | 
			
		||||
  "version": "0.12.1",
 | 
			
		||||
  "version": "0.12.2",
 | 
			
		||||
  "description": "FFmpeg WebAssembly version for browser",
 | 
			
		||||
  "main": "./dist/umd/ffmpeg.js",
 | 
			
		||||
  "types": "./dist/esm/index.d.ts",
 | 
			
		||||
@ -17,7 +17,8 @@
 | 
			
		||||
    "clean": "rimraf dist",
 | 
			
		||||
    "build:esm": "tsc -p tsconfig.esm.json",
 | 
			
		||||
    "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": [
 | 
			
		||||
    "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 enum FFMessageType {
 | 
			
		||||
  LOAD = "load",
 | 
			
		||||
  LOAD = "LOAD",
 | 
			
		||||
  EXEC = "EXEC",
 | 
			
		||||
  WRITE_FILE = "WRITE_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"
 | 
			
		||||
);
 | 
			
		||||
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`;
 | 
			
		||||
   */
 | 
			
		||||
  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 {
 | 
			
		||||
 | 
			
		||||
@ -22,7 +22,11 @@ import type {
 | 
			
		||||
  FileData,
 | 
			
		||||
} from "./types";
 | 
			
		||||
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 {
 | 
			
		||||
  interface WorkerGlobalScope {
 | 
			
		||||
@ -51,13 +55,17 @@ const load = async ({
 | 
			
		||||
  try {
 | 
			
		||||
    // when web worker type is `classic`.
 | 
			
		||||
    importScripts(coreURL);
 | 
			
		||||
  } catch (e: unknown) {
 | 
			
		||||
  } catch {
 | 
			
		||||
    // when web worker type is `module`.
 | 
			
		||||
    if (e instanceof TypeError && e.toString().includes("Module scripts")) {
 | 
			
		||||
    (self as WorkerGlobalScope).createFFmpegCore = (
 | 
			
		||||
        (await import(coreURL)) as ImportedFFmpegCoreModuleFactory
 | 
			
		||||
      (await import(
 | 
			
		||||
        /* @vite-ignore */ coreURL
 | 
			
		||||
      )) as ImportedFFmpegCoreModuleFactory
 | 
			
		||||
    ).default;
 | 
			
		||||
    } else throw e;
 | 
			
		||||
 | 
			
		||||
    if (!(self as WorkerGlobalScope).createFFmpegCore) {
 | 
			
		||||
      throw ERROR_IMPORT_FAILURE;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ffmpeg = await (self as WorkerGlobalScope).createFFmpegCore({
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,8 @@
 | 
			
		||||
    "clean": "rimraf dist",
 | 
			
		||||
    "build:esm": "tsc -p tsconfig.esm.json",
 | 
			
		||||
    "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": [
 | 
			
		||||
    "dist"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user