API index and search · Build metadata
Source snapshot
packages/room/src/wasm.ts
1// Loader for the room wasm artifact (pkg/, built by ./build.sh) — the same init-once2// pattern as @rindle/wasm: a `--target web` ESM artifact needs one explicit init before3// the classes are usable. Node reads the bytes from the package; a browser/Worker host4// fetches (or passes a precompiled module).56import init, { WasmRoom } from "../pkg/rindle_room.js";78export { WasmRoom };910let initialized: Promise<void> | null = null;1112/** Initialize the room wasm module (idempotent). Call once before `WasmRoom.open`.13 * Node: bytes are read from the package. Browser/bundler: the wasm is fetched. Pass14 * `moduleOrPath` to override (a `WebAssembly.Module`, URL, or bytes). */15export function initRoomWasm(moduleOrPath?: unknown): Promise<void> {16 if (!initialized) {17 initialized = (async () => {18 if (moduleOrPath !== undefined) {19 await init({ module_or_path: moduleOrPath });20 } else if (21 (globalThis as { process?: { versions?: { node?: string } } }).process?.versions?.node22 ) {23 const { readFile } = await import("node:fs/promises");24 const bytes = await readFile(new URL("../pkg/rindle_room_bg.wasm", import.meta.url));25 await init({ module_or_path: bytes });26 } else {27 await init();28 }29 })();30 }31 return initialized;32}33