Naturally, gdextension .wasms are side modules, while Godot itself runs as a wasm main module. My understanding is that currently, the FMOD HTML5 assumes it is always run from a main module. This means, trying to use the FMOD HTML5 wasm in a side module will not work, and one gets errors such as
Uncaught TypeError: Module.FMOD_JS_MixerFastpathFunction is not a function
What is the recommendation here? Does Godot Engine need a new way of using wasm into its main module? Is there anything that is missing from the FMOD html5 files like glue code that could help us solving this (e.g. configuring FMOD to run as side module and it somehow communicating with browser API differently)? How is this solved for Unity/Unreal engine and other engines?
I’m not sure about unreal but in Unity you use the C++ .a lib and import it as a plugin (put the .a in plugins folder). The compiler and linker links that in as part of its js/wasm creation process. So you don’t use the .js or wasm FMOD files in that case. See https://www.fmod.com/docs/2.01/api/platforms-html5.html#upstream-w32
At the moment the FMOD HTML5 wasm is built as a standalone Emscripten main module with its own JS runtime and helper functions. Godot GDExtension on the web expects .wasm extensions to be Emscripten side modules that link against Godot’s main wasm module.
Because of that mismatch, using the shipped FMOD HTML5 wasm directly as a gdextension side module isn’t supported and leads to errors like Module.FMOD_JS_MixerFastpathFunction is not a function, since the JS glue that defines those helpers isn’t present in the Godot side-module environment.
To support this properly we’d need a dedicated side-module-style FMOD build that’s designed to link into Godot’s main wasm module. The current HTML5 package doesn’t provide that, so using FMOD this way isn’t possible right now.
FMOD for HTML5 is undergoing a large overhaul right now (even the API is different and TypeScript compliant) and built a variety of ways to work in node/es6 flavours for different framework environments. It is also supporting NPM for easy package inclusion into a project.