MySafeCode commited on
Commit
ab8f89b
·
verified ·
1 Parent(s): ce14a3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
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 - send via WebSocket
309
- let mouseTimer;
310
- img.addEventListener('mousemove', (e) => {
311
- const rect = img.getBoundingClientRect();
312
- const x = Math.round((e.clientX - rect.left) * 640 / rect.width);
313
- const y = Math.round((e.clientY - rect.top) * 480 / rect.height);
314
-
315
- document.getElementById('mouseCoords').innerHTML = `X: ${x}, Y: ${y}`;
316
-
317
- // Throttle to 30fps
318
- if (mouseTimer) clearTimeout(mouseTimer);
319
- mouseTimer = setTimeout(() => {
320
- ws.send(JSON.stringify({
321
- type: 'mouse',
322
- x: x,
323
- y: y
324
- }));
325
- }, 33);
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) => {