velxio/frontend/src/simulation
David Montero Crespo 694a2f4073 fix(frontend): polyfill crypto.randomUUID for non-secure contexts
crypto.randomUUID() is only exposed on secure contexts (HTTPS, localhost,
127.0.0.1, ::1). When Velxio is self-hosted and accessed via a LAN IP over
plain HTTP (e.g. http://192.168.31.139:3080/), crypto.randomUUID is
undefined and any code path that calls it throws TypeError.

This silently broke ESP32 simulation start for self-hosters: the frontend
generates a UUID for the WS client_id when Run is clicked; the throw
rejected the promise before reaching the WS connect, so the backend
never got the start request — no worker spawned, logs empty, simulation
"didn't start" with no visible error.

Same root cause would also break the multi-file editor (createFile,
createFileGroup) on the same LAN-HTTP self-host setup, just less
observably.

Add a single generateUUID() helper that:
  1. Uses crypto.randomUUID() when available (secure context fast path).
  2. Falls back to crypto.getRandomValues() — which IS available in
     non-secure contexts — to build a v4 UUID by hand.
  3. Final fallback to Math.random() if even that is missing
     (defensive — Web Crypto getRandomValues has been universal for
     years).

Replace all 6 crypto.randomUUID() call sites:
  - frontend/src/simulation/Esp32Bridge.ts (2 sites — getTabSessionId)
  - frontend/src/store/useEditorStore.ts   (4 sites — file IDs)

Reported by a self-hoster on OrangePi 5B accessing Velxio via LAN IP.
DevTools console showed:
  TypeError: crypto.randomUUID is not a function
    at Ph (...) at wh.connect (...) at startBoard (...)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 13:41:30 -03:00
..
customChips Add ESP32 chip demos and comprehensive tests for I2C, SPI, and UART interactions 2026-04-28 19:24:39 -03:00
cyw43 refactor: rename wokwi-libs/ → third-party/ 2026-05-03 00:58:57 -03:00
displays feat: add support for UC8159c (ACeP 7-colour) display 2026-04-30 00:27:40 -03:00
parts refactor(spi): unify SPI bus interface across all simulators 2026-05-02 22:36:29 -03:00
spice style: update ESLint rules and clean up code formatting across multiple files 2026-04-21 17:14:27 -03:00
AVRSimulator.ts Merge branch 'master' into feature/electrical-simulation-ngspice 2026-04-21 17:11:26 -03:00
Esp32Bridge.ts fix(frontend): polyfill crypto.randomUUID for non-secure contexts 2026-05-05 13:41:30 -03:00
Esp32C3Simulator.ts refactor: rename components and update prefixes to 'velxio-' for consistency 2026-04-21 16:45:45 -03:00
Esp32MicroPythonLoader.ts Add comprehensive tests for Cyw43Emulator functionality and lifecycle 2026-04-29 00:21:26 -03:00
I2CBusManager.ts refactor: rename components and update prefixes to 'velxio-' for consistency 2026-04-21 16:45:45 -03:00
Interconnect.ts feat(multi-board): add wire-aware cross-board interconnect router 2026-04-25 19:47:40 -03:00
MicroPythonLoader.ts refactor: rename components and update prefixes to 'velxio-' for consistency 2026-04-21 16:45:45 -03:00
PinManager.ts feat(multi-board): add wire-aware cross-board interconnect router 2026-04-25 19:47:40 -03:00
RP2040Simulator.ts refactor(spi): unify SPI bus interface across all simulators 2026-05-02 22:36:29 -03:00
RaspberryPi3Bridge.ts refactor: rename components and update prefixes to 'velxio-' for consistency 2026-04-21 16:45:45 -03:00
RiscVCore.ts refactor: rename components and update prefixes to 'velxio-' for consistency 2026-04-21 16:45:45 -03:00
RiscVSimulator.ts refactor: rename components and update prefixes to 'velxio-' for consistency 2026-04-21 16:45:45 -03:00
SensorUpdateRegistry.ts
SpiBus.ts refactor(spi): unify SPI bus interface across all simulators 2026-05-02 22:36:29 -03:00
rp2040-bootrom.ts
sensorControlConfig.ts feat(photodiode): add lux control in sensor panel and property dialog 2026-04-24 16:42:36 +02:00