@@ -3,13 +3,15 @@ const defaultArgs = require('./constants/defaultArgs');
33const strList2ptr = require ( './utils/strList2ptr' ) ;
44const getTransferables = require ( '../utils/getTransferables' ) ;
55
6+ const NO_LOAD_ERROR = 'FFmpegCore is not ready, make sure you have completed Worker.load().' ;
7+
68let action = 'unknown' ;
79let Module = null ;
810let adapter = null ;
911let ffmpeg = null ;
1012
1113const load = ( { workerId, payload : { options : { corePath } } } , res ) => {
12- if ( Module == null ) {
14+ if ( Module === null ) {
1315 const Core = adapter . getCore ( corePath ) ;
1416 Core ( )
1517 . then ( async ( _Module ) => {
@@ -33,22 +35,30 @@ const FS = ({
3335 args,
3436 } ,
3537} , 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+ }
4046} ;
4147
4248const run = ( {
4349 payload : {
4450 args : _args ,
4551 } ,
4652} , 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+ }
5262} ;
5363
5464exports . dispatchHandlers = ( packet , send ) => {
0 commit comments