@@ -43,25 +43,22 @@ interface ImportedFFmpegCoreModuleFactory {
43
43
let ffmpeg : FFmpegCoreModule ;
44
44
45
45
const load = async ( {
46
- coreURL : _coreURL = CORE_URL ,
46
+ coreURL : _coreURL ,
47
47
wasmURL : _wasmURL ,
48
48
workerURL : _workerURL ,
49
49
} : FFMessageLoadConfig ) : Promise < IsFirst > => {
50
50
const first = ! ffmpeg ;
51
- const coreURL = _coreURL ;
52
- const wasmURL = _wasmURL ? _wasmURL : _coreURL . replace ( / .j s $ / g, ".wasm" ) ;
53
- const workerURL = _workerURL
54
- ? _workerURL
55
- : _coreURL . replace ( / .j s $ / g, ".worker.js" ) ;
56
51
57
52
try {
53
+ if ( ! _coreURL ) _coreURL = CORE_URL ;
58
54
// when web worker type is `classic`.
59
- importScripts ( coreURL ) ;
55
+ importScripts ( _coreURL ) ;
60
56
} catch {
57
+ if ( ! _coreURL ) _coreURL = CORE_URL . replace ( '/umd/' , '/esm/' ) ;
61
58
// when web worker type is `module`.
62
59
( self as WorkerGlobalScope ) . createFFmpegCore = (
63
60
( await import (
64
- /* @vite -ignore */ coreURL
61
+ /* @vite -ignore */ _coreURL
65
62
) ) as ImportedFFmpegCoreModuleFactory
66
63
) . default ;
67
64
@@ -70,6 +67,12 @@ const load = async ({
70
67
}
71
68
}
72
69
70
+ const coreURL = _coreURL ;
71
+ const wasmURL = _wasmURL ? _wasmURL : _coreURL . replace ( / .j s $ / g, ".wasm" ) ;
72
+ const workerURL = _workerURL
73
+ ? _workerURL
74
+ : _coreURL . replace ( / .j s $ / g, ".worker.js" ) ;
75
+
73
76
ffmpeg = await ( self as WorkerGlobalScope ) . createFFmpegCore ( {
74
77
// Fix `Overload resolution failed.` when using multi-threaded ffmpeg-core.
75
78
// Encoded wasmURL and workerURL in the URL as a hack to fix locateFile issue.
@@ -140,8 +143,8 @@ const deleteDir = ({ path }: FFMessageDeleteDirData): OK => {
140
143
} ;
141
144
142
145
const mount = ( { fsType, options, mountPoint } : FFMessageMountData ) : OK => {
143
- let str = fsType as keyof typeof ffmpeg . FS . filesystems ;
144
- let fs = ffmpeg . FS . filesystems [ str ] ;
146
+ const str = fsType as keyof typeof ffmpeg . FS . filesystems ;
147
+ const fs = ffmpeg . FS . filesystems [ str ] ;
145
148
if ( ! fs ) return false ;
146
149
ffmpeg . FS . mount ( fs , options , mountPoint ) ;
147
150
return true ;
0 commit comments