@@ -3,13 +3,15 @@ const defaultArgs = require('./constants/defaultArgs');
3
3
const strList2ptr = require ( './utils/strList2ptr' ) ;
4
4
const getTransferables = require ( '../utils/getTransferables' ) ;
5
5
6
+ const NO_LOAD_ERROR = 'FFmpegCore is not ready, make sure you have completed Worker.load().' ;
7
+
6
8
let action = 'unknown' ;
7
9
let Module = null ;
8
10
let adapter = null ;
9
11
let ffmpeg = null ;
10
12
11
13
const load = ( { workerId, payload : { options : { corePath } } } , res ) => {
12
- if ( Module == null ) {
14
+ if ( Module === null ) {
13
15
const Core = adapter . getCore ( corePath ) ;
14
16
Core ( )
15
17
. then ( async ( _Module ) => {
@@ -33,22 +35,30 @@ const FS = ({
33
35
args,
34
36
} ,
35
37
} , res ) => {
36
- res . resolve ( {
37
- message : `Complete ${ method } ` ,
38
- data : Module . FS [ method ] ( ...args ) ,
39
- } ) ;
38
+ if ( Module === null ) {
39
+ throw NO_LOAD_ERROR ;
40
+ } else {
41
+ res . resolve ( {
42
+ message : `Complete ${ method } ` ,
43
+ data : Module . FS [ method ] ( ...args ) ,
44
+ } ) ;
45
+ }
40
46
} ;
41
47
42
48
const run = ( {
43
49
payload : {
44
50
args : _args ,
45
51
} ,
46
52
} , res ) => {
47
- const args = [ ...defaultArgs , ..._args . trim ( ) . split ( ' ' ) ] . filter ( ( s ) => s . length !== 0 ) ;
48
- ffmpeg ( args . length , strList2ptr ( Module , args ) ) ;
49
- res . resolve ( {
50
- message : `Complete ${ args . join ( ' ' ) } ` ,
51
- } ) ;
53
+ if ( Module === null ) {
54
+ throw NO_LOAD_ERROR ;
55
+ } else {
56
+ const args = [ ...defaultArgs , ..._args . trim ( ) . split ( ' ' ) ] . filter ( ( s ) => s . length !== 0 ) ;
57
+ ffmpeg ( args . length , strList2ptr ( Module , args ) ) ;
58
+ res . resolve ( {
59
+ message : `Complete ${ args . join ( ' ' ) } ` ,
60
+ } ) ;
61
+ }
52
62
} ;
53
63
54
64
exports . dispatchHandlers = ( packet , send ) => {
0 commit comments