Spaces:
Runtime error
Runtime error
da03
commited on
Commit
·
6e88d5e
1
Parent(s):
6fa3785
- static/index.html +136 -23
static/index.html
CHANGED
@@ -275,16 +275,16 @@
|
|
275 |
} else if (data.type === "timeout_warning") {
|
276 |
console.log(`Received timeout warning: ${data.timeout_in} seconds remaining`);
|
277 |
setTimeoutMessage(`No activity detected. Connection will be dropped in <span id="timeoutCountdown">${data.timeout_in}</span> seconds and page will refresh automatically.`);
|
278 |
-
startTimeoutCountdown(data.timeout_in, false); // false = show stay connected button
|
279 |
} else if (data.type === "activity_reset") {
|
280 |
console.log("Server detected user activity, resetting timeout");
|
281 |
-
stopTimeoutCountdown();
|
282 |
|
283 |
-
// If there's still a session time limit active,
|
284 |
if (data.session_time_remaining && data.session_time_remaining > 0) {
|
285 |
-
console.log(`
|
286 |
setTimeoutMessage(`⏰ Other users waiting. Time remaining: <span id="timeoutCountdown">${Math.ceil(data.session_time_remaining)}</span> seconds.`);
|
287 |
-
startTimeoutCountdown(Math.ceil(data.session_time_remaining), true); // true = hide stay connected button
|
288 |
}
|
289 |
} else if (data.type === "queue_update") {
|
290 |
console.log(`Queue update: Position ${data.position}/${data.total_waiting}, wait: ${data.maximum_wait_seconds.toFixed(1)} seconds`);
|
@@ -317,22 +317,23 @@
|
|
317 |
} else if (data.type === "session_warning") {
|
318 |
console.log(`Session time warning: ${data.time_remaining} seconds remaining`);
|
319 |
setTimeoutMessage(`Other users waiting. Time remaining: <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds.`);
|
320 |
-
startTimeoutCountdown(Math.ceil(data.time_remaining), true); // true = hide stay connected button
|
321 |
} else if (data.type === "idle_warning") {
|
322 |
console.log(`Idle warning: ${data.time_remaining} seconds until timeout`);
|
323 |
setTimeoutMessage(`No activity detected. Connection will be dropped in <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds and page will refresh automatically.`);
|
324 |
-
startTimeoutCountdown(Math.ceil(data.time_remaining), false); // false = show stay connected button
|
325 |
} else if (data.type === "grace_period") {
|
326 |
console.log(`Grace period: ${data.time_remaining} seconds remaining`);
|
327 |
setTimeoutMessage(`Other users waiting. Time remaining: <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds.`);
|
328 |
-
startTimeoutCountdown(Math.ceil(data.time_remaining), true); // true = hide stay connected button
|
329 |
} else if (data.type === "time_limit_removed") {
|
330 |
console.log("Time limit removed - queue became empty");
|
331 |
-
stopTimeoutCountdown();
|
|
|
332 |
} else if (data.type === "queue_limit_applied") {
|
333 |
console.log(`Queue limit applied, ${data.time_remaining} seconds remaining`);
|
334 |
setTimeoutMessage(`⏰ Other users waiting. Time remaining: <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds.`);
|
335 |
-
startTimeoutCountdown(Math.ceil(data.time_remaining), true); // true = hide stay connected button
|
336 |
} else if (data.type === "worker_failure") {
|
337 |
console.log("Worker failure detected, reconnecting...");
|
338 |
showConnectionStatus("🔄 GPU worker failed. Reconnecting to healthy worker...");
|
@@ -390,11 +391,18 @@
|
|
390 |
let autoInputEnabled = true; // Default to enabled
|
391 |
let userHasInteracted = false; // Track if user has moved mouse inside canvas
|
392 |
|
393 |
-
// Timeout countdown mechanism
|
394 |
let timeoutCountdownInterval = null;
|
395 |
let timeoutCountdown = 10;
|
396 |
let timeoutWarningActive = false;
|
397 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
// Queue waiting countdown mechanism
|
399 |
let queueCountdownInterval = null;
|
400 |
let queueWaitTime = 0;
|
@@ -481,12 +489,36 @@
|
|
481 |
}
|
482 |
}
|
483 |
|
484 |
-
function startTimeoutCountdown(initialTime = 10, hideStayConnectedButton = false) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
if (timeoutCountdownInterval) {
|
486 |
clearInterval(timeoutCountdownInterval);
|
487 |
}
|
488 |
|
489 |
-
timeoutCountdown =
|
490 |
timeoutWarningActive = true;
|
491 |
|
492 |
// Show warning
|
@@ -495,10 +527,10 @@
|
|
495 |
warning.style.display = 'block';
|
496 |
}
|
497 |
|
498 |
-
// Show/hide Stay Connected button based on
|
499 |
const stayConnectedButton = warning.querySelector('button');
|
500 |
if (stayConnectedButton) {
|
501 |
-
stayConnectedButton.style.display =
|
502 |
}
|
503 |
|
504 |
// Update initial display
|
@@ -507,26 +539,107 @@
|
|
507 |
countdownElement.textContent = timeoutCountdown;
|
508 |
}
|
509 |
|
|
|
|
|
510 |
// Start countdown
|
511 |
timeoutCountdownInterval = setInterval(() => {
|
512 |
-
|
513 |
-
const
|
514 |
-
|
515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
}
|
517 |
|
518 |
-
if (
|
519 |
stopAutoInput();
|
520 |
stopTimeoutCountdown();
|
521 |
-
//clearInterval(heartbeatInterval);
|
522 |
console.log("Connection timeout countdown finished - refreshing page");
|
523 |
// Refresh the page to reconnect
|
524 |
window.location.reload();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
}
|
526 |
}, 1000);
|
527 |
}
|
528 |
|
529 |
-
function stopTimeoutCountdown() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
530 |
if (timeoutCountdownInterval) {
|
531 |
clearInterval(timeoutCountdownInterval);
|
532 |
timeoutCountdownInterval = null;
|
@@ -618,7 +731,7 @@
|
|
618 |
console.error("Error sending stay connected ping:", error);
|
619 |
}
|
620 |
}
|
621 |
-
stopTimeoutCountdown();
|
622 |
}
|
623 |
|
624 |
function sendInputState(x, y, isLeftClick = false, isRightClick = false, keysDownArr = [], keysUpArr = [], wheelDeltaX = 0, wheelDeltaY = 0) {
|
|
|
275 |
} else if (data.type === "timeout_warning") {
|
276 |
console.log(`Received timeout warning: ${data.timeout_in} seconds remaining`);
|
277 |
setTimeoutMessage(`No activity detected. Connection will be dropped in <span id="timeoutCountdown">${data.timeout_in}</span> seconds and page will refresh automatically.`);
|
278 |
+
startTimeoutCountdown(data.timeout_in, false, 'idle'); // false = show stay connected button
|
279 |
} else if (data.type === "activity_reset") {
|
280 |
console.log("Server detected user activity, resetting timeout");
|
281 |
+
stopTimeoutCountdown('idle'); // Only clear idle timeout
|
282 |
|
283 |
+
// If there's still a session time limit active, update it
|
284 |
if (data.session_time_remaining && data.session_time_remaining > 0) {
|
285 |
+
console.log(`Updating session countdown: ${data.session_time_remaining} seconds remaining`);
|
286 |
setTimeoutMessage(`⏰ Other users waiting. Time remaining: <span id="timeoutCountdown">${Math.ceil(data.session_time_remaining)}</span> seconds.`);
|
287 |
+
startTimeoutCountdown(Math.ceil(data.session_time_remaining), true, 'session'); // true = hide stay connected button
|
288 |
}
|
289 |
} else if (data.type === "queue_update") {
|
290 |
console.log(`Queue update: Position ${data.position}/${data.total_waiting}, wait: ${data.maximum_wait_seconds.toFixed(1)} seconds`);
|
|
|
317 |
} else if (data.type === "session_warning") {
|
318 |
console.log(`Session time warning: ${data.time_remaining} seconds remaining`);
|
319 |
setTimeoutMessage(`Other users waiting. Time remaining: <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds.`);
|
320 |
+
startTimeoutCountdown(Math.ceil(data.time_remaining), true, 'session'); // true = hide stay connected button
|
321 |
} else if (data.type === "idle_warning") {
|
322 |
console.log(`Idle warning: ${data.time_remaining} seconds until timeout`);
|
323 |
setTimeoutMessage(`No activity detected. Connection will be dropped in <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds and page will refresh automatically.`);
|
324 |
+
startTimeoutCountdown(Math.ceil(data.time_remaining), false, 'idle'); // false = show stay connected button
|
325 |
} else if (data.type === "grace_period") {
|
326 |
console.log(`Grace period: ${data.time_remaining} seconds remaining`);
|
327 |
setTimeoutMessage(`Other users waiting. Time remaining: <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds.`);
|
328 |
+
startTimeoutCountdown(Math.ceil(data.time_remaining), true, 'grace'); // true = hide stay connected button
|
329 |
} else if (data.type === "time_limit_removed") {
|
330 |
console.log("Time limit removed - queue became empty");
|
331 |
+
stopTimeoutCountdown('session'); // Only clear session timeout
|
332 |
+
stopTimeoutCountdown('grace'); // Also clear grace period if active
|
333 |
} else if (data.type === "queue_limit_applied") {
|
334 |
console.log(`Queue limit applied, ${data.time_remaining} seconds remaining`);
|
335 |
setTimeoutMessage(`⏰ Other users waiting. Time remaining: <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds.`);
|
336 |
+
startTimeoutCountdown(Math.ceil(data.time_remaining), true, 'session'); // true = hide stay connected button
|
337 |
} else if (data.type === "worker_failure") {
|
338 |
console.log("Worker failure detected, reconnecting...");
|
339 |
showConnectionStatus("🔄 GPU worker failed. Reconnecting to healthy worker...");
|
|
|
391 |
let autoInputEnabled = true; // Default to enabled
|
392 |
let userHasInteracted = false; // Track if user has moved mouse inside canvas
|
393 |
|
394 |
+
// Timeout countdown mechanism - support concurrent timeouts
|
395 |
let timeoutCountdownInterval = null;
|
396 |
let timeoutCountdown = 10;
|
397 |
let timeoutWarningActive = false;
|
398 |
|
399 |
+
// Track concurrent timeout systems
|
400 |
+
let currentTimeouts = {
|
401 |
+
idle: null, // { remaining: 10, hideButton: false }
|
402 |
+
session: null, // { remaining: 60, hideButton: true }
|
403 |
+
grace: null // { remaining: 5, hideButton: true }
|
404 |
+
};
|
405 |
+
|
406 |
// Queue waiting countdown mechanism
|
407 |
let queueCountdownInterval = null;
|
408 |
let queueWaitTime = 0;
|
|
|
489 |
}
|
490 |
}
|
491 |
|
492 |
+
function startTimeoutCountdown(initialTime = 10, hideStayConnectedButton = false, timeoutType = 'idle') {
|
493 |
+
// Update the specific timeout type
|
494 |
+
currentTimeouts[timeoutType] = {
|
495 |
+
remaining: initialTime,
|
496 |
+
hideButton: hideStayConnectedButton,
|
497 |
+
type: timeoutType
|
498 |
+
};
|
499 |
+
|
500 |
+
// Find the timeout that will expire first
|
501 |
+
let earliestTimeout = null;
|
502 |
+
let earliestTime = Infinity;
|
503 |
+
|
504 |
+
for (const [type, timeout] of Object.entries(currentTimeouts)) {
|
505 |
+
if (timeout && timeout.remaining < earliestTime) {
|
506 |
+
earliestTime = timeout.remaining;
|
507 |
+
earliestTimeout = timeout;
|
508 |
+
}
|
509 |
+
}
|
510 |
+
|
511 |
+
if (!earliestTimeout) {
|
512 |
+
stopTimeoutCountdown();
|
513 |
+
return;
|
514 |
+
}
|
515 |
+
|
516 |
+
// Stop existing countdown
|
517 |
if (timeoutCountdownInterval) {
|
518 |
clearInterval(timeoutCountdownInterval);
|
519 |
}
|
520 |
|
521 |
+
timeoutCountdown = earliestTimeout.remaining;
|
522 |
timeoutWarningActive = true;
|
523 |
|
524 |
// Show warning
|
|
|
527 |
warning.style.display = 'block';
|
528 |
}
|
529 |
|
530 |
+
// Show/hide Stay Connected button based on the earliest timeout
|
531 |
const stayConnectedButton = warning.querySelector('button');
|
532 |
if (stayConnectedButton) {
|
533 |
+
stayConnectedButton.style.display = earliestTimeout.hideButton ? 'none' : 'inline-block';
|
534 |
}
|
535 |
|
536 |
// Update initial display
|
|
|
539 |
countdownElement.textContent = timeoutCountdown;
|
540 |
}
|
541 |
|
542 |
+
console.log(`Starting ${earliestTimeout.type} timeout countdown: ${timeoutCountdown} seconds`);
|
543 |
+
|
544 |
// Start countdown
|
545 |
timeoutCountdownInterval = setInterval(() => {
|
546 |
+
// Update all active timeouts
|
547 |
+
for (const [type, timeout] of Object.entries(currentTimeouts)) {
|
548 |
+
if (timeout) {
|
549 |
+
timeout.remaining--;
|
550 |
+
}
|
551 |
+
}
|
552 |
+
|
553 |
+
// Find the timeout that will expire first
|
554 |
+
let newEarliestTimeout = null;
|
555 |
+
let newEarliestTime = Infinity;
|
556 |
+
|
557 |
+
for (const [type, timeout] of Object.entries(currentTimeouts)) {
|
558 |
+
if (timeout && timeout.remaining > 0 && timeout.remaining < newEarliestTime) {
|
559 |
+
newEarliestTime = timeout.remaining;
|
560 |
+
newEarliestTimeout = timeout;
|
561 |
+
}
|
562 |
}
|
563 |
|
564 |
+
if (!newEarliestTimeout || newEarliestTimeout.remaining <= 0) {
|
565 |
stopAutoInput();
|
566 |
stopTimeoutCountdown();
|
|
|
567 |
console.log("Connection timeout countdown finished - refreshing page");
|
568 |
// Refresh the page to reconnect
|
569 |
window.location.reload();
|
570 |
+
return;
|
571 |
+
}
|
572 |
+
|
573 |
+
// Update display with the earliest timeout
|
574 |
+
timeoutCountdown = newEarliestTimeout.remaining;
|
575 |
+
const countdownElement = document.getElementById('timeoutCountdown');
|
576 |
+
if (countdownElement) {
|
577 |
+
countdownElement.textContent = timeoutCountdown;
|
578 |
+
}
|
579 |
+
|
580 |
+
// Update Stay Connected button visibility if the timeout type changed
|
581 |
+
if (newEarliestTimeout.type !== earliestTimeout.type) {
|
582 |
+
console.log(`Timeout type changed from ${earliestTimeout.type} to ${newEarliestTimeout.type}`);
|
583 |
+
const stayConnectedButton = warning.querySelector('button');
|
584 |
+
if (stayConnectedButton) {
|
585 |
+
stayConnectedButton.style.display = newEarliestTimeout.hideButton ? 'none' : 'inline-block';
|
586 |
+
}
|
587 |
+
|
588 |
+
// Update timeout message based on new timeout type
|
589 |
+
if (newEarliestTimeout.type === 'idle') {
|
590 |
+
setTimeoutMessage(`No activity detected. Connection will be dropped in <span id="timeoutCountdown">${newEarliestTimeout.remaining}</span> seconds and page will refresh automatically.`);
|
591 |
+
} else if (newEarliestTimeout.type === 'session' || newEarliestTimeout.type === 'grace') {
|
592 |
+
setTimeoutMessage(`⏰ Other users waiting. Time remaining: <span id="timeoutCountdown">${newEarliestTimeout.remaining}</span> seconds.`);
|
593 |
+
}
|
594 |
+
|
595 |
+
earliestTimeout = newEarliestTimeout;
|
596 |
}
|
597 |
}, 1000);
|
598 |
}
|
599 |
|
600 |
+
function stopTimeoutCountdown(timeoutType = null) {
|
601 |
+
if (timeoutType) {
|
602 |
+
// Clear specific timeout type
|
603 |
+
currentTimeouts[timeoutType] = null;
|
604 |
+
console.log(`Cleared ${timeoutType} timeout`);
|
605 |
+
|
606 |
+
// Check if any other timeouts are still active
|
607 |
+
let hasActiveTimeouts = false;
|
608 |
+
for (const [type, timeout] of Object.entries(currentTimeouts)) {
|
609 |
+
if (timeout && timeout.remaining > 0) {
|
610 |
+
hasActiveTimeouts = true;
|
611 |
+
break;
|
612 |
+
}
|
613 |
+
}
|
614 |
+
|
615 |
+
if (hasActiveTimeouts) {
|
616 |
+
// Restart countdown with remaining timeouts
|
617 |
+
// Find the earliest remaining timeout and restart with it
|
618 |
+
let earliestTimeout = null;
|
619 |
+
let earliestTime = Infinity;
|
620 |
+
|
621 |
+
for (const [type, timeout] of Object.entries(currentTimeouts)) {
|
622 |
+
if (timeout && timeout.remaining < earliestTime) {
|
623 |
+
earliestTime = timeout.remaining;
|
624 |
+
earliestTimeout = timeout;
|
625 |
+
}
|
626 |
+
}
|
627 |
+
|
628 |
+
if (earliestTimeout) {
|
629 |
+
startTimeoutCountdown(earliestTimeout.remaining, earliestTimeout.hideButton, earliestTimeout.type);
|
630 |
+
}
|
631 |
+
return;
|
632 |
+
}
|
633 |
+
} else {
|
634 |
+
// Clear all timeouts
|
635 |
+
currentTimeouts = {
|
636 |
+
idle: null,
|
637 |
+
session: null,
|
638 |
+
grace: null
|
639 |
+
};
|
640 |
+
console.log("Cleared all timeouts");
|
641 |
+
}
|
642 |
+
|
643 |
if (timeoutCountdownInterval) {
|
644 |
clearInterval(timeoutCountdownInterval);
|
645 |
timeoutCountdownInterval = null;
|
|
|
731 |
console.error("Error sending stay connected ping:", error);
|
732 |
}
|
733 |
}
|
734 |
+
stopTimeoutCountdown('idle'); // Only clear idle timeout, not session timeout
|
735 |
}
|
736 |
|
737 |
function sendInputState(x, y, isLeftClick = false, isRightClick = false, keysDownArr = [], keysUpArr = [], wheelDeltaX = 0, wheelDeltaY = 0) {
|