Live-Demo im Browser vorbereitet: WebGL-Zwilling, MIME-Typen, Anleitung
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>feature/figma-frontend-js-backend
parent
7d5a952054
commit
cc5ce175bb
|
|
@ -24,3 +24,6 @@ __pycache__/
|
|||
|
||||
# WLAN-Zugangsdaten der Firmware
|
||||
firmware/**/wifi_config.h
|
||||
|
||||
# Unity-WebGL-Build (lokal erzeugt, gross)
|
||||
frontend/SmartLectureRoom-Web/
|
||||
|
|
|
|||
|
|
@ -86,6 +86,18 @@ Eingaben im Unity-HUD gehen an **dieselben Endpunkte wie beim Webinterface**: St
|
|||
```
|
||||
`sensor` hat das Format von `SensorPacket` (Wind in m/s). `sensorFelder` nennt die Felder, die das Backend kennt. Die übrigen simuliert Unity weiter, weil `JsonUtility` fehlende Felder nicht erkennt. `steuerung` hat das Format von `ArduinoBridge.BuildCommand` (`window`: closed/tilted/open, Rest 0 … 1). Die Antwort enthält keine `null`-Werte; in `manuell` bedeutet `-1` bzw. `""` Automatik. Unity schickt keine Entscheidungen zurück; ein `POST /api/steuerung` älterer Versionen wird nur gemerkt.
|
||||
|
||||
### Live-Demo im Browser (Webinterface + Zwilling für alle)
|
||||
Das Backend liefert alles unter `frontend/` aus. Mit einem Tunnel wird der Laptop unter einer öffentlichen HTTPS-Adresse erreichbar, der ESP schickt weiter lokal an den Laptop.
|
||||
|
||||
1. **Zwilling als WebGL bauen:** Unity 6 mit Modul „Web Build Support“ → File → Build Profiles → Web. Unter Publishing Settings **Compression Format = Disabled** (der Server sendet kein `Content-Encoding`). Ausgabe nach `frontend/SmartLectureRoom-Web/` (nicht in Git, siehe `.gitignore`).
|
||||
2. **Backend starten:** `backend/start.bat`.
|
||||
3. **Tunnel starten**, z. B. mit Cloudflare Quick Tunnel (kein Konto nötig): `cloudflared tunnel --url http://localhost:3000`. Die ausgegebene `https://….trycloudflare.com`-Adresse ist die Demo-Adresse.
|
||||
4. **Adressen:** Webinterface `https://<tunnel>/`, 3D-Zwilling `https://<tunnel>/SmartLectureRoom-Web/`.
|
||||
|
||||
Im Browser übernimmt der Zwilling die Adresse der Seite als Backend (`BackendLink.cs`), das Webinterface macht das ohnehin. Beide zeigen denselben Zustand. Der UDP-Modus und Seriell gibt es im Browser nicht.
|
||||
|
||||
> **Sicherheit:** Es gibt keine Anmeldung, die Rolle wird nicht geprüft. Wer die Adresse hat, kann Szenarien umschalten, den Vortragsmodus setzen und als „Dozent“ manuell steuern; alle Besucher sehen das sofort. Die Adresse nur zur Demo teilen und den Tunnel danach beenden (Strg+C).
|
||||
|
||||
## Python-Server (`server.py`)
|
||||
|
||||
> **Veraltet:** Für Webinterface und Unity-Zwilling `server.js` verwenden (`start.bat` startet inzwischen das Node-Backend). `server.py` bleibt nur als Notlösung ohne Logik.
|
||||
|
|
|
|||
|
|
@ -26,6 +26,15 @@ const MIME = {
|
|||
".css": "text/css; charset=utf-8",
|
||||
".svg": "image/svg+xml",
|
||||
".png": "image/png",
|
||||
".json": "application/json; charset=utf-8",
|
||||
".ico": "image/x-icon",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".webp": "image/webp",
|
||||
".woff2": "font/woff2",
|
||||
// Unity-WebGL-Build (unkomprimiert): .wasm muss als application/wasm kommen, sonst startet der Browser ihn nicht
|
||||
".wasm": "application/wasm",
|
||||
".data": "application/octet-stream",
|
||||
};
|
||||
|
||||
const raum = new Raum();
|
||||
|
|
|
|||
|
|
@ -139,9 +139,13 @@ namespace SmartRoom
|
|||
|
||||
void OpenUdp()
|
||||
{
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
Status = "UDP im Browser nicht verfügbar: Verbindung → Backend nutzen";
|
||||
#else
|
||||
udp = new UdpClient(udpListenPort);
|
||||
StartWorker(UdpLoop);
|
||||
Status = $"Lausche auf UDP-Port {udpListenPort}";
|
||||
#endif
|
||||
}
|
||||
|
||||
void StartWorker(ThreadStart loop)
|
||||
|
|
|
|||
|
|
@ -68,6 +68,12 @@ namespace SmartRoom
|
|||
string id = SystemInfo.deviceUniqueIdentifier;
|
||||
if (string.IsNullOrEmpty(id) || id == SystemInfo.unsupportedIdentifier) id = Guid.NewGuid().ToString("N");
|
||||
ClientId = "unity-" + id.Substring(0, Mathf.Min(12, id.Length));
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
// Im Browser läuft der Zwilling auf der Seite des Backends: dessen Adresse übernehmen, nicht "localhost".
|
||||
// Nur bei http(s); beim Öffnen per file:// bleibt die eingestellte URL.
|
||||
if (Application.absoluteURL.StartsWith("http", StringComparison.OrdinalIgnoreCase))
|
||||
serverUrl = new Uri(Application.absoluteURL).GetLeftPart(UriPartial.Authority);
|
||||
#endif
|
||||
}
|
||||
|
||||
string Base => serverUrl.TrimEnd('/');
|
||||
|
|
|
|||
Loading…
Reference in New Issue