Skip to content

Add FluidNC WASM demo bridge support - #29

Draft
MitchBradley wants to merge 3 commits into
mainfrom
feature/wasm-demo-bridge
Draft

Add FluidNC WASM demo bridge support#29
MitchBradley wants to merge 3 commits into
mainfrom
feature/wasm-demo-bridge

Conversation

@MitchBradley

Copy link
Copy Markdown
Collaborator

Summary

Lets FigUI run against a real, compiled FluidNC instance running in WebAssembly in the browser (see FluidNC/wasm/README.md in the firmware repo), instead of only real hardware or the JS-simulated demo mode. wasmBridge/index.ts's installWasmBridgeIfActive() is called unconditionally from main.tsx (works in every build mode, including the real build:esp32 artifact) and is a no-op unless a runtime marker is present, so it's harmless in a normal deployment — the marker only gets injected when this build is loaded inside the FluidNC WASM demo's iframe.

  • wasmBridge/shimTransport.ts — low-level postMessage client talking to the demo page's ShimChannel bridge (raw Grbl-line stream + a file-op request/response RPC).
  • wasmBridge/WasmBridgeWebSocket.ts — installed as window.WebSocket so src/lib/ws.ts works unmodified.
  • wasmBridge/httpBridge.ts — intercepts fetch/XMLHttpRequest for /command, /upload, /files, etc., matching src/lib/http.ts's real endpoints.
  • wasmBridge/commandBridge.ts — request/response command sends for the HTTP-shaped surface.

Since the wasm build shares one physical channel for everything (unlike real hardware's genuinely independent HTTP and WebSocket connections), the last two commits close a couple of races that only show up in that environment:

  • JSON reassembly moved to common code: FluidNC's JSONencoder wraps JSON payloads sent over a serial-shaped channel in [JSON:...]-tagged chunks, so a payload line can't collide with the ok/error line that terminates a command. That reassembly used to be done independently in this bridge and in the equivalent bridges for two other WebUI projects (ESP3D-WEBUI, WebUI-mm) that talk to the same demo. It's now done once, by the demo page itself, before anything is ever posted here — this bridge just receives whole, already-unwrapped lines.
  • Centralized command queuing: two commands sent through the bridge at once could have their response lines cross-attributed. Fixed by queuing sends centrally on the demo side rather than per-bridge. A real bug surfaced during testing: a raw send made directly through WasmBridgeWebSocket (bypassing the old per-bridge queue) could still race a pending command and steal its ok line, so the queue now serializes all shim traffic — raw sends and RPC commands alike — not just commands against each other.
  • Real ESP800 instead of a spoofed response: the wasm build now has an actual [ESP800]json=yes handler (FluidNC/wasm/FwInfo.cpp in the firmware repo) rather than each bridge hardcoding a fake firmware-info response — parser.ts/App.tsx/http.ts updated to consume the real JSON shape.

Note for reviewers

src/lib/http.ts overlaps with e4d3cec (Serialize filesystem ops), already on main. This branch predates that commit, so it doesn't yet reflect it — both efforts independently added serialization to prevent races in their own subsystem (filesystem ops there, shim commands here), just worth being aware of when merging. The overlapping line (getDeviceInfoFast's [ESP800] command string) isn't touched by e4d3cec itself, so I don't expect a real conflict, but flagging it since I haven't rebased onto current main yet.

Test plan

  • npx tsc --noEmit clean
  • npm run build:esp32 clean
  • Verified live against the FluidNC WASM demo: boots, shows live machine status, Settings/Machine Config panels populate from real ESP400/ESP401/ESP800 data, file manager works
  • Rebase onto current main and re-verify (12 commits behind at the time of this PR)
  • Manual smoke test on real hardware to confirm the bridge is inert (marker check short-circuits) in normal operation

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 58fafb2e-370d-4f8e-ae12-5ecdb0e12a1b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant