Spaces:
Runtime error
Runtime error
da03
commited on
Commit
·
cd4cdde
1
Parent(s):
2ff6d31
- static/index.html +53 -5
static/index.html
CHANGED
@@ -93,7 +93,7 @@
|
|
93 |
<div class="canvas-container">
|
94 |
<div id="timeoutWarning" class="alert alert-warning" style="display: none; margin-bottom: 15px;">
|
95 |
<strong>Connection Timeout Warning:</strong>
|
96 |
-
No user activity detected. Connection will be dropped in <span id="timeoutCountdown">10</span> seconds and page will refresh automatically
|
97 |
<button type="button" class="btn btn-sm btn-primary ms-2" onclick="resetTimeout()">Stay Connected</button>
|
98 |
</div>
|
99 |
|
@@ -169,13 +169,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() {
|
@@ -267,10 +274,38 @@
|
|
267 |
document.getElementById('useRnnToggle').checked = data.use_rnn;
|
268 |
} else if (data.type === "timeout_warning") {
|
269 |
console.log(`Received timeout warning: ${data.timeout_in} seconds remaining`);
|
270 |
-
|
|
|
271 |
} else if (data.type === "activity_reset") {
|
272 |
console.log("Server detected user activity, resetting timeout");
|
273 |
stopTimeoutCountdown();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
}
|
275 |
};
|
276 |
}
|
@@ -401,12 +436,12 @@
|
|
401 |
}
|
402 |
}
|
403 |
|
404 |
-
function startTimeoutCountdown() {
|
405 |
if (timeoutCountdownInterval) {
|
406 |
clearInterval(timeoutCountdownInterval);
|
407 |
}
|
408 |
|
409 |
-
timeoutCountdown =
|
410 |
timeoutWarningActive = true;
|
411 |
|
412 |
// Show warning
|
@@ -415,6 +450,12 @@
|
|
415 |
warning.style.display = 'block';
|
416 |
}
|
417 |
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
// Start countdown
|
419 |
timeoutCountdownInterval = setInterval(() => {
|
420 |
timeoutCountdown--;
|
@@ -456,6 +497,13 @@
|
|
456 |
}
|
457 |
}
|
458 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
function resetTimeout() {
|
460 |
// Send a regular input to reset the server's timeout
|
461 |
if (socket && socket.readyState === WebSocket.OPEN && lastSentPosition) {
|
|
|
93 |
<div class="canvas-container">
|
94 |
<div id="timeoutWarning" class="alert alert-warning" style="display: none; margin-bottom: 15px;">
|
95 |
<strong>Connection Timeout Warning:</strong>
|
96 |
+
<span id="timeoutMessage">No user activity detected. Connection will be dropped in <span id="timeoutCountdown">10</span> seconds and page will refresh automatically.</span>
|
97 |
<button type="button" class="btn btn-sm btn-primary ms-2" onclick="resetTimeout()">Stay Connected</button>
|
98 |
</div>
|
99 |
|
|
|
169 |
}
|
170 |
|
171 |
// Function to show connection status
|
172 |
+
function showConnectionStatus(message, subtitle = null) {
|
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 - 10);
|
179 |
ctx.fillText(message, canvas.width/2, canvas.height/2);
|
180 |
+
|
181 |
+
if (subtitle) {
|
182 |
+
ctx.font = "14px Arial";
|
183 |
+
ctx.fillStyle = "#888888";
|
184 |
+
ctx.fillText(subtitle, canvas.width/2, canvas.height/2 + 15);
|
185 |
+
}
|
186 |
}
|
187 |
|
188 |
function connect() {
|
|
|
274 |
document.getElementById('useRnnToggle').checked = data.use_rnn;
|
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);
|
279 |
} else if (data.type === "activity_reset") {
|
280 |
console.log("Server detected user activity, resetting timeout");
|
281 |
stopTimeoutCountdown();
|
282 |
+
} else if (data.type === "queue_update") {
|
283 |
+
console.log(`Queue update: Position ${data.position}/${data.total_waiting}, estimated wait: ${data.estimated_wait_minutes.toFixed(1)} minutes`);
|
284 |
+
const waitMinutes = Math.ceil(data.estimated_wait_minutes);
|
285 |
+
const waitText = waitMinutes === 1 ? "1 minute" : `${waitMinutes} minutes`;
|
286 |
+
showConnectionStatus(
|
287 |
+
`Position ${data.position} in queue`,
|
288 |
+
`Estimated wait time: ${waitText}`
|
289 |
+
);
|
290 |
+
} else if (data.type === "session_start") {
|
291 |
+
console.log("Session started, clearing queue display");
|
292 |
+
// Clear the queue status display
|
293 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
294 |
+
} else if (data.type === "session_warning") {
|
295 |
+
console.log(`Session time warning: ${data.time_remaining} seconds remaining`);
|
296 |
+
setTimeoutMessage(`Session time limit reached. You will be disconnected in <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds due to queue waiting.`);
|
297 |
+
startTimeoutCountdown(Math.ceil(data.time_remaining));
|
298 |
+
} else if (data.type === "idle_warning") {
|
299 |
+
console.log(`Idle warning: ${data.time_remaining} seconds until timeout`);
|
300 |
+
setTimeoutMessage(`No activity detected. Connection will be dropped in <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds and page will refresh automatically.`);
|
301 |
+
startTimeoutCountdown(Math.ceil(data.time_remaining));
|
302 |
+
} else if (data.type === "grace_period") {
|
303 |
+
console.log(`Grace period: ${data.time_remaining} seconds remaining`);
|
304 |
+
setTimeoutMessage(`Grace period: Session will end in <span id="timeoutCountdown">${Math.ceil(data.time_remaining)}</span> seconds unless queue empties.`);
|
305 |
+
startTimeoutCountdown(Math.ceil(data.time_remaining));
|
306 |
+
} else if (data.type === "time_limit_removed") {
|
307 |
+
console.log("Time limit removed - queue became empty");
|
308 |
+
stopTimeoutCountdown();
|
309 |
}
|
310 |
};
|
311 |
}
|
|
|
436 |
}
|
437 |
}
|
438 |
|
439 |
+
function startTimeoutCountdown(initialTime = 10) {
|
440 |
if (timeoutCountdownInterval) {
|
441 |
clearInterval(timeoutCountdownInterval);
|
442 |
}
|
443 |
|
444 |
+
timeoutCountdown = initialTime;
|
445 |
timeoutWarningActive = true;
|
446 |
|
447 |
// Show warning
|
|
|
450 |
warning.style.display = 'block';
|
451 |
}
|
452 |
|
453 |
+
// Update initial display
|
454 |
+
const countdownElement = document.getElementById('timeoutCountdown');
|
455 |
+
if (countdownElement) {
|
456 |
+
countdownElement.textContent = timeoutCountdown;
|
457 |
+
}
|
458 |
+
|
459 |
// Start countdown
|
460 |
timeoutCountdownInterval = setInterval(() => {
|
461 |
timeoutCountdown--;
|
|
|
497 |
}
|
498 |
}
|
499 |
|
500 |
+
function setTimeoutMessage(message) {
|
501 |
+
const messageElement = document.getElementById('timeoutMessage');
|
502 |
+
if (messageElement) {
|
503 |
+
messageElement.innerHTML = message;
|
504 |
+
}
|
505 |
+
}
|
506 |
+
|
507 |
function resetTimeout() {
|
508 |
// Send a regular input to reset the server's timeout
|
509 |
if (socket && socket.readyState === WebSocket.OPEN && lastSentPosition) {
|