返回提交历史
Modified
static/webui/script.js
+16
-5
XFEstudio/SpaceNinjaServer
chore(webui): assume server config may have changed when reconnected (#3250)
Closes #3248 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3250 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
285b8d24
代码差异
1 个文件
+16
-5
@@ -11,7 +11,8 @@
11
11
let auth_pending = false,
12
12
did_initial_auth = false,
13
13
ws_is_open = false,
14
wsid = 0;
14
wsid = 0,
15
ws_reconnect = false;
15
16
const sendAuth = isRegister => {
16
17
if (ws_is_open && localStorage.getItem("email") && localStorage.getItem("password")) {
17
18
auth_pending = true;
@@ -52,10 +53,7 @@ function openWebSocket() {
52
53
location.port = location.protocol == "https:" ? msg.ports.https : msg.ports.http;
53
54
}
54
55
if ("config_reloaded" in msg) {
55
//window.is_admin = undefined;
56
if (single.getCurrentPath() == "/webui/cheats") {
57
single.loadRoute("/webui/cheats");
58
}
56
refreshServerConfig();
59
57
}
60
58
if ("auth_succ" in msg) {
61
59
auth_pending = false;
@@ -75,6 +73,11 @@ function openWebSocket() {
75
73
did_initial_auth = true;
76
74
updateInventory();
77
75
}
76
if (ws_reconnect) {
77
ws_reconnect = false;
78
// Config may have changed during the time we were disconnected.
79
refreshServerConfig();
80
}
78
81
}
79
82
if ("auth_fail" in msg) {
80
83
auth_pending = false;
@@ -108,11 +111,19 @@ function openWebSocket() {
108
111
};
109
112
window.ws.onclose = function () {
110
113
ws_is_open = false;
114
ws_reconnect = true;
111
115
setTimeout(openWebSocket, 3000);
112
116
};
113
117
}
114
118
openWebSocket();
115
119
120
function refreshServerConfig() {
121
//window.is_admin = undefined;
122
if (single.getCurrentPath() == "/webui/cheats") {
123
single.loadRoute("/webui/cheats");
124
}
125
}
126
116
127
function getWebSocket() {
117
128
return new Promise(resolve => {
118
129
let interval;