audioview/frontend/core/static/player.js

35 lines
1.1 KiB
JavaScript

// Currently, in order to compile the player module in a way that can both
// utilize shared memory and be sent to an audio worklet, it seems necessary to
// generate JS bindings with --no-modules.
//
// https://github.com/rustwasm/wasm-bindgen/blob/master/examples/raytrace-parallel/build.sh#L18-L19
//
// Therefore, in order to import the public player API into the frontend-core
// module, we create a simple ES6 module ourselves which loads the player wasm
// module and then exports the necessary functions. These can then be imported
// into the core module using an extern "C" block.
//
// I really don't know if it's the best possible approach at this time. But it
// works!
let wasmModule;
function init() {
console.log("Loading audioview_player wasm module...");
wasm_bindgen('/wasm/audioview_player_bg.wasm')
.then(mod => wasmModule = mod)
.then(() => console.log("Loaded audioview_player wasm module successfully"))
.catch(err => console.error);
}
export function get_val() {
return wasmModule.get_val();
}
export function load_file(f) {
return wasmModule.load_file(f);
}
init();