1+ import invariant from "invariant" ;
12import Module from "./raw/elementary-wasm.js" ;
23
34const EventTypes = {
@@ -44,14 +45,10 @@ class ElementaryAudioWorkletProcessor extends AudioWorkletProcessor {
4445 0 ,
4546 ) ;
4647
47- const hasProcOpts2 =
48- options . hasOwnProperty ( "processorOptions" ) &&
49- typeof options . processorOptions === "object" &&
50- options . processorOptions !== null ;
48+ const { wasmBinary, virtualFileSystem, ...other } =
49+ options . processorOptions ;
5150
52- const wasmBinary = hasProcOpts2
53- ? options . processorOptions . wasmBinary
54- : null ;
51+ invariant ( wasmBinary instanceof ArrayBuffer , "Invalid wasm binary" ) ;
5552
5653 Module ( {
5754 instantiateWasm : async function ( imports , receiveInstance ) {
@@ -78,26 +75,17 @@ class ElementaryAudioWorkletProcessor extends AudioWorkletProcessor {
7875 // See: https://webaudio.github.io/web-audio-api/#rendering-loop
7976 this . _native . prepare ( sampleRate , 128 ) ;
8077
81- const hasProcOpts =
82- options . hasOwnProperty ( "processorOptions" ) &&
83- typeof options . processorOptions === "object" &&
84- options . processorOptions !== null ;
78+ const validVFS =
79+ typeof virtualFileSystem === "object" &&
80+ virtualFileSystem !== null &&
81+ Object . keys ( virtualFileSystem ) . length > 0 ;
8582
86- if ( hasProcOpts ) {
87- const { virtualFileSystem, ...other } = options . processorOptions ;
83+ if ( validVFS ) {
84+ for ( let [ key , val ] of Object . entries ( virtualFileSystem ) ) {
85+ let result = this . _native . addSharedResource ( key , val ) ;
8886
89- const validVFS =
90- typeof virtualFileSystem === "object" &&
91- virtualFileSystem !== null &&
92- Object . keys ( virtualFileSystem ) . length > 0 ;
93-
94- if ( validVFS ) {
95- for ( let [ key , val ] of Object . entries ( virtualFileSystem ) ) {
96- let result = this . _native . addSharedResource ( key , val ) ;
97-
98- if ( ! result . success ) {
99- this . port . postMessage ( [ "error" , result . message ] ) ;
100- }
87+ if ( ! result . success ) {
88+ this . port . postMessage ( [ "error" , result . message ] ) ;
10189 }
10290 }
10391 }
0 commit comments