$ show openclaw/libopus-wasm
libopus-wasm is a TypeScript library that provides WebAssembly bindings for libopus, enabling raw Opus packet encode/decode in browsers and Node.js without native dependencies. It exposes async factories (`createEncoder`, `createDecoder`) that lazily load a single-file WASM module, returning typed handles with methods for Int16 and Float32 PCM, batch operations, packet-loss concealment, in-band FEC, and a curated CTL passthrough. The library also ships a `@discordjs/opus`-compatible adapter (`libopus-wasm/discordjs`) for drop-in replacement. The codebase is well-structured with strict validation, deterministic cleanup via `Symbol.dispose`, and comprehensive test coverage. Build scripts compile libopus from source using Emscripten with SHA-256 verification, and the documentation site is generated from Markdown by a custom static site builder. The repository is actively maintained with recent commits, CI across Node 22–26, and no open issues.
The LLM identified 2 files worth highlighting for reuse:
A self-contained Node.js script that downloads libopus 1.6.1 from Xiph.Org, verifies the tarball against a pinned SHA-256, configures and compiles it with Emscripten using `emconfigure`/`emmake`, and links the wrapper C code into a single-file ES module with inlined WASM. It demonstrates a reusable pattern for building any C library to WebAssembly with integrity verification, parallel builds, and deterministic output. The script is parameterized (opus version, cache directory, exported functions) and could be adapted for other native libraries with minimal changes.
The `WasmBuffer` class (lines ~120–140) implements a simple managed buffer pattern for WebAssembly linear memory. It lazily allocates and reuses a WASM heap buffer, growing only when a larger size is requested, and frees the old allocation. This avoids repeated malloc/free cycles for PCM and packet buffers during encode/decode operations. The pattern is isolated, has no external dependencies beyond the WASM module, and can be extracted as a utility for any project that needs efficient temporary WASM memory management.