Update app.py
Browse files304 unmodified lines305306307308309310311312313314315316317318319320321322323324325326327328329304 unmodified linesws.onopen = () => document.getElementById('wsStatus').innerHTML = '🟢 Connected';ws.onclose = () => document.getElementById('wsStatus').innerHTML = '🔴 Disconnected';// Mouse tracking - send via WebSocketlet mouseTimer;img.addEventListener('mousemove', (e) => {const rect = img.getBoundingClientRect();const x = Math.round((e.clientX - rect.left) * 640 / rect.width);const y = Math.round((e.clientY - rect.top) * 480 / rect.height);document.getElementById('mouseCoords').innerHTML = `X: ${x}, Y: ${y}`;// Throttle to 30fpsif (mouseTimer) clearTimeout(mouseTimer);mouseTimer = setTimeout(() => {ws.send(JSON.stringify({type: 'mouse',x: x,y: y}));}, 33);});// Click handling - send via WebSocketimg.addEventListener('click', (e) => {304 unmodified lines305306307308309310311312313314315316317318319320321322323324325326327328329330331332333304 unmodified linesws.onopen = () => document.getElementById('wsStatus').innerHTML = '🟢 Connected';ws.onclose = () => document.getElementById('wsStatus').innerHTML = '🔴 Disconnected';// Mouse tracking with proper throttlinglet lastMouseSend = 0;const MOUSE_THROTTLE_MS = 33; // 30fps (change to 50 for 20fps)img.addEventListener('mousemove', (e) => {const rect = img.getBoundingClientRect();const x = Math.round((e.clientX - rect.left) * 640 / rect.width);const y = Math.round((e.clientY - rect.top) * 480 / rect.height);// Update display immediately (no lag)document.getElementById('mouseCoords').innerHTML = `X: ${x}, Y: ${y}`;// Throttle sends to 30fpsconst now = Date.now();if (now - lastMouseSend >= MOUSE_THROTTLE_MS) {ws.send(JSON.stringify({type: 'mouse',x: x,y: y}));lastMouseSend = now;}});// Click handling - send via WebSocketimg.addEventListener('click', (e) => {
app.py+23-19