Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -305,25 +305,29 @@ def index():
|
|
| 305 |
ws.onopen = () => document.getElementById('wsStatus').innerHTML = '🟢 Connected';
|
| 306 |
ws.onclose = () => document.getElementById('wsStatus').innerHTML = '🔴 Disconnected';
|
| 307 |
|
| 308 |
-
// Mouse tracking
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
|
| 328 |
// Click handling - send via WebSocket
|
| 329 |
img.addEventListener('click', (e) => {
|
|
|
|
| 305 |
ws.onopen = () => document.getElementById('wsStatus').innerHTML = '🟢 Connected';
|
| 306 |
ws.onclose = () => document.getElementById('wsStatus').innerHTML = '🔴 Disconnected';
|
| 307 |
|
| 308 |
+
// Mouse tracking with proper throttling
|
| 309 |
+
let lastMouseSend = 0;
|
| 310 |
+
const MOUSE_THROTTLE_MS = 33; // 30fps (change to 50 for 20fps)
|
| 311 |
+
|
| 312 |
+
img.addEventListener('mousemove', (e) => {
|
| 313 |
+
const rect = img.getBoundingClientRect();
|
| 314 |
+
const x = Math.round((e.clientX - rect.left) * 640 / rect.width);
|
| 315 |
+
const y = Math.round((e.clientY - rect.top) * 480 / rect.height);
|
| 316 |
+
|
| 317 |
+
// Update display immediately (no lag)
|
| 318 |
+
document.getElementById('mouseCoords').innerHTML = `X: ${x}, Y: ${y}`;
|
| 319 |
+
|
| 320 |
+
// Throttle sends to 30fps
|
| 321 |
+
const now = Date.now();
|
| 322 |
+
if (now - lastMouseSend >= MOUSE_THROTTLE_MS) {
|
| 323 |
+
ws.send(JSON.stringify({
|
| 324 |
+
type: 'mouse',
|
| 325 |
+
x: x,
|
| 326 |
+
y: y
|
| 327 |
+
}));
|
| 328 |
+
lastMouseSend = now;
|
| 329 |
+
}
|
| 330 |
+
});
|
| 331 |
|
| 332 |
// Click handling - send via WebSocket
|
| 333 |
img.addEventListener('click', (e) => {
|