Skip to main content

Crate konjure_web

Crate konjure_web 

Source
Expand description

§konjure-web

Konjure’s Rust browser platform adapter. It depends on konjure-sdk, without the authoring compiler or language runtime. Browser APIs live here; the SDK remains independent of the DOM, clocks, permissions, and graphics handles.

BrowserSession owns the presentation clock: typed lifecycle inputs, bounded frame steps, pause and seek, visibility, graphics context suspension, and the transition between inline and immersive rendering. This is the lifetime of a browser view, separate from resumable scene/session data. sample can feed its validated clock directly into an SDK runtime. A rejected input or frame leaves the accepted clock unchanged. Hidden inline views and lost contexts do not accumulate elapsed time; immersive views can advance while the page is hidden.

use konjure_web::{BrowserSession, FrameInput, SessionInput};

let mut session = BrowserSession::new(true);
assert_eq!(session.frame(FrameInput { timestamp_ms: 100.0 })?.time_seconds, 0.0);
assert_eq!(session.frame(FrameInput { timestamp_ms: 150.0 })?.time_seconds, 0.05);
session.apply(SessionInput::Visible(false))?;
assert!(!session.frame(FrameInput { timestamp_ms: 200.0 })?.should_render);
session.apply(SessionInput::Visible(true))?;
// Time spent hidden is not animation time.
assert_eq!(session.frame(FrameInput { timestamp_ms: 5000.0 })?.time_seconds, 0.05);

On wasm32, browser::discover_capabilities uses web-sys and wasm-bindgen to inspect the browser. It allocates a temporary WebGL 2 context and releases it when the context-loss extension is available. WebGPU means API presence, not a validated GPU adapter. XR support queries preserve failures separately from unsupported modes. They invoke neither requestSession, getUserMedia, nor a Permissions API request; browser policy may gate support queries. No result establishes room anchoring or hardware tracking quality.

The current consumer is @konjure/web: konjure-wasm exposes the platform adapter alongside low-level SDK/language exports, and generated wasm-bindgen declarations define its JavaScript types. The TypeScript package supplies DOM lifecycle wiring, accessible controls, and Three.js rendering. This crate does not implement a general UI framework, XR rendering, camera capture, audio, or browser persistence.

Run cargo nextest run -p konjure-web, cargo test -p konjure-web --doc, cargo run -p konjure-web --example lifecycle, and env RUSTFLAGS= cargo check -p konjure-web --target wasm32-unknown-unknown. Rebuild the actual web bindings with npm run sdk:wasm; npm run test:web checks the WASM lifecycle boundary. Browser validation must exercise the website separately; native tests do not prove DOM or XR availability.

Browser API references: web-sys, wasm-bindgen futures, and the WebXR support-query contract.

Modules§

browser
DOM/browser API implementation, compiled only for wasm32.

Structs§

BrowserCapabilities
Observed browser APIs and support queries, not permission grants or hardware proof.
BrowserSession
Lifecycle and clock of a browser view, independent of DOM object ownership.
FrameInput
One host-supplied animation callback timestamp, in browser milliseconds.
FrameTiming
A validated presentation time; the host owns graphics submission.

Enums§

BrowserError
Invalid browser input, or SDK evaluation failure. Inputs are transactional.
SessionInput
Explicit input from DOM controls and browser lifecycle events.