da03 commited on
Commit
30c8a40
·
1 Parent(s): a59d77c
Files changed (1) hide show
  1. static/index.html +38 -2
static/index.html CHANGED
@@ -168,6 +168,16 @@
168
  ctx.fillText("The neural model will render in this area", canvas.width/2, canvas.height/2 + 20);
169
  }
170
 
 
 
 
 
 
 
 
 
 
 
171
  function connect() {
172
  const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
173
  socket = new WebSocket(`${protocol}//${window.location.host}/ws`);
@@ -178,6 +188,15 @@
178
  //connectionAttempted = false; // Reset flag for potential reconnections
179
  //reconnectAttempts = 0;
180
 
 
 
 
 
 
 
 
 
 
181
  // Start auto-input mechanism
182
  startAutoInput();
183
 
@@ -493,13 +512,30 @@
493
  }
494
 
495
  // Capture mouse movements and clicks
496
- canvas.addEventListener("mousemove", function (event) {
497
  // Establish connection on first mouse movement if not already connected
498
  if (!isConnected && !connectionAttempted) {
499
  console.log("First mouse movement detected - establishing WebSocket connection");
500
  connectionAttempted = true;
 
501
  connect();
502
- //return; // Skip this event, let the next one be processed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  }
504
 
505
  if (!isConnected || isProcessing) return;
 
168
  ctx.fillText("The neural model will render in this area", canvas.width/2, canvas.height/2 + 20);
169
  }
170
 
171
+ // Function to show connection status
172
+ function showConnectionStatus(message) {
173
+ ctx.fillStyle = "#ffffff";
174
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
175
+ ctx.font = "18px Arial";
176
+ ctx.fillStyle = "#666666";
177
+ ctx.textAlign = "center";
178
+ ctx.fillText(message, canvas.width/2, canvas.height/2);
179
+ }
180
+
181
  function connect() {
182
  const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
183
  socket = new WebSocket(`${protocol}//${window.location.host}/ws`);
 
188
  //connectionAttempted = false; // Reset flag for potential reconnections
189
  //reconnectAttempts = 0;
190
 
191
+ // Show brief success message
192
+ showConnectionStatus("Connected! Processing input...");
193
+ setTimeout(() => {
194
+ // Clear the message after 1 second
195
+ if (isConnected) {
196
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
197
+ }
198
+ }, 1000);
199
+
200
  // Start auto-input mechanism
201
  startAutoInput();
202
 
 
512
  }
513
 
514
  // Capture mouse movements and clicks
515
+ canvas.addEventListener("mousemove", async function (event) {
516
  // Establish connection on first mouse movement if not already connected
517
  if (!isConnected && !connectionAttempted) {
518
  console.log("First mouse movement detected - establishing WebSocket connection");
519
  connectionAttempted = true;
520
+ showConnectionStatus("Connecting to NeuralOS...");
521
  connect();
522
+
523
+ // Wait for connection to be established
524
+ let attempts = 0;
525
+ const maxAttempts = 50; // 5 seconds max wait
526
+ while (!isConnected && attempts < maxAttempts) {
527
+ await new Promise(resolve => setTimeout(resolve, 100)); // Wait 100ms
528
+ attempts++;
529
+ }
530
+
531
+ if (!isConnected) {
532
+ console.error("Failed to establish connection after 5 seconds");
533
+ connectionAttempted = false; // Reset flag to allow retry
534
+ showConnectionStatus("Connection failed. Move mouse to retry.");
535
+ return;
536
+ }
537
+
538
+ console.log("Connection established, processing first mouse movement");
539
  }
540
 
541
  if (!isConnected || isProcessing) return;