Enhance WebSocket handling and log polling logic
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -997,10 +997,43 @@ function initShellLayout() {
|
||||
setConnectionState("idle");
|
||||
SHELL_LAYOUT_READY = true;
|
||||
}
|
||||
function shouldPollLogs() {
|
||||
if (document.hidden == true) {
|
||||
return false;
|
||||
}
|
||||
if (document.getElementById("content_log") == null) {
|
||||
return false;
|
||||
}
|
||||
if (ACTIVE_MENU_ID.length < 1) {
|
||||
return false;
|
||||
}
|
||||
var activeItem = document.getElementById(ACTIVE_MENU_ID);
|
||||
if (activeItem == null) {
|
||||
return false;
|
||||
}
|
||||
return activeItem.getAttribute("data-menu") == "log";
|
||||
}
|
||||
function PageReady() {
|
||||
initShellLayout();
|
||||
var server = new Server("getServerConfig");
|
||||
server.request(new Object());
|
||||
var bootstrapAttempts = 0;
|
||||
var maxBootstrapAttempts = 5;
|
||||
var bootstrapTimer = window.setInterval(function () {
|
||||
if (SERVER.hasOwnProperty("clientInfo") == true) {
|
||||
window.clearInterval(bootstrapTimer);
|
||||
return;
|
||||
}
|
||||
if (SERVER_CONNECTION == true) {
|
||||
return;
|
||||
}
|
||||
bootstrapAttempts++;
|
||||
var retryServer = new Server("getServerConfig");
|
||||
retryServer.request(new Object());
|
||||
if (bootstrapAttempts >= maxBootstrapAttempts) {
|
||||
window.clearInterval(bootstrapTimer);
|
||||
}
|
||||
}, 3000);
|
||||
window.addEventListener("resize", function () {
|
||||
if (window.innerWidth > 900) {
|
||||
setLayoutMenuState(false);
|
||||
@@ -1008,7 +1041,7 @@ function PageReady() {
|
||||
calculateWrapperHeight();
|
||||
}, true);
|
||||
setInterval(function () {
|
||||
if (document.hidden == true) {
|
||||
if (shouldPollLogs() == false) {
|
||||
return;
|
||||
}
|
||||
updateLog();
|
||||
|
||||
@@ -27,6 +27,7 @@ var Server = /** @class */ (function () {
|
||||
}
|
||||
var url = this.protocol + wsHost + "/data/" + "?Token=" + getCookie("Token");
|
||||
data["cmd"] = this.cmd;
|
||||
var requestCmd = data["cmd"];
|
||||
var ws = new WebSocket(url);
|
||||
var isLogUpdate = data["cmd"] == "updateLog";
|
||||
var responseReceived = false;
|
||||
@@ -88,7 +89,7 @@ var Server = /** @class */ (function () {
|
||||
errorState = "idle";
|
||||
}
|
||||
finishRequest(errorState, false);
|
||||
if (WS_AVAILABLE == false && isLogUpdate == false) {
|
||||
if (WS_AVAILABLE == false && isLogUpdate == false && requestCmd != "getServerConfig") {
|
||||
alert("No websocket connection to xTeVe could be established. Check your network configuration.");
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user