src/platforms/wasm/README.md
WebAssembly/browser platform with C++ ↔ JavaScript bridges and a pure data‑export pattern.
js_bindings.cpp: Critical C++↔JS bridge (EMSCRIPTEN_KEEPALIVE functions). Exports frame/strip/UI data as JSON and avoids embedded JS. JavaScript side handles async via modules in compiler/modules/.entry_point.cpp, timer.cpp, ui.cpp, js.cpp, fs_wasm.*, fastspi_wasm.*: WASM platform runtime and I/O.compiler/: Browser launcher and JS modules (async controller, events, graphics, UI, audio). Also includes build_flags.toml for WASM builds.FastLED WASM uses dedicated Web Workers (PROXY_TO_PTHREAD) for background execution. Asyncify was removed in 2025-01 to reduce binary size (44.4% reduction) and fix audio reactive mode issues.
WASM uses the stub platform threading profile (identical to host testing builds):
fl/stl/thread.h default logic (FASTLED_TESTING + pthread.h availability)FASTLED_MULTITHREADED=1):
fl::mutex → std::mutex (POSIX pthread mutexes via Web Workers)fl::atomic<T> → AtomicReal<T> (using __atomic compiler builtins)fl::condition_variable → std::condition_variableFASTLED_MULTITHREADED=0):
Build flags in compiler/build_flags.toml provide pthread support:
-pthread (compiler and linker)-sUSE_PTHREADS=1 (Emscripten pthread implementation)-sPROXY_TO_PTHREAD (run main() on a pthread)Design principle: WASM and stub platform share identical threading configuration, ensuring consistent behavior between WASM browser builds and desktop testing environments.
When adding or modifying C++ ↔ JS bridge functions:
compiler/modules/ consumers together.getFrameData/freeFrameData). Do not embed JS in C++; centralize browser logic under compiler/modules/.Recommended exported patterns:
extern "C" EMSCRIPTEN_KEEPALIVE const uint8_t* getFrameData(uint32_t* out_size); paired with freeFrameData(const uint8_t* ptr).const char* to a stable, heap-allocated UTF-8 string with a corresponding free.applyPendingUiJson()), and keep them non-blocking.getFrameData, freeFrameData, getStripPixelData); changes require synchronized JS updates.FASTLED_STUB_IMPL: Enables stubbed Arduino/system behaviors for WASM builds (set in led_sysdefs_wasm.h).FASTLED_MULTITHREADED: Inherits stub platform's detection (based on FASTLED_TESTING + pthread.h). Can be overridden before including FastLED.h.FASTLED_HAS_MILLIS: Default 1.FASTLED_USE_PROGMEM: Default 0.FASTLED_ALLOW_INTERRUPTS: Default 1.Define before including FastLED.h if overriding defaults.