Rindle

API index and search · Build metadata

Source snapshot

packages/room/src/wasm.ts

Source revision 05d0bf2c2e56 · build details
Source revision: 05d0bf2c2e56.
TypeScript input SHA-256: aabe6cfcc4172b870d5e272142958e9ea8d8784c2aa23133156e5a7ee633318e
Generated 2026-09-04T23:58:25.590Z with TypeScript 6.0.3. Public TypeScript checks and declaration emit passed. Package runtime tests are separate.
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