yuntian-deng commited on
Commit
dab8c4c
·
1 Parent(s): f9c716f

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +7 -4
static/index.html CHANGED
@@ -17,6 +17,8 @@
17
  let reconnectAttempts = 0;
18
  const MAX_RECONNECT_DELAY = 30000; // Maximum delay between reconnection attempts (30 seconds)
19
 
 
 
20
  function connect() {
21
  socket = new WebSocket(`wss://${window.location.host}/ws`);
22
 
@@ -46,6 +48,7 @@
46
  const img = new Image();
47
  img.onload = function() {
48
  ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
 
49
  };
50
  img.src = 'data:image/png;base64,' + data.image;
51
  }
@@ -77,7 +80,8 @@
77
 
78
  function sendMousePosition(x, y, forceUpdate = false) {
79
  const currentTime = Date.now();
80
- if (isConnected && (forceUpdate || !lastSentPosition || currentTime - lastSentTime >= SEND_INTERVAL)) {
 
81
  socket.send(JSON.stringify({
82
  "action_type": "move",
83
  "mouse_position": [x, y]
@@ -104,13 +108,12 @@
104
  });
105
 
106
  canvas.addEventListener("click", function (event) {
107
- if (!isConnected) return;
108
  let rect = canvas.getBoundingClientRect();
109
  let x = event.clientX - rect.left;
110
  let y = event.clientY - rect.top;
111
 
112
- sendMousePosition(x, y, true);
113
-
114
  socket.send(JSON.stringify({
115
  "action_type": "left_click",
116
  "mouse_position": [x, y]
 
17
  let reconnectAttempts = 0;
18
  const MAX_RECONNECT_DELAY = 30000; // Maximum delay between reconnection attempts (30 seconds)
19
 
20
+ let isProcessing = false;
21
+
22
  function connect() {
23
  socket = new WebSocket(`wss://${window.location.host}/ws`);
24
 
 
48
  const img = new Image();
49
  img.onload = function() {
50
  ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
51
+ isProcessing = false; // Allow new inputs after drawing the image
52
  };
53
  img.src = 'data:image/png;base64,' + data.image;
54
  }
 
80
 
81
  function sendMousePosition(x, y, forceUpdate = false) {
82
  const currentTime = Date.now();
83
+ if (isConnected && !isProcessing && (forceUpdate || !lastSentPosition || currentTime - lastSentTime >= SEND_INTERVAL)) {
84
+ isProcessing = true;
85
  socket.send(JSON.stringify({
86
  "action_type": "move",
87
  "mouse_position": [x, y]
 
108
  });
109
 
110
  canvas.addEventListener("click", function (event) {
111
+ if (!isConnected || isProcessing) return;
112
  let rect = canvas.getBoundingClientRect();
113
  let x = event.clientX - rect.left;
114
  let y = event.clientY - rect.top;
115
 
116
+ isProcessing = true;
 
117
  socket.send(JSON.stringify({
118
  "action_type": "left_click",
119
  "mouse_position": [x, y]