File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,7 @@ export class Board {
167167 fs : this . fs ,
168168 conversions,
169169 noInitialRun : true ,
170+ instantiateWasm,
170171 } ) ;
171172 const module = new ModuleWrapper ( wrapped ) ;
172173 this . audio . initializeCallbacks ( {
@@ -675,3 +676,34 @@ function isFileSystem(
675676 ( [ k , v ] ) => typeof k === "string" && v instanceof Uint8Array
676677 ) ;
677678}
679+
680+ const fetchWasm = async ( ) => {
681+ const response = await fetch ( "/build/firmware.wasm" ) ;
682+ if ( ! response . ok ) {
683+ throw new Error ( response . statusText ) ;
684+ }
685+ return response . arrayBuffer ( ) ;
686+ } ;
687+
688+ const compileWasm = async ( ) => {
689+ // Can't use streaming in Safari 14 but would be nice to feature detect.
690+ return WebAssembly . compile ( new Uint8Array ( await fetchWasm ( ) ) ) ;
691+ } ;
692+
693+ let compiledWasmPromise : Promise < WebAssembly . Module > = compileWasm ( ) ;
694+
695+ const instantiateWasm = function ( imports : any , successCallback : any ) {
696+ // No easy way to communicate failure here so hard to add retries.
697+ compiledWasmPromise
698+ . then ( async ( wasmModule ) => {
699+ const instance = await WebAssembly . instantiate ( wasmModule , imports ) ;
700+ console . log ( "Woah!" ) ;
701+ successCallback ( instance ) ;
702+ } )
703+ . catch ( ( e ) => {
704+ console . error ( "Failed to instantiate WASM" ) ;
705+ console . error ( e ) ;
706+ } ) ;
707+ // Result via callback.
708+ return { } ;
709+ } ;
You can’t perform that action at this time.
0 commit comments