da03 commited on
Commit
b682e6d
·
1 Parent(s): 2225158
Files changed (2) hide show
  1. main.py +4 -4
  2. static/index.html +4 -4
main.py CHANGED
@@ -132,8 +132,8 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
132
  connection_counter = 0
133
 
134
  # Connection timeout settings
135
- CONNECTION_TIMEOUT = 60 # 1 minute timeout
136
- WARNING_TIME = 30 # 30 seconds warning before timeout
137
 
138
  # Create a thread pool executor
139
  thread_executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
@@ -391,7 +391,7 @@ async def websocket_endpoint(websocket: WebSocket):
391
  current_time = time.perf_counter()
392
  time_since_activity = current_time - last_user_activity_time
393
 
394
- # Send warning at 30 seconds
395
  if time_since_activity >= WARNING_TIME and not timeout_warning_sent:
396
  print(f"[{current_time:.3f}] Sending timeout warning to client {client_id}")
397
  await websocket.send_json({
@@ -400,7 +400,7 @@ async def websocket_endpoint(websocket: WebSocket):
400
  })
401
  timeout_warning_sent = True
402
 
403
- # Close connection at 1 minute
404
  if time_since_activity >= CONNECTION_TIMEOUT:
405
  print(f"[{current_time:.3f}] Closing connection {client_id} due to timeout")
406
 
 
132
  connection_counter = 0
133
 
134
  # Connection timeout settings
135
+ CONNECTION_TIMEOUT = 30 # 30 seconds timeout
136
+ WARNING_TIME = 15 # 15 seconds warning before timeout
137
 
138
  # Create a thread pool executor
139
  thread_executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
 
391
  current_time = time.perf_counter()
392
  time_since_activity = current_time - last_user_activity_time
393
 
394
+ # Send warning at 15 seconds
395
  if time_since_activity >= WARNING_TIME and not timeout_warning_sent:
396
  print(f"[{current_time:.3f}] Sending timeout warning to client {client_id}")
397
  await websocket.send_json({
 
400
  })
401
  timeout_warning_sent = True
402
 
403
+ # Close connection at 30 seconds
404
  if time_since_activity >= CONNECTION_TIMEOUT:
405
  print(f"[{current_time:.3f}] Closing connection {client_id} due to timeout")
406
 
static/index.html CHANGED
@@ -117,7 +117,7 @@
117
 
118
  <div id="timeoutWarning" class="alert alert-warning" style="display: none; margin-top: 10px;">
119
  <strong>Connection Timeout Warning:</strong>
120
- No user activity detected. Connection will be dropped in <span id="timeoutCountdown">30</span> seconds.
121
  <button type="button" class="btn btn-sm btn-primary ms-2" onclick="resetTimeout()">Stay Connected</button>
122
  </div>
123
  </div>
@@ -279,7 +279,7 @@
279
 
280
  // Timeout countdown mechanism
281
  let timeoutCountdownInterval = null;
282
- let timeoutCountdown = 30;
283
  let timeoutWarningActive = false;
284
 
285
  // Track currently pressed keys
@@ -369,7 +369,7 @@
369
  clearInterval(timeoutCountdownInterval);
370
  }
371
 
372
- timeoutCountdown = 30;
373
  timeoutWarningActive = true;
374
 
375
  // Show warning
@@ -400,7 +400,7 @@
400
  }
401
 
402
  timeoutWarningActive = false;
403
- timeoutCountdown = 30;
404
 
405
  // Hide warning
406
  const warning = document.getElementById('timeoutWarning');
 
117
 
118
  <div id="timeoutWarning" class="alert alert-warning" style="display: none; margin-top: 10px;">
119
  <strong>Connection Timeout Warning:</strong>
120
+ No user activity detected. Connection will be dropped in <span id="timeoutCountdown">15</span> seconds.
121
  <button type="button" class="btn btn-sm btn-primary ms-2" onclick="resetTimeout()">Stay Connected</button>
122
  </div>
123
  </div>
 
279
 
280
  // Timeout countdown mechanism
281
  let timeoutCountdownInterval = null;
282
+ let timeoutCountdown = 15;
283
  let timeoutWarningActive = false;
284
 
285
  // Track currently pressed keys
 
369
  clearInterval(timeoutCountdownInterval);
370
  }
371
 
372
+ timeoutCountdown = 15;
373
  timeoutWarningActive = true;
374
 
375
  // Show warning
 
400
  }
401
 
402
  timeoutWarningActive = false;
403
+ timeoutCountdown = 15;
404
 
405
  // Hide warning
406
  const warning = document.getElementById('timeoutWarning');