Hand tracking demo: MediaPipe HandLandmarker + proportional head control
Browse filesBrowser-side inference on robot's WebRTC video stream. Detects biggest hand,
computes centroid offset from center, drives robot head yaw/pitch to track it.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- hand_tracker_live_app_demo/main.py +5 -58
- hand_tracker_live_app_demo/static/index.html +0 -27
- hand_tracker_live_app_demo/static/main.js +0 -47
- hand_tracker_live_app_demo/static/style.css +0 -25
- index.html +637 -35
- style.css +345 -398
hand_tracker_live_app_demo/main.py
CHANGED
|
@@ -1,70 +1,17 @@
|
|
| 1 |
import threading
|
| 2 |
from reachy_mini import ReachyMini, ReachyMiniApp
|
| 3 |
-
from reachy_mini.utils import create_head_pose
|
| 4 |
-
import numpy as np
|
| 5 |
import time
|
| 6 |
-
from pydantic import BaseModel
|
| 7 |
|
| 8 |
|
| 9 |
class HandTrackerLiveAppDemo(ReachyMiniApp):
|
| 10 |
-
|
| 11 |
-
# eg. "http://localhost:8042"
|
| 12 |
-
custom_app_url: str | None = "http://0.0.0.0:8042"
|
| 13 |
-
# Optional: specify a media backend ("gstreamer", "gstreamer_no_video", "default", etc.)
|
| 14 |
-
# On the wireless, use gstreamer_no_video to optimise CPU usage if the app does not use video streaming
|
| 15 |
request_media_backend: str | None = None
|
| 16 |
|
| 17 |
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
antennas_enabled = True
|
| 21 |
-
sound_play_requested = False
|
| 22 |
-
|
| 23 |
-
# You can ignore this part if you don't want to add settings to your app. If you set custom_app_url to None, you have to remove this part as well.
|
| 24 |
-
# === vvv ===
|
| 25 |
-
class AntennaState(BaseModel):
|
| 26 |
-
enabled: bool
|
| 27 |
-
|
| 28 |
-
@self.settings_app.post("/antennas")
|
| 29 |
-
def update_antennas_state(state: AntennaState):
|
| 30 |
-
nonlocal antennas_enabled
|
| 31 |
-
antennas_enabled = state.enabled
|
| 32 |
-
return {"antennas_enabled": antennas_enabled}
|
| 33 |
-
|
| 34 |
-
@self.settings_app.post("/play_sound")
|
| 35 |
-
def request_sound_play():
|
| 36 |
-
nonlocal sound_play_requested
|
| 37 |
-
sound_play_requested = True
|
| 38 |
-
|
| 39 |
-
# === ^^^ ===
|
| 40 |
-
|
| 41 |
-
# Main control loop
|
| 42 |
while not stop_event.is_set():
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
yaw_deg = 30.0 * np.sin(2.0 * np.pi * 0.2 * t)
|
| 46 |
-
head_pose = create_head_pose(yaw=yaw_deg, degrees=True)
|
| 47 |
-
|
| 48 |
-
if antennas_enabled:
|
| 49 |
-
amp_deg = 25.0
|
| 50 |
-
a = amp_deg * np.sin(2.0 * np.pi * 0.5 * t)
|
| 51 |
-
antennas_deg = np.array([a, -a])
|
| 52 |
-
else:
|
| 53 |
-
antennas_deg = np.array([0.0, 0.0])
|
| 54 |
-
|
| 55 |
-
if sound_play_requested:
|
| 56 |
-
print("Playing sound...")
|
| 57 |
-
reachy_mini.media.play_sound("wake_up.wav")
|
| 58 |
-
sound_play_requested = False
|
| 59 |
-
|
| 60 |
-
antennas_rad = np.deg2rad(antennas_deg)
|
| 61 |
-
|
| 62 |
-
reachy_mini.set_target(
|
| 63 |
-
head=head_pose,
|
| 64 |
-
antennas=antennas_rad,
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
time.sleep(0.02)
|
| 68 |
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
|
@@ -72,4 +19,4 @@ if __name__ == "__main__":
|
|
| 72 |
try:
|
| 73 |
app.wrapped_run()
|
| 74 |
except KeyboardInterrupt:
|
| 75 |
-
app.stop()
|
|
|
|
| 1 |
import threading
|
| 2 |
from reachy_mini import ReachyMini, ReachyMiniApp
|
|
|
|
|
|
|
| 3 |
import time
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
class HandTrackerLiveAppDemo(ReachyMiniApp):
|
| 7 |
+
custom_app_url: str | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
request_media_backend: str | None = None
|
| 9 |
|
| 10 |
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 11 |
+
# All head control is handled by the browser via WebRTC data channel.
|
| 12 |
+
# This loop just keeps the app alive.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
while not stop_event.is_set():
|
| 14 |
+
time.sleep(0.1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
if __name__ == "__main__":
|
|
|
|
| 19 |
try:
|
| 20 |
app.wrapped_run()
|
| 21 |
except KeyboardInterrupt:
|
| 22 |
+
app.stop()
|
hand_tracker_live_app_demo/static/index.html
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
|
| 4 |
-
<head>
|
| 5 |
-
<meta charset="UTF-8">
|
| 6 |
-
<title>Reachy Mini example app template</title>
|
| 7 |
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 8 |
-
<link rel="stylesheet" href="/static/style.css">
|
| 9 |
-
</head>
|
| 10 |
-
|
| 11 |
-
<body>
|
| 12 |
-
<h1>Reachy Mini – Control Panel</h1>
|
| 13 |
-
|
| 14 |
-
<div id="controls">
|
| 15 |
-
<label style="display:flex; align-items:center; gap:8px;">
|
| 16 |
-
<input type="checkbox" id="antenna-checkbox" checked>
|
| 17 |
-
Antennas
|
| 18 |
-
</label>
|
| 19 |
-
|
| 20 |
-
<button id="sound-btn">Play Sound</button>
|
| 21 |
-
</div>
|
| 22 |
-
|
| 23 |
-
<div id="status">Antennas status: running</div>
|
| 24 |
-
<script src="/static/main.js"></script>
|
| 25 |
-
</body>
|
| 26 |
-
|
| 27 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hand_tracker_live_app_demo/static/main.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
| 1 |
-
let antennasEnabled = true;
|
| 2 |
-
|
| 3 |
-
async function updateAntennasState(enabled) {
|
| 4 |
-
try {
|
| 5 |
-
const resp = await fetch("/antennas", {
|
| 6 |
-
method: "POST",
|
| 7 |
-
headers: { "Content-Type": "application/json" },
|
| 8 |
-
body: JSON.stringify({ enabled }),
|
| 9 |
-
});
|
| 10 |
-
const data = await resp.json();
|
| 11 |
-
antennasEnabled = data.antennas_enabled;
|
| 12 |
-
updateUI();
|
| 13 |
-
} catch (e) {
|
| 14 |
-
document.getElementById("status").textContent = "Backend error";
|
| 15 |
-
}
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
async function playSound() {
|
| 19 |
-
try {
|
| 20 |
-
await fetch("/play_sound", { method: "POST" });
|
| 21 |
-
} catch (e) {
|
| 22 |
-
console.error("Error triggering sound:", e);
|
| 23 |
-
}
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
function updateUI() {
|
| 27 |
-
const checkbox = document.getElementById("antenna-checkbox");
|
| 28 |
-
const status = document.getElementById("status");
|
| 29 |
-
|
| 30 |
-
checkbox.checked = antennasEnabled;
|
| 31 |
-
|
| 32 |
-
if (antennasEnabled) {
|
| 33 |
-
status.textContent = "Antennas status: running";
|
| 34 |
-
} else {
|
| 35 |
-
status.textContent = "Antennas status: stopped";
|
| 36 |
-
}
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
document.getElementById("antenna-checkbox").addEventListener("change", (e) => {
|
| 40 |
-
updateAntennasState(e.target.checked);
|
| 41 |
-
});
|
| 42 |
-
|
| 43 |
-
document.getElementById("sound-btn").addEventListener("click", () => {
|
| 44 |
-
playSound();
|
| 45 |
-
});
|
| 46 |
-
|
| 47 |
-
updateUI();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hand_tracker_live_app_demo/static/style.css
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
body {
|
| 2 |
-
font-family: sans-serif;
|
| 3 |
-
margin: 24px;
|
| 4 |
-
}
|
| 5 |
-
|
| 6 |
-
#sound-btn {
|
| 7 |
-
padding: 10px 20px;
|
| 8 |
-
border: none;
|
| 9 |
-
color: white;
|
| 10 |
-
cursor: pointer;
|
| 11 |
-
font-size: 16px;
|
| 12 |
-
border-radius: 6px;
|
| 13 |
-
background-color: #3498db;
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
#status {
|
| 17 |
-
margin-top: 16px;
|
| 18 |
-
font-weight: bold;
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
#controls {
|
| 22 |
-
display: flex;
|
| 23 |
-
align-items: center;
|
| 24 |
-
gap: 20px;
|
| 25 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
index.html
CHANGED
|
@@ -1,40 +1,642 @@
|
|
| 1 |
<!doctype html>
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
<head>
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
</head>
|
| 10 |
-
|
| 11 |
<body>
|
| 12 |
-
<div class="hero">
|
| 13 |
-
<div class="hero-content">
|
| 14 |
-
<div class="app-icon">🤖⚡</div>
|
| 15 |
-
<h1> Hand Tracker Live App Demo </h1>
|
| 16 |
-
<p class="tagline">Enter your tagline here</p>
|
| 17 |
-
</div>
|
| 18 |
-
</div>
|
| 19 |
-
|
| 20 |
-
<div class="container">
|
| 21 |
-
<div class="main-card">
|
| 22 |
-
<div class="app-preview">
|
| 23 |
-
<div class="preview-image">
|
| 24 |
-
<div class="camera-feed">🛠️</div>
|
| 25 |
-
</div>
|
| 26 |
-
</div>
|
| 27 |
-
</div>
|
| 28 |
-
</div>
|
| 29 |
-
|
| 30 |
-
<div class="footer">
|
| 31 |
-
<p>
|
| 32 |
-
🤖 Hand Tracker Live App Demo •
|
| 33 |
-
<a href="https://github.com/pollen-robotics" target="_blank">Pollen Robotics</a> •
|
| 34 |
-
<a href="https://huggingface.co/spaces/pollen-robotics/reachy-mini-landing-page#apps" target="_blank">Browse More
|
| 35 |
-
Apps</a>
|
| 36 |
-
</p>
|
| 37 |
-
</div>
|
| 38 |
-
</body>
|
| 39 |
|
| 40 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
+
<html lang="en">
|
|
|
|
| 3 |
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
|
| 6 |
+
<title>Hand Tracker - Reachy Mini</title>
|
| 7 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 8 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 10 |
+
<link rel="stylesheet" href="style.css">
|
| 11 |
</head>
|
|
|
|
| 12 |
<body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
<!-- Login -->
|
| 15 |
+
<div id="loginView" class="login-view">
|
| 16 |
+
<div class="login-card">
|
| 17 |
+
<h2>Hand Tracker</h2>
|
| 18 |
+
<p>Track your hand with Reachy Mini's camera — inference runs in your browser.</p>
|
| 19 |
+
<button class="btn-hf" id="loginBtn">
|
| 20 |
+
<svg width="16" height="16" viewBox="0 0 95 88" fill="currentColor">
|
| 21 |
+
<path d="M47.5 0C26.3 0 9.1 17.2 9.1 38.4v2.9c0 4.5 1.1 9 3.2 13L0 88h95L82.7 54.3c2.1-4 3.2-8.5 3.2-13v-2.9C85.9 17.2 68.7 0 47.5 0z"/>
|
| 22 |
+
</svg>
|
| 23 |
+
Sign in with Hugging Face
|
| 24 |
+
</button>
|
| 25 |
+
</div>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
<!-- App -->
|
| 29 |
+
<div id="appView" class="hidden" style="display:none; flex-direction:column; height:100vh;">
|
| 30 |
+
<header>
|
| 31 |
+
<div class="brand">Hand Tracker <span>Reachy Mini</span></div>
|
| 32 |
+
<div class="user-info">
|
| 33 |
+
<span id="username"></span>
|
| 34 |
+
<button class="btn-logout" id="logoutBtn">Sign out</button>
|
| 35 |
+
</div>
|
| 36 |
+
</header>
|
| 37 |
+
|
| 38 |
+
<main>
|
| 39 |
+
<div class="video-container">
|
| 40 |
+
<video id="video" autoplay playsinline muted></video>
|
| 41 |
+
<canvas id="overlay"></canvas>
|
| 42 |
+
|
| 43 |
+
<div class="hud">
|
| 44 |
+
<div class="hud-top">
|
| 45 |
+
<div class="badge-group">
|
| 46 |
+
<div class="badge status-disconnected" id="statusBadge">Disconnected</div>
|
| 47 |
+
<div class="badge hidden" id="latencyBadge">--</div>
|
| 48 |
+
</div>
|
| 49 |
+
<div class="badge-group">
|
| 50 |
+
<div class="badge hidden" id="fpsBadge">-- fps</div>
|
| 51 |
+
</div>
|
| 52 |
+
</div>
|
| 53 |
+
<div class="hud-bottom">
|
| 54 |
+
<div class="badge tracking-disabled hidden" id="trackBadge">Tracking off</div>
|
| 55 |
+
<div class="badge hidden" id="headBadge">Y:0 P:0</div>
|
| 56 |
+
</div>
|
| 57 |
+
</div>
|
| 58 |
+
|
| 59 |
+
<div class="model-loading hidden" id="modelLoading">
|
| 60 |
+
<div class="spinner"></div>
|
| 61 |
+
Loading hand detection model...
|
| 62 |
+
</div>
|
| 63 |
+
</div>
|
| 64 |
+
|
| 65 |
+
<div class="controls">
|
| 66 |
+
<button class="btn btn-connect" id="connectBtn">Connect</button>
|
| 67 |
+
<select id="robotList" class="hidden">
|
| 68 |
+
<option value="">Select robot...</option>
|
| 69 |
+
</select>
|
| 70 |
+
<button class="btn btn-start" id="startBtn" disabled>Start</button>
|
| 71 |
+
<button class="btn btn-stop" id="stopBtn" disabled>Stop</button>
|
| 72 |
+
|
| 73 |
+
<div class="spacer"></div>
|
| 74 |
+
|
| 75 |
+
<label class="toggle">
|
| 76 |
+
<input type="checkbox" id="trackingToggle" checked>
|
| 77 |
+
<span>Track</span>
|
| 78 |
+
</label>
|
| 79 |
+
|
| 80 |
+
<button class="btn-tune" id="tuneBtn">Tune</button>
|
| 81 |
+
</div>
|
| 82 |
+
|
| 83 |
+
<div class="tuning hidden" id="tuningPanel">
|
| 84 |
+
<label>
|
| 85 |
+
Gain
|
| 86 |
+
<input type="range" id="gainSlider" min="5" max="150" value="60">
|
| 87 |
+
<span class="value" id="gainVal">60</span>
|
| 88 |
+
</label>
|
| 89 |
+
<label>
|
| 90 |
+
Smooth
|
| 91 |
+
<input type="range" id="smoothSlider" min="0" max="95" value="60">
|
| 92 |
+
<span class="value" id="smoothVal">0.60</span>
|
| 93 |
+
</label>
|
| 94 |
+
<label>
|
| 95 |
+
Dead
|
| 96 |
+
<input type="range" id="dzSlider" min="0" max="15" value="3">
|
| 97 |
+
<span class="value" id="dzVal">0.03</span>
|
| 98 |
+
</label>
|
| 99 |
+
</div>
|
| 100 |
+
</main>
|
| 101 |
+
</div>
|
| 102 |
+
|
| 103 |
+
<script type="module">
|
| 104 |
+
import { ReachyMini } from "https://cdn.jsdelivr.net/gh/pollen-robotics/reachy_mini@fix/js-app-latency/js/reachy-mini.js";
|
| 105 |
+
import { HandLandmarker, FilesetResolver } from "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.14/vision_bundle.mjs";
|
| 106 |
+
|
| 107 |
+
// ─── Hand skeleton connections ───
|
| 108 |
+
const CONNECTIONS = [
|
| 109 |
+
[0,1],[1,2],[2,3],[3,4],
|
| 110 |
+
[5,6],[6,7],[7,8],
|
| 111 |
+
[9,10],[10,11],[11,12],
|
| 112 |
+
[13,14],[14,15],[15,16],
|
| 113 |
+
[17,18],[18,19],[19,20],
|
| 114 |
+
[0,5],[5,9],[9,13],[13,17],[0,17],
|
| 115 |
+
];
|
| 116 |
+
|
| 117 |
+
// ─── State ───
|
| 118 |
+
const robot = new ReachyMini({ enableMicrophone: false });
|
| 119 |
+
let detector = null;
|
| 120 |
+
let detachVideo = null;
|
| 121 |
+
let selectedRobotId = null;
|
| 122 |
+
|
| 123 |
+
// Tracking state
|
| 124 |
+
let trackingEnabled = true;
|
| 125 |
+
let smoothX = 0.5, smoothY = 0.5;
|
| 126 |
+
let currentYaw = 0, currentPitch = 0;
|
| 127 |
+
let lastCmdTime = 0;
|
| 128 |
+
let lastFrameTime = 0;
|
| 129 |
+
let lastDetectTs = -1;
|
| 130 |
+
let frameCount = 0;
|
| 131 |
+
let fpsTime = 0;
|
| 132 |
+
let currentFps = 0;
|
| 133 |
+
let noHandFrames = 0;
|
| 134 |
+
let latencyPending = false;
|
| 135 |
+
let lastLatencyTime = 0;
|
| 136 |
+
const NO_HAND_RETURN_THRESHOLD = 60; // frames before returning to center
|
| 137 |
+
|
| 138 |
+
// Tuning params
|
| 139 |
+
let gain = 60;
|
| 140 |
+
let smoothing = 0.60;
|
| 141 |
+
let deadzone = 0.03;
|
| 142 |
+
const CMD_INTERVAL = 50; // ms (20 Hz)
|
| 143 |
+
|
| 144 |
+
// DOM refs
|
| 145 |
+
const $ = (id) => document.getElementById(id);
|
| 146 |
+
const video = $('video');
|
| 147 |
+
const canvas = $('overlay');
|
| 148 |
+
const ctx = canvas.getContext('2d');
|
| 149 |
+
|
| 150 |
+
// ─── Init ───
|
| 151 |
+
document.addEventListener('DOMContentLoaded', async () => {
|
| 152 |
+
if (await robot.authenticate()) {
|
| 153 |
+
showApp();
|
| 154 |
+
}
|
| 155 |
+
initEvents();
|
| 156 |
+
initTuning();
|
| 157 |
+
});
|
| 158 |
+
|
| 159 |
+
// ─── Auth ───
|
| 160 |
+
$('loginBtn').onclick = () => robot.login();
|
| 161 |
+
$('logoutBtn').onclick = () => {
|
| 162 |
+
if (detachVideo) { detachVideo(); detachVideo = null; }
|
| 163 |
+
robot.logout();
|
| 164 |
+
$('appView').style.display = 'none';
|
| 165 |
+
$('loginView').style.display = '';
|
| 166 |
+
};
|
| 167 |
+
|
| 168 |
+
function showApp() {
|
| 169 |
+
$('loginView').style.display = 'none';
|
| 170 |
+
$('appView').style.display = 'flex';
|
| 171 |
+
$('username').textContent = '@' + robot.username;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
// ─── Robot events ───
|
| 175 |
+
function initEvents() {
|
| 176 |
+
robot.addEventListener('robotsChanged', (e) => {
|
| 177 |
+
const sel = $('robotList');
|
| 178 |
+
sel.innerHTML = '<option value="">Select robot...</option>';
|
| 179 |
+
for (const r of e.detail.robots) {
|
| 180 |
+
const opt = document.createElement('option');
|
| 181 |
+
opt.value = r.id;
|
| 182 |
+
opt.textContent = r.meta?.name || r.id.slice(0, 12);
|
| 183 |
+
sel.appendChild(opt);
|
| 184 |
+
}
|
| 185 |
+
sel.classList.remove('hidden');
|
| 186 |
+
});
|
| 187 |
+
|
| 188 |
+
$('robotList').onchange = (e) => {
|
| 189 |
+
selectedRobotId = e.target.value || null;
|
| 190 |
+
$('startBtn').disabled = !selectedRobotId;
|
| 191 |
+
};
|
| 192 |
+
|
| 193 |
+
robot.addEventListener('streaming', () => {
|
| 194 |
+
setStatus('streaming', 'Streaming');
|
| 195 |
+
$('startBtn').disabled = true;
|
| 196 |
+
$('stopBtn').disabled = false;
|
| 197 |
+
$('robotList').disabled = true;
|
| 198 |
+
showTrackingHud();
|
| 199 |
+
initDetector();
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
+
robot.addEventListener('sessionStopped', () => {
|
| 203 |
+
setStatus('connected', 'Connected');
|
| 204 |
+
$('startBtn').disabled = !selectedRobotId;
|
| 205 |
+
$('stopBtn').disabled = true;
|
| 206 |
+
$('robotList').disabled = false;
|
| 207 |
+
hideTrackingHud();
|
| 208 |
+
clearCanvas();
|
| 209 |
+
resetTrackingState();
|
| 210 |
+
});
|
| 211 |
+
|
| 212 |
+
robot.addEventListener('disconnected', () => {
|
| 213 |
+
setStatus('disconnected', 'Disconnected');
|
| 214 |
+
$('connectBtn').disabled = false;
|
| 215 |
+
$('startBtn').disabled = true;
|
| 216 |
+
$('stopBtn').disabled = true;
|
| 217 |
+
$('robotList').classList.add('hidden');
|
| 218 |
+
$('robotList').disabled = false;
|
| 219 |
+
hideTrackingHud();
|
| 220 |
+
clearCanvas();
|
| 221 |
+
});
|
| 222 |
+
|
| 223 |
+
robot.addEventListener('error', (e) => {
|
| 224 |
+
console.error(`[${e.detail.source}]`, e.detail.error);
|
| 225 |
+
});
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
// ─── Connection ───
|
| 229 |
+
$('connectBtn').onclick = async () => {
|
| 230 |
+
$('connectBtn').disabled = true;
|
| 231 |
+
setStatus('connecting', 'Connecting...');
|
| 232 |
+
try {
|
| 233 |
+
await robot.connect();
|
| 234 |
+
setStatus('connected', 'Connected');
|
| 235 |
+
} catch (e) {
|
| 236 |
+
console.error('Connect failed:', e);
|
| 237 |
+
setStatus('disconnected', 'Disconnected');
|
| 238 |
+
$('connectBtn').disabled = false;
|
| 239 |
+
}
|
| 240 |
+
};
|
| 241 |
+
|
| 242 |
+
$('startBtn').onclick = async () => {
|
| 243 |
+
if (!selectedRobotId) return;
|
| 244 |
+
setStatus('connecting', 'Starting...');
|
| 245 |
+
detachVideo = robot.attachVideo(video);
|
| 246 |
+
$('startBtn').disabled = true;
|
| 247 |
+
$('stopBtn').disabled = false;
|
| 248 |
+
try {
|
| 249 |
+
await robot.startSession(selectedRobotId);
|
| 250 |
+
} catch (e) {
|
| 251 |
+
console.error('Session failed:', e);
|
| 252 |
+
if (detachVideo) { detachVideo(); detachVideo = null; }
|
| 253 |
+
$('startBtn').disabled = !selectedRobotId;
|
| 254 |
+
$('stopBtn').disabled = true;
|
| 255 |
+
setStatus('connected', 'Connected');
|
| 256 |
+
}
|
| 257 |
+
};
|
| 258 |
+
|
| 259 |
+
$('stopBtn').onclick = async () => {
|
| 260 |
+
if (detachVideo) { detachVideo(); detachVideo = null; }
|
| 261 |
+
await robot.stopSession();
|
| 262 |
+
};
|
| 263 |
+
|
| 264 |
+
// ─── Status helpers ───
|
| 265 |
+
function setStatus(state, text) {
|
| 266 |
+
const b = $('statusBadge');
|
| 267 |
+
b.className = 'badge status-' + state;
|
| 268 |
+
b.textContent = text;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
function showTrackingHud() {
|
| 272 |
+
$('fpsBadge').classList.remove('hidden');
|
| 273 |
+
$('trackBadge').classList.remove('hidden');
|
| 274 |
+
$('headBadge').classList.remove('hidden');
|
| 275 |
+
$('latencyBadge').classList.remove('hidden');
|
| 276 |
+
updateTrackBadge();
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
function hideTrackingHud() {
|
| 280 |
+
$('fpsBadge').classList.add('hidden');
|
| 281 |
+
$('trackBadge').classList.add('hidden');
|
| 282 |
+
$('headBadge').classList.add('hidden');
|
| 283 |
+
$('latencyBadge').classList.add('hidden');
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
function updateTrackBadge() {
|
| 287 |
+
const b = $('trackBadge');
|
| 288 |
+
if (!trackingEnabled) {
|
| 289 |
+
b.className = 'badge tracking-disabled';
|
| 290 |
+
b.textContent = 'Tracking off';
|
| 291 |
+
} else if (noHandFrames > 10) {
|
| 292 |
+
b.className = 'badge tracking-searching';
|
| 293 |
+
b.textContent = 'Searching...';
|
| 294 |
+
} else {
|
| 295 |
+
b.className = 'badge tracking-active';
|
| 296 |
+
b.textContent = 'Tracking';
|
| 297 |
+
}
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
// ─── Tracking toggle ───
|
| 301 |
+
$('trackingToggle').onchange = (e) => {
|
| 302 |
+
trackingEnabled = e.target.checked;
|
| 303 |
+
if (trackingEnabled) {
|
| 304 |
+
smoothX = 0.5;
|
| 305 |
+
smoothY = 0.5;
|
| 306 |
+
}
|
| 307 |
+
updateTrackBadge();
|
| 308 |
+
if (!trackingEnabled) {
|
| 309 |
+
clearCanvas();
|
| 310 |
+
}
|
| 311 |
+
};
|
| 312 |
+
|
| 313 |
+
// ─── Tuning ───
|
| 314 |
+
$('tuneBtn').onclick = () => {
|
| 315 |
+
$('tuningPanel').classList.toggle('hidden');
|
| 316 |
+
};
|
| 317 |
+
|
| 318 |
+
function initTuning() {
|
| 319 |
+
const gs = $('gainSlider'), ss = $('smoothSlider'), ds = $('dzSlider');
|
| 320 |
+
gs.oninput = () => { gain = +gs.value; $('gainVal').textContent = gain; };
|
| 321 |
+
ss.oninput = () => { smoothing = +ss.value / 100; $('smoothVal').textContent = smoothing.toFixed(2); };
|
| 322 |
+
ds.oninput = () => { deadzone = +ds.value / 100; $('dzVal').textContent = deadzone.toFixed(2); };
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
// ─── MediaPipe detector ───
|
| 326 |
+
async function initDetector() {
|
| 327 |
+
if (detector) {
|
| 328 |
+
startTracking();
|
| 329 |
+
return;
|
| 330 |
+
}
|
| 331 |
+
$('modelLoading').classList.remove('hidden');
|
| 332 |
+
try {
|
| 333 |
+
const vision = await FilesetResolver.forVisionTasks(
|
| 334 |
+
"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.14/wasm"
|
| 335 |
+
);
|
| 336 |
+
detector = await HandLandmarker.createFromOptions(vision, {
|
| 337 |
+
baseOptions: {
|
| 338 |
+
modelAssetPath: "https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/latest/hand_landmarker.task",
|
| 339 |
+
delegate: "GPU",
|
| 340 |
+
},
|
| 341 |
+
runningMode: "VIDEO",
|
| 342 |
+
numHands: 2,
|
| 343 |
+
});
|
| 344 |
+
console.log("Hand detector ready");
|
| 345 |
+
} catch (e) {
|
| 346 |
+
console.error("Failed to load hand detector:", e);
|
| 347 |
+
$('modelLoading').innerHTML = 'Failed to load model<br><button onclick="this.parentElement.classList.add(\'hidden\'); initDetector();" style="margin-top:0.5rem; padding:0.4rem 1rem; border-radius:6px; border:none; cursor:pointer;">Retry</button>';
|
| 348 |
+
startTracking(); // still run frame loop for video display
|
| 349 |
+
return;
|
| 350 |
+
}
|
| 351 |
+
$('modelLoading').classList.add('hidden');
|
| 352 |
+
startTracking();
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
// ─── Frame processing loop ───
|
| 356 |
+
function startTracking() {
|
| 357 |
+
frameCount = 0;
|
| 358 |
+
fpsTime = performance.now();
|
| 359 |
+
lastFrameTime = 0;
|
| 360 |
+
scheduleFrame();
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
function scheduleFrame() {
|
| 364 |
+
if (robot.state !== 'streaming') return;
|
| 365 |
+
if ('requestVideoFrameCallback' in video) {
|
| 366 |
+
video.requestVideoFrameCallback(onFrame);
|
| 367 |
+
} else {
|
| 368 |
+
requestAnimationFrame(onFrameFallback);
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
function onFrame(now, metadata) {
|
| 373 |
+
processFrame(now);
|
| 374 |
+
scheduleFrame();
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
function onFrameFallback(now) {
|
| 378 |
+
processFrame(now);
|
| 379 |
+
scheduleFrame();
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
function syncCanvasToVideo() {
|
| 383 |
+
if (!video.videoWidth || !video.videoHeight) return;
|
| 384 |
+
const cw = video.clientWidth;
|
| 385 |
+
const ch = video.clientHeight;
|
| 386 |
+
const vw = video.videoWidth;
|
| 387 |
+
const vh = video.videoHeight;
|
| 388 |
+
const videoAR = vw / vh;
|
| 389 |
+
const containerAR = cw / ch;
|
| 390 |
+
let rw, rh, ox, oy;
|
| 391 |
+
if (containerAR > videoAR) {
|
| 392 |
+
rh = ch;
|
| 393 |
+
rw = ch * videoAR;
|
| 394 |
+
} else {
|
| 395 |
+
rw = cw;
|
| 396 |
+
rh = cw / videoAR;
|
| 397 |
+
}
|
| 398 |
+
ox = (cw - rw) / 2;
|
| 399 |
+
oy = (ch - rh) / 2;
|
| 400 |
+
canvas.style.left = ox + 'px';
|
| 401 |
+
canvas.style.top = oy + 'px';
|
| 402 |
+
canvas.style.width = rw + 'px';
|
| 403 |
+
canvas.style.height = rh + 'px';
|
| 404 |
+
if (canvas.width !== vw || canvas.height !== vh) {
|
| 405 |
+
canvas.width = vw;
|
| 406 |
+
canvas.height = vh;
|
| 407 |
+
}
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
function processFrame(now) {
|
| 411 |
+
if (robot.state !== 'streaming') return;
|
| 412 |
+
if (video.readyState < 2) return;
|
| 413 |
+
|
| 414 |
+
syncCanvasToVideo();
|
| 415 |
+
|
| 416 |
+
// FPS counter
|
| 417 |
+
frameCount++;
|
| 418 |
+
const elapsed = now - fpsTime;
|
| 419 |
+
if (elapsed >= 1000) {
|
| 420 |
+
currentFps = Math.round(frameCount * 1000 / elapsed);
|
| 421 |
+
$('fpsBadge').textContent = currentFps + ' fps';
|
| 422 |
+
frameCount = 0;
|
| 423 |
+
fpsTime = now;
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
// Run detection (guard: timestamp must be strictly increasing)
|
| 427 |
+
let results = null;
|
| 428 |
+
if (detector && trackingEnabled && now > lastDetectTs) {
|
| 429 |
+
try {
|
| 430 |
+
results = detector.detectForVideo(video, now);
|
| 431 |
+
lastDetectTs = now;
|
| 432 |
+
} catch (e) {
|
| 433 |
+
// Timestamp errors can happen on seek; ignore
|
| 434 |
+
}
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
// Clear canvas
|
| 438 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 439 |
+
|
| 440 |
+
if (!trackingEnabled) {
|
| 441 |
+
return;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
const w = canvas.width;
|
| 445 |
+
const h = canvas.height;
|
| 446 |
+
|
| 447 |
+
// Draw center crosshair
|
| 448 |
+
drawCrosshair(w, h);
|
| 449 |
+
|
| 450 |
+
if (results && results.landmarks && results.landmarks.length > 0) {
|
| 451 |
+
noHandFrames = 0;
|
| 452 |
+
|
| 453 |
+
// Find biggest hand by bounding box area
|
| 454 |
+
let bestIdx = 0;
|
| 455 |
+
let bestArea = 0;
|
| 456 |
+
for (let i = 0; i < results.landmarks.length; i++) {
|
| 457 |
+
const lm = results.landmarks[i];
|
| 458 |
+
let minX = 1, maxX = 0, minY = 1, maxY = 0;
|
| 459 |
+
for (const p of lm) {
|
| 460 |
+
if (p.x < minX) minX = p.x;
|
| 461 |
+
if (p.x > maxX) maxX = p.x;
|
| 462 |
+
if (p.y < minY) minY = p.y;
|
| 463 |
+
if (p.y > maxY) maxY = p.y;
|
| 464 |
+
}
|
| 465 |
+
const area = (maxX - minX) * (maxY - minY);
|
| 466 |
+
if (area > bestArea) {
|
| 467 |
+
bestArea = area;
|
| 468 |
+
bestIdx = i;
|
| 469 |
+
}
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
const hand = results.landmarks[bestIdx];
|
| 473 |
+
|
| 474 |
+
// Draw all hands (dimmed)
|
| 475 |
+
for (let i = 0; i < results.landmarks.length; i++) {
|
| 476 |
+
drawHand(results.landmarks[i], w, h, i === bestIdx);
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
// Compute centroid of tracked hand
|
| 480 |
+
let cx = 0, cy = 0;
|
| 481 |
+
for (const p of hand) {
|
| 482 |
+
cx += p.x;
|
| 483 |
+
cy += p.y;
|
| 484 |
+
}
|
| 485 |
+
cx /= hand.length;
|
| 486 |
+
cy /= hand.length;
|
| 487 |
+
|
| 488 |
+
// Draw centroid marker
|
| 489 |
+
ctx.beginPath();
|
| 490 |
+
ctx.arc(cx * w, cy * h, 8, 0, Math.PI * 2);
|
| 491 |
+
ctx.fillStyle = 'rgba(255, 107, 53, 0.8)';
|
| 492 |
+
ctx.fill();
|
| 493 |
+
|
| 494 |
+
// Smooth position (EMA)
|
| 495 |
+
const alpha = 1 - smoothing;
|
| 496 |
+
smoothX = alpha * cx + smoothing * smoothX;
|
| 497 |
+
smoothY = alpha * cy + smoothing * smoothY;
|
| 498 |
+
|
| 499 |
+
// Error from center
|
| 500 |
+
let errorX = smoothX - 0.5;
|
| 501 |
+
let errorY = smoothY - 0.5;
|
| 502 |
+
|
| 503 |
+
// Apply deadzone
|
| 504 |
+
if (Math.abs(errorX) < deadzone) errorX = 0;
|
| 505 |
+
if (Math.abs(errorY) < deadzone) errorY = 0;
|
| 506 |
+
|
| 507 |
+
// Time delta
|
| 508 |
+
const dt = lastFrameTime ? Math.min((performance.now() - lastFrameTime) / 1000, 0.1) : 0;
|
| 509 |
+
lastFrameTime = performance.now();
|
| 510 |
+
|
| 511 |
+
// Proportional controller
|
| 512 |
+
// Yaw: hand right (errorX > 0) → yaw should decrease (look right)
|
| 513 |
+
// Pitch: hand below center (errorY > 0) → pitch should decrease (look down)
|
| 514 |
+
currentYaw -= gain * errorX * dt;
|
| 515 |
+
currentPitch -= gain * errorY * dt;
|
| 516 |
+
|
| 517 |
+
// Clamp to robot limits
|
| 518 |
+
currentYaw = Math.max(-45, Math.min(45, currentYaw));
|
| 519 |
+
currentPitch = Math.max(-30, Math.min(30, currentPitch));
|
| 520 |
+
|
| 521 |
+
// Draw error line from center to smoothed hand position
|
| 522 |
+
ctx.beginPath();
|
| 523 |
+
ctx.moveTo(0.5 * w, 0.5 * h);
|
| 524 |
+
ctx.lineTo(smoothX * w, smoothY * h);
|
| 525 |
+
ctx.strokeStyle = 'rgba(255, 107, 53, 0.4)';
|
| 526 |
+
ctx.lineWidth = 2;
|
| 527 |
+
ctx.setLineDash([6, 4]);
|
| 528 |
+
ctx.stroke();
|
| 529 |
+
ctx.setLineDash([]);
|
| 530 |
+
|
| 531 |
+
} else {
|
| 532 |
+
noHandFrames++;
|
| 533 |
+
lastFrameTime = performance.now();
|
| 534 |
+
|
| 535 |
+
// Slowly return to center when no hand detected
|
| 536 |
+
if (noHandFrames > NO_HAND_RETURN_THRESHOLD) {
|
| 537 |
+
const returnRate = 0.97;
|
| 538 |
+
currentYaw *= returnRate;
|
| 539 |
+
currentPitch *= returnRate;
|
| 540 |
+
// Snap to zero when very close
|
| 541 |
+
if (Math.abs(currentYaw) < 0.5) currentYaw = 0;
|
| 542 |
+
if (Math.abs(currentPitch) < 0.5) currentPitch = 0;
|
| 543 |
+
}
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
// Send head command at limited rate
|
| 547 |
+
const cmdNow = performance.now();
|
| 548 |
+
if (cmdNow - lastCmdTime >= CMD_INTERVAL) {
|
| 549 |
+
lastCmdTime = cmdNow;
|
| 550 |
+
robot.setHeadPose(0, currentPitch, currentYaw);
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
// Update HUD
|
| 554 |
+
updateTrackBadge();
|
| 555 |
+
$('headBadge').textContent = `Y:${currentYaw.toFixed(1)} P:${currentPitch.toFixed(1)}`;
|
| 556 |
+
const cmdNow2 = performance.now();
|
| 557 |
+
if (cmdNow2 - lastLatencyTime >= 2000) {
|
| 558 |
+
lastLatencyTime = cmdNow2;
|
| 559 |
+
updateLatencyBadge();
|
| 560 |
+
}
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
// ─── Drawing ───
|
| 564 |
+
function drawHand(landmarks, w, h, isTracked) {
|
| 565 |
+
const color = isTracked ? 'rgba(0, 230, 118, 0.8)' : 'rgba(0, 230, 118, 0.25)';
|
| 566 |
+
const dotColor = isTracked ? 'rgba(255, 107, 53, 0.9)' : 'rgba(255, 107, 53, 0.3)';
|
| 567 |
+
const lineWidth = isTracked ? 2.5 : 1;
|
| 568 |
+
const dotRadius = isTracked ? 4 : 2;
|
| 569 |
+
|
| 570 |
+
// Connections
|
| 571 |
+
ctx.strokeStyle = color;
|
| 572 |
+
ctx.lineWidth = lineWidth;
|
| 573 |
+
for (const [i, j] of CONNECTIONS) {
|
| 574 |
+
ctx.beginPath();
|
| 575 |
+
ctx.moveTo(landmarks[i].x * w, landmarks[i].y * h);
|
| 576 |
+
ctx.lineTo(landmarks[j].x * w, landmarks[j].y * h);
|
| 577 |
+
ctx.stroke();
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
// Landmarks
|
| 581 |
+
ctx.fillStyle = dotColor;
|
| 582 |
+
for (const p of landmarks) {
|
| 583 |
+
ctx.beginPath();
|
| 584 |
+
ctx.arc(p.x * w, p.y * h, dotRadius, 0, Math.PI * 2);
|
| 585 |
+
ctx.fill();
|
| 586 |
+
}
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
function drawCrosshair(w, h) {
|
| 590 |
+
const cx = w / 2, cy = h / 2;
|
| 591 |
+
const size = 20;
|
| 592 |
+
ctx.strokeStyle = 'rgba(255, 255, 255, 0.2)';
|
| 593 |
+
ctx.lineWidth = 1;
|
| 594 |
+
ctx.beginPath();
|
| 595 |
+
ctx.moveTo(cx - size, cy);
|
| 596 |
+
ctx.lineTo(cx + size, cy);
|
| 597 |
+
ctx.moveTo(cx, cy - size);
|
| 598 |
+
ctx.lineTo(cx, cy + size);
|
| 599 |
+
ctx.stroke();
|
| 600 |
+
|
| 601 |
+
// Small circle
|
| 602 |
+
ctx.beginPath();
|
| 603 |
+
ctx.arc(cx, cy, 4, 0, Math.PI * 2);
|
| 604 |
+
ctx.stroke();
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
function clearCanvas() {
|
| 608 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 609 |
+
}
|
| 610 |
+
|
| 611 |
+
function resetTrackingState() {
|
| 612 |
+
smoothX = 0.5;
|
| 613 |
+
smoothY = 0.5;
|
| 614 |
+
currentYaw = 0;
|
| 615 |
+
currentPitch = 0;
|
| 616 |
+
lastCmdTime = 0;
|
| 617 |
+
lastFrameTime = 0;
|
| 618 |
+
lastDetectTs = -1;
|
| 619 |
+
noHandFrames = 0;
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
// ─── Latency badge ───
|
| 623 |
+
async function updateLatencyBadge() {
|
| 624 |
+
if (latencyPending || !robot._pc) return;
|
| 625 |
+
latencyPending = true;
|
| 626 |
+
try {
|
| 627 |
+
const stats = await robot._pc.getStats();
|
| 628 |
+
let rttMs = null;
|
| 629 |
+
stats.forEach(report => {
|
| 630 |
+
if (report.type === 'candidate-pair' && report.currentRoundTripTime != null) {
|
| 631 |
+
rttMs = Math.round(report.currentRoundTripTime * 1000);
|
| 632 |
+
}
|
| 633 |
+
});
|
| 634 |
+
if (rttMs !== null) {
|
| 635 |
+
$('latencyBadge').textContent = `rtt ${rttMs}ms`;
|
| 636 |
+
}
|
| 637 |
+
} catch (_) {}
|
| 638 |
+
latencyPending = false;
|
| 639 |
+
}
|
| 640 |
+
</script>
|
| 641 |
+
</body>
|
| 642 |
+
</html>
|
style.css
CHANGED
|
@@ -1,411 +1,358 @@
|
|
| 1 |
-
* {
|
| 2 |
-
margin: 0;
|
| 3 |
-
padding: 0;
|
| 4 |
-
box-sizing: border-box;
|
| 5 |
-
}
|
| 6 |
-
|
| 7 |
-
body {
|
| 8 |
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 9 |
-
line-height: 1.6;
|
| 10 |
-
color: #333;
|
| 11 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 12 |
-
min-height: 100vh;
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
.hero {
|
| 16 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 17 |
-
color: white;
|
| 18 |
-
padding: 4rem 2rem;
|
| 19 |
-
text-align: center;
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
.hero-content {
|
| 23 |
-
max-width: 800px;
|
| 24 |
-
margin: 0 auto;
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
.app-icon {
|
| 28 |
-
font-size: 4rem;
|
| 29 |
-
margin-bottom: 1rem;
|
| 30 |
-
display: inline-block;
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
.hero h1 {
|
| 34 |
-
font-size: 3rem;
|
| 35 |
-
font-weight: 700;
|
| 36 |
-
margin-bottom: 1rem;
|
| 37 |
-
background: linear-gradient(45deg, #fff, #f0f9ff);
|
| 38 |
-
background-clip: text;
|
| 39 |
-
-webkit-background-clip: text;
|
| 40 |
-
-webkit-text-fill-color: transparent;
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
.tagline {
|
| 44 |
-
font-size: 1.25rem;
|
| 45 |
-
opacity: 0.9;
|
| 46 |
-
max-width: 600px;
|
| 47 |
-
margin: 0 auto;
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
.container {
|
| 51 |
-
max-width: 1200px;
|
| 52 |
-
margin: 0 auto;
|
| 53 |
-
padding: 0 2rem;
|
| 54 |
-
position: relative;
|
| 55 |
-
z-index: 2;
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
.main-card {
|
| 59 |
-
background: white;
|
| 60 |
-
border-radius: 20px;
|
| 61 |
-
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
| 62 |
-
margin-top: -2rem;
|
| 63 |
-
overflow: hidden;
|
| 64 |
-
margin-bottom: 3rem;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
.app-preview {
|
| 68 |
-
background: linear-gradient(135deg, #1e3a8a, #3b82f6);
|
| 69 |
-
padding: 3rem;
|
| 70 |
-
color: white;
|
| 71 |
-
text-align: center;
|
| 72 |
-
position: relative;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
.preview-image {
|
| 76 |
-
background: #000;
|
| 77 |
-
border-radius: 15px;
|
| 78 |
-
padding: 2rem;
|
| 79 |
-
max-width: 500px;
|
| 80 |
-
margin: 0 auto;
|
| 81 |
-
position: relative;
|
| 82 |
-
overflow: hidden;
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
.camera-feed {
|
| 86 |
-
font-size: 4rem;
|
| 87 |
-
margin-bottom: 1rem;
|
| 88 |
-
opacity: 0.7;
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
.detection-overlay {
|
| 92 |
-
position: absolute;
|
| 93 |
-
top: 50%;
|
| 94 |
-
left: 50%;
|
| 95 |
-
transform: translate(-50%, -50%);
|
| 96 |
-
width: 100%;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
.bbox {
|
| 100 |
-
background: rgba(34, 197, 94, 0.9);
|
| 101 |
-
color: white;
|
| 102 |
-
padding: 0.5rem 1rem;
|
| 103 |
-
border-radius: 8px;
|
| 104 |
-
font-size: 0.9rem;
|
| 105 |
-
font-weight: 600;
|
| 106 |
-
margin: 0.5rem;
|
| 107 |
-
display: inline-block;
|
| 108 |
-
border: 2px solid #22c55e;
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
.app-details {
|
| 112 |
-
padding: 3rem;
|
| 113 |
-
}
|
| 114 |
-
|
| 115 |
-
.app-details h2 {
|
| 116 |
-
font-size: 2rem;
|
| 117 |
-
color: #1e293b;
|
| 118 |
-
margin-bottom: 2rem;
|
| 119 |
-
text-align: center;
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
.template-info {
|
| 123 |
-
display: grid;
|
| 124 |
-
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
| 125 |
-
gap: 2rem;
|
| 126 |
-
margin-bottom: 3rem;
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
.info-box {
|
| 130 |
-
background: #f0f9ff;
|
| 131 |
-
border: 2px solid #e0f2fe;
|
| 132 |
-
border-radius: 12px;
|
| 133 |
-
padding: 2rem;
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
.info-box h3 {
|
| 137 |
-
color: #0c4a6e;
|
| 138 |
-
margin-bottom: 1rem;
|
| 139 |
-
font-size: 1.2rem;
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
.info-box p {
|
| 143 |
-
color: #0369a1;
|
| 144 |
-
line-height: 1.6;
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
.how-to-use {
|
| 148 |
-
background: #fefce8;
|
| 149 |
-
border: 2px solid #fde047;
|
| 150 |
-
border-radius: 12px;
|
| 151 |
-
padding: 2rem;
|
| 152 |
-
margin-top: 3rem;
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
.how-to-use h3 {
|
| 156 |
-
color: #a16207;
|
| 157 |
-
margin-bottom: 1.5rem;
|
| 158 |
-
font-size: 1.3rem;
|
| 159 |
-
text-align: center;
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
-
.steps {
|
| 163 |
-
display: flex;
|
| 164 |
-
flex-direction: column;
|
| 165 |
-
gap: 1.5rem;
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
.step {
|
| 169 |
-
display: flex;
|
| 170 |
-
align-items: flex-start;
|
| 171 |
-
gap: 1rem;
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
.step-number {
|
| 175 |
-
background: #eab308;
|
| 176 |
-
color: white;
|
| 177 |
-
width: 2rem;
|
| 178 |
-
height: 2rem;
|
| 179 |
-
border-radius: 50%;
|
| 180 |
-
display: flex;
|
| 181 |
-
align-items: center;
|
| 182 |
-
justify-content: center;
|
| 183 |
-
font-weight: bold;
|
| 184 |
-
flex-shrink: 0;
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
.step h4 {
|
| 188 |
-
color: #a16207;
|
| 189 |
-
margin-bottom: 0.5rem;
|
| 190 |
-
font-size: 1.1rem;
|
| 191 |
-
}
|
| 192 |
-
|
| 193 |
-
.step p {
|
| 194 |
-
color: #ca8a04;
|
| 195 |
-
}
|
| 196 |
-
|
| 197 |
-
.download-card {
|
| 198 |
-
background: white;
|
| 199 |
-
border-radius: 20px;
|
| 200 |
-
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
| 201 |
-
padding: 3rem;
|
| 202 |
-
text-align: center;
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
.download-card h2 {
|
| 206 |
-
font-size: 2rem;
|
| 207 |
-
color: #1e293b;
|
| 208 |
-
margin-bottom: 1rem;
|
| 209 |
-
}
|
| 210 |
-
|
| 211 |
-
.download-card>p {
|
| 212 |
-
color: #64748b;
|
| 213 |
-
font-size: 1.1rem;
|
| 214 |
-
margin-bottom: 2rem;
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
.dashboard-config {
|
| 218 |
-
margin-bottom: 2rem;
|
| 219 |
-
text-align: left;
|
| 220 |
-
max-width: 400px;
|
| 221 |
-
margin-left: auto;
|
| 222 |
-
margin-right: auto;
|
| 223 |
-
}
|
| 224 |
-
|
| 225 |
-
.dashboard-config label {
|
| 226 |
-
display: block;
|
| 227 |
-
color: #374151;
|
| 228 |
-
font-weight: 600;
|
| 229 |
-
margin-bottom: 0.5rem;
|
| 230 |
-
}
|
| 231 |
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
}
|
| 240 |
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
}
|
| 262 |
-
|
| 263 |
-
.
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
}
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
}
|
| 328 |
-
|
| 329 |
-
.
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
}
|
| 357 |
|
| 358 |
-
.
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
}
|
| 361 |
|
| 362 |
-
.
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
|
|
|
| 366 |
}
|
| 367 |
|
| 368 |
-
.
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
| 373 |
}
|
| 374 |
|
| 375 |
-
.
|
| 376 |
-
color: white;
|
| 377 |
-
text-decoration: none;
|
| 378 |
-
font-weight: 600;
|
| 379 |
-
}
|
| 380 |
|
| 381 |
-
|
| 382 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
}
|
| 384 |
-
|
| 385 |
-
/* Responsive Design */
|
| 386 |
-
@media (max-width: 768px) {
|
| 387 |
-
.hero {
|
| 388 |
-
padding: 2rem 1rem;
|
| 389 |
-
}
|
| 390 |
-
|
| 391 |
-
.hero h1 {
|
| 392 |
-
font-size: 2rem;
|
| 393 |
-
}
|
| 394 |
-
|
| 395 |
-
.container {
|
| 396 |
-
padding: 0 1rem;
|
| 397 |
-
}
|
| 398 |
-
|
| 399 |
-
.app-details,
|
| 400 |
-
.download-card {
|
| 401 |
-
padding: 2rem;
|
| 402 |
-
}
|
| 403 |
-
|
| 404 |
-
.features-grid {
|
| 405 |
-
grid-template-columns: 1fr;
|
| 406 |
-
}
|
| 407 |
-
|
| 408 |
-
.download-options {
|
| 409 |
-
grid-template-columns: 1fr;
|
| 410 |
-
}
|
| 411 |
-
}
|
|
|
|
| 1 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
:root {
|
| 4 |
+
--bg: #0a0a1a;
|
| 5 |
+
--surface: #1a1a2e;
|
| 6 |
+
--border: #2a2a40;
|
| 7 |
+
--accent: #FF6B35;
|
| 8 |
+
--accent-dim: rgba(255, 107, 53, 0.15);
|
| 9 |
+
--text: #e0e0e0;
|
| 10 |
+
--text-muted: #888;
|
| 11 |
+
--green: #00e676;
|
| 12 |
+
--yellow: #ffd740;
|
| 13 |
+
--red: #ff5252;
|
| 14 |
}
|
| 15 |
|
| 16 |
+
body {
|
| 17 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
| 18 |
+
background: var(--bg);
|
| 19 |
+
color: var(--text);
|
| 20 |
+
height: 100vh;
|
| 21 |
+
display: flex;
|
| 22 |
+
flex-direction: column;
|
| 23 |
+
overflow: hidden;
|
| 24 |
+
user-select: none;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.hidden { display: none !important; }
|
| 28 |
+
|
| 29 |
+
/* ── Login ── */
|
| 30 |
+
.login-view {
|
| 31 |
+
display: flex;
|
| 32 |
+
align-items: center;
|
| 33 |
+
justify-content: center;
|
| 34 |
+
height: 100vh;
|
| 35 |
+
background: radial-gradient(ellipse at center, #1a1a3e 0%, var(--bg) 70%);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
.login-card {
|
| 39 |
+
background: var(--surface);
|
| 40 |
+
border: 1px solid var(--border);
|
| 41 |
+
border-radius: 16px;
|
| 42 |
+
padding: 3rem;
|
| 43 |
+
text-align: center;
|
| 44 |
+
max-width: 380px;
|
| 45 |
+
width: 90%;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.login-card h2 {
|
| 49 |
+
font-size: 1.8rem;
|
| 50 |
+
margin-bottom: 0.5rem;
|
| 51 |
+
color: var(--accent);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
.login-card p {
|
| 55 |
+
color: var(--text-muted);
|
| 56 |
+
margin-bottom: 2rem;
|
| 57 |
+
font-size: 0.9rem;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.btn-hf {
|
| 61 |
+
background: #FFD21E;
|
| 62 |
+
color: #1a1a1a;
|
| 63 |
+
border: none;
|
| 64 |
+
padding: 0.8rem 1.5rem;
|
| 65 |
+
border-radius: 8px;
|
| 66 |
+
font-size: 0.95rem;
|
| 67 |
+
font-weight: 600;
|
| 68 |
+
cursor: pointer;
|
| 69 |
+
display: inline-flex;
|
| 70 |
+
align-items: center;
|
| 71 |
+
gap: 0.5rem;
|
| 72 |
+
transition: transform 0.15s, box-shadow 0.15s;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn-hf:hover {
|
| 76 |
+
transform: translateY(-1px);
|
| 77 |
+
box-shadow: 0 4px 12px rgba(255, 210, 30, 0.3);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/* ── Header ── */
|
| 81 |
+
header {
|
| 82 |
+
display: flex;
|
| 83 |
+
align-items: center;
|
| 84 |
+
justify-content: space-between;
|
| 85 |
+
padding: 0.6rem 1rem;
|
| 86 |
+
background: var(--surface);
|
| 87 |
+
border-bottom: 1px solid var(--border);
|
| 88 |
+
flex-shrink: 0;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.brand {
|
| 92 |
+
font-weight: 700;
|
| 93 |
+
font-size: 1rem;
|
| 94 |
+
color: var(--accent);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
.brand span {
|
| 98 |
+
color: var(--text-muted);
|
| 99 |
+
font-weight: 400;
|
| 100 |
+
font-size: 0.85rem;
|
| 101 |
+
margin-left: 0.4rem;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
.user-info {
|
| 105 |
+
display: flex;
|
| 106 |
+
align-items: center;
|
| 107 |
+
gap: 0.8rem;
|
| 108 |
+
font-size: 0.85rem;
|
| 109 |
+
color: var(--text-muted);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.btn-logout {
|
| 113 |
+
background: none;
|
| 114 |
+
border: 1px solid var(--border);
|
| 115 |
+
color: var(--text-muted);
|
| 116 |
+
padding: 0.3rem 0.8rem;
|
| 117 |
+
border-radius: 6px;
|
| 118 |
+
font-size: 0.8rem;
|
| 119 |
+
cursor: pointer;
|
| 120 |
+
transition: border-color 0.15s;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.btn-logout:hover { border-color: var(--text-muted); }
|
| 124 |
+
|
| 125 |
+
/* ── Main layout ── */
|
| 126 |
+
main {
|
| 127 |
+
flex: 1;
|
| 128 |
+
display: flex;
|
| 129 |
+
flex-direction: column;
|
| 130 |
+
min-height: 0;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/* ── Video ── */
|
| 134 |
+
.video-container {
|
| 135 |
+
flex: 1;
|
| 136 |
+
position: relative;
|
| 137 |
+
background: #000;
|
| 138 |
+
min-height: 0;
|
| 139 |
+
display: flex;
|
| 140 |
+
align-items: center;
|
| 141 |
+
justify-content: center;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
.video-container video {
|
| 145 |
+
width: 100%;
|
| 146 |
+
height: 100%;
|
| 147 |
+
object-fit: contain;
|
| 148 |
+
display: block;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
.video-container canvas {
|
| 152 |
+
position: absolute;
|
| 153 |
+
pointer-events: none;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
/* ── HUD badges ── */
|
| 157 |
+
.hud {
|
| 158 |
+
position: absolute;
|
| 159 |
+
top: 0;
|
| 160 |
+
left: 0;
|
| 161 |
+
right: 0;
|
| 162 |
+
bottom: 0;
|
| 163 |
+
pointer-events: none;
|
| 164 |
+
padding: 0.6rem;
|
| 165 |
+
display: flex;
|
| 166 |
+
flex-direction: column;
|
| 167 |
+
justify-content: space-between;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.hud-top, .hud-bottom {
|
| 171 |
+
display: flex;
|
| 172 |
+
justify-content: space-between;
|
| 173 |
+
align-items: flex-start;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
.badge {
|
| 177 |
+
background: rgba(0, 0, 0, 0.7);
|
| 178 |
+
backdrop-filter: blur(8px);
|
| 179 |
+
padding: 0.3rem 0.6rem;
|
| 180 |
+
border-radius: 6px;
|
| 181 |
+
font-size: 0.75rem;
|
| 182 |
+
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
|
| 183 |
+
white-space: nowrap;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
.badge.status-disconnected { border-left: 3px solid var(--red); }
|
| 187 |
+
.badge.status-connecting { border-left: 3px solid var(--yellow); }
|
| 188 |
+
.badge.status-connected { border-left: 3px solid var(--green); }
|
| 189 |
+
.badge.status-streaming { border-left: 3px solid var(--green); }
|
| 190 |
+
|
| 191 |
+
.badge.tracking-active { border-left: 3px solid var(--green); }
|
| 192 |
+
.badge.tracking-searching { border-left: 3px solid var(--yellow); }
|
| 193 |
+
.badge.tracking-disabled { border-left: 3px solid var(--text-muted); }
|
| 194 |
+
|
| 195 |
+
.badge-group {
|
| 196 |
+
display: flex;
|
| 197 |
+
gap: 0.4rem;
|
| 198 |
+
flex-wrap: wrap;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
.model-loading {
|
| 202 |
+
position: absolute;
|
| 203 |
+
top: 50%;
|
| 204 |
+
left: 50%;
|
| 205 |
+
transform: translate(-50%, -50%);
|
| 206 |
+
text-align: center;
|
| 207 |
+
color: var(--text-muted);
|
| 208 |
+
font-size: 0.9rem;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.model-loading .spinner {
|
| 212 |
+
width: 32px;
|
| 213 |
+
height: 32px;
|
| 214 |
+
border: 3px solid var(--border);
|
| 215 |
+
border-top-color: var(--accent);
|
| 216 |
+
border-radius: 50%;
|
| 217 |
+
animation: spin 0.8s linear infinite;
|
| 218 |
+
margin: 0 auto 0.8rem;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
@keyframes spin { to { transform: rotate(360deg); } }
|
| 222 |
+
|
| 223 |
+
/* ── Controls bar ── */
|
| 224 |
+
.controls {
|
| 225 |
+
display: flex;
|
| 226 |
+
align-items: center;
|
| 227 |
+
gap: 0.5rem;
|
| 228 |
+
padding: 0.5rem 0.8rem;
|
| 229 |
+
background: var(--surface);
|
| 230 |
+
border-top: 1px solid var(--border);
|
| 231 |
+
flex-shrink: 0;
|
| 232 |
+
flex-wrap: wrap;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
.controls select {
|
| 236 |
+
background: var(--bg);
|
| 237 |
+
color: var(--text);
|
| 238 |
+
border: 1px solid var(--border);
|
| 239 |
+
padding: 0.4rem 0.6rem;
|
| 240 |
+
border-radius: 6px;
|
| 241 |
+
font-size: 0.8rem;
|
| 242 |
+
min-width: 120px;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
.btn {
|
| 246 |
+
padding: 0.4rem 0.9rem;
|
| 247 |
+
border-radius: 6px;
|
| 248 |
+
font-size: 0.8rem;
|
| 249 |
+
font-weight: 600;
|
| 250 |
+
border: none;
|
| 251 |
+
cursor: pointer;
|
| 252 |
+
transition: opacity 0.15s;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
.btn:disabled {
|
| 256 |
+
opacity: 0.4;
|
| 257 |
+
cursor: not-allowed;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
.btn-connect { background: var(--accent); color: #fff; }
|
| 261 |
+
.btn-start { background: var(--green); color: #111; }
|
| 262 |
+
.btn-stop { background: var(--red); color: #fff; }
|
| 263 |
+
|
| 264 |
+
.spacer { flex: 1; }
|
| 265 |
+
|
| 266 |
+
/* ── Toggle ── */
|
| 267 |
+
.toggle {
|
| 268 |
+
display: flex;
|
| 269 |
+
align-items: center;
|
| 270 |
+
gap: 0.5rem;
|
| 271 |
+
font-size: 0.8rem;
|
| 272 |
+
color: var(--text-muted);
|
| 273 |
+
cursor: pointer;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
.toggle input[type="checkbox"] {
|
| 277 |
+
appearance: none;
|
| 278 |
+
width: 36px;
|
| 279 |
+
height: 20px;
|
| 280 |
+
background: var(--border);
|
| 281 |
+
border-radius: 10px;
|
| 282 |
+
position: relative;
|
| 283 |
+
cursor: pointer;
|
| 284 |
+
transition: background 0.2s;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
.toggle input[type="checkbox"]::after {
|
| 288 |
+
content: '';
|
| 289 |
+
position: absolute;
|
| 290 |
+
width: 16px;
|
| 291 |
+
height: 16px;
|
| 292 |
+
background: #fff;
|
| 293 |
+
border-radius: 50%;
|
| 294 |
+
top: 2px;
|
| 295 |
+
left: 2px;
|
| 296 |
+
transition: transform 0.2s;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
.toggle input[type="checkbox"]:checked {
|
| 300 |
+
background: var(--accent);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
.toggle input[type="checkbox"]:checked::after {
|
| 304 |
+
transform: translateX(16px);
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
/* ── Tuning panel ── */
|
| 308 |
+
.tuning {
|
| 309 |
+
display: flex;
|
| 310 |
+
gap: 1.5rem;
|
| 311 |
+
padding: 0.5rem 0.8rem;
|
| 312 |
+
background: var(--bg);
|
| 313 |
+
border-top: 1px solid var(--border);
|
| 314 |
+
flex-shrink: 0;
|
| 315 |
+
flex-wrap: wrap;
|
| 316 |
+
align-items: center;
|
| 317 |
}
|
| 318 |
|
| 319 |
+
.tuning label {
|
| 320 |
+
display: flex;
|
| 321 |
+
align-items: center;
|
| 322 |
+
gap: 0.5rem;
|
| 323 |
+
font-size: 0.75rem;
|
| 324 |
+
color: var(--text-muted);
|
| 325 |
+
white-space: nowrap;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
.tuning input[type="range"] {
|
| 329 |
+
width: 80px;
|
| 330 |
+
accent-color: var(--accent);
|
| 331 |
}
|
| 332 |
|
| 333 |
+
.tuning .value {
|
| 334 |
+
font-family: 'SF Mono', monospace;
|
| 335 |
+
color: var(--text);
|
| 336 |
+
min-width: 2.5em;
|
| 337 |
+
text-align: right;
|
| 338 |
}
|
| 339 |
|
| 340 |
+
.btn-tune {
|
| 341 |
+
background: none;
|
| 342 |
+
border: 1px solid var(--border);
|
| 343 |
+
color: var(--text-muted);
|
| 344 |
+
padding: 0.3rem 0.6rem;
|
| 345 |
+
border-radius: 6px;
|
| 346 |
+
font-size: 0.75rem;
|
| 347 |
+
cursor: pointer;
|
| 348 |
}
|
| 349 |
|
| 350 |
+
.btn-tune:hover { border-color: var(--accent); color: var(--accent); }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
+
/* ── Responsive ── */
|
| 353 |
+
@media (max-width: 600px) {
|
| 354 |
+
.controls { gap: 0.3rem; }
|
| 355 |
+
.btn { padding: 0.35rem 0.6rem; font-size: 0.75rem; }
|
| 356 |
+
.tuning { gap: 0.8rem; }
|
| 357 |
+
.tuning input[type="range"] { width: 60px; }
|
| 358 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|