feat: improve session limit handling and add k6 load testing
This commit is contained in:
+14
-5
@@ -59,22 +59,31 @@ cat > /opt/portal/index.html <<HTML
|
||||
rfb.scaleViewport = true;
|
||||
rfb.resizeSession = true;
|
||||
const enableHeartbeat = "${ENABLE_HEARTBEAT}" === "1";
|
||||
const SESSION_CLOSED_URL = '/?session_closed=idle';
|
||||
const SESSION_CLOSED_URL_BASE = '/?session_closed=';
|
||||
const CLOSE_PATH = '${TOUCH_PATH}'.replace(/\/touch$/, '/close');
|
||||
function goSessionClosed() {
|
||||
function goSessionClosed(reason = 'idle') {
|
||||
const safeReason = reason === 'limit' ? 'limit' : 'idle';
|
||||
const target = `${SESSION_CLOSED_URL_BASE}${safeReason}`;
|
||||
try {
|
||||
if (window.top && window.top !== window) {
|
||||
window.top.location.href = SESSION_CLOSED_URL;
|
||||
window.top.location.href = target;
|
||||
return;
|
||||
}
|
||||
} catch (e) {}
|
||||
window.location.href = SESSION_CLOSED_URL;
|
||||
window.location.href = target;
|
||||
}
|
||||
async function touch() {
|
||||
try {
|
||||
const res = await fetch('${TOUCH_PATH}', {method:'POST', credentials:'include'});
|
||||
if (!res.ok) {
|
||||
goSessionClosed();
|
||||
let reason = 'idle';
|
||||
try {
|
||||
const payload = await res.json();
|
||||
if (payload && typeof payload.reason === 'string') {
|
||||
reason = payload.reason;
|
||||
}
|
||||
} catch (e) {}
|
||||
goSessionClosed(reason);
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user