This commit is contained in:
Dmitry Borisenko
2022-01-25 01:41:29 +01:00
parent b1ffc86636
commit 1b3e6b02a5

View File

@@ -161,13 +161,11 @@
let configJsonBuf = []; let configJsonBuf = [];
let configJsonFlag = false; let configJsonFlag = false;
let configJsonStart = "/st/config.json"; let configJsonStart = "/st/config.json";
let configJsonEnd = "/end/config.json";
let widgetsJson = []; let widgetsJson = [];
let widgetsJsonBuf = []; let widgetsJsonBuf = [];
let widgetsJsonFlag = false; let widgetsJsonFlag = false;
let widgetsJsonStart = "/st/widgets.json"; let widgetsJsonStart = "/st/widgets.json";
let widgetsJsonEnd = "/end/widgets.json";
//web sockets //web sockets
let socket = []; let socket = [];
@@ -281,101 +279,52 @@
//socket[ws].send("HELLO"); //socket[ws].send("HELLO");
}); });
socket[ws].addEventListener("message", function (event) { socket[ws].addEventListener("message", function (event) {
let data;
if (typeof event.data === "string") { if (typeof event.data === "string") {
data = event.data; let data = event.data;
if (data === configJsonStart) {
if (debug) console.log("[i]", "start receiving configJson");
configJsonFlag = true;
}
if (data === widgetsJsonStart) {
if (debug) console.log("[i]", "start receiving widgetsJson");
widgetsJsonFlag = true;
}
} }
if (event.data instanceof Blob) { if (event.data instanceof Blob) {
if (debug) console.log("[i]", "binary frame");
let reader = new FileReader(); let reader = new FileReader();
reader.readAsText(event.data); reader.readAsText(event.data);
reader.onload = () => { reader.onload = () => {
let result = reader.result; let result = reader.result;
//сборщик configJson пакетов======================================== //сборщик configJson пакетов========================================
if (configJsonFlag) { if (result === "/st/config.json") {
configJsonFlag = true;
if (debug) console.log("[i]", "configJson start!");
}
if (configJsonFlag && result != "/st/config.json" && result != "/end/config.json") {
configJsonBuf = configJsonBuf + result; configJsonBuf = configJsonBuf + result;
if (result.includes("]")) { }
if (debug) console.log("[i]", "stop receiving configJson"); if (result === "/end/config.json") {
if (debug) console.log("[i]", configJsonBuf); configJsonFlag = false;
if (debug) console.log("[i]", "configJson end!");
//if (debug) console.log("[i]", configJsonBuf);
if (IsJsonParse(configJsonBuf)) { if (IsJsonParse(configJsonBuf)) {
configJson = JSON.parse(configJsonBuf); configJson = JSON.parse(configJsonBuf);
configJson = configJson; configJson = configJson;
if (debug) console.log("[i]", "configJson parced!"); if (debug) console.log("[i]", "configJson parced!");
configJsonFlag = false;
}
} }
} }
//сборщик widgetsJson пакетов======================================== //сборщик widgetsJson пакетов========================================
if (widgetsJsonFlag) { if (result === "/st/widgets.json") {
widgetsJsonFlag = true;
if (debug) console.log("[i]", "widgetsJson start!");
}
if (widgetsJsonFlag && result != "/st/widgets.json" && result != "/end/widgets.json") {
widgetsJsonBuf = widgetsJsonBuf + result; widgetsJsonBuf = widgetsJsonBuf + result;
if (result.includes("]")) { }
if (debug) console.log("[i]", "stop receiving widgetsJson"); if (result === "/end/widgets.json") {
if (debug) console.log("[i]", widgetsJsonBuf); widgetsJsonFlag = false;
if (debug) console.log("[i]", "widgetsJson end!");
//if (debug) console.log("[i]", widgetsJsonBuf);
if (IsJsonParse(widgetsJsonBuf)) { if (IsJsonParse(widgetsJsonBuf)) {
widgetsJson = JSON.parse(widgetsJsonBuf); widgetsJson = JSON.parse(widgetsJsonBuf);
widgetsJson = widgetsJson; widgetsJson = widgetsJson;
if (debug) console.log("[i]", "widgetsJson parced!"); if (debug) console.log("[i]", "widgetsJson parced!");
widgetsJsonFlag = false;
}
} }
} }
}; };
} }
//if (debug) console.log("[i]", "data:", data);
//if (data.includes("[log]")) {
// data = data.replace("[log]", "");
// addCoreMsg(data);
//}
//сборщик configJson пакетов========================================
//if (data === configJsonStart) {
// if (debug) console.log("[i]", "start receiving configJson");
// configJsonFlag = true;
// configJsonBuf = [];
// configJson = [];
//}
//if (configJsonFlag && data != configJsonStart && data != configJsonEnd) {
// configJsonBuf = configJsonBuf + data;
//}
//if (data === configJsonEnd) {
// if (debug) console.log("[i]", "comleted receiving configJson");
// configJsonFlag = false;
// if (IsJsonParse(configJsonBuf)) {
// configJson = JSON.parse(configJsonBuf);
// configJson = configJson;
// if (debug) console.log("[i]", "configJson parced!");
// }
// configJsonBuf = [];
//}
////сборщик widgetsJson пакетов========================================
//if (data === widgetsJsonStart) {
// if (debug) console.log("[i]", "start receiving widgetsJson");
// widgetsJsonFlag = true;
// widgetsJsonBuf = [];
// widgetsJson = [];
//}
//if (widgetsJsonFlag && data != widgetsJsonStart && data != widgetsJsonEnd) {
// widgetsJsonBuf = widgetsJsonBuf + data;
//}
//if (data === widgetsJsonEnd) {
// if (debug) console.log("[i]", "comleted receiving widgetsJson");
// widgetsJsonFlag = false;
// if (IsJsonParse(widgetsJsonBuf)) {
// widgetsJson = JSON.parse(widgetsJsonBuf);
// widgetsJson = widgetsJson;
// if (debug) console.log("[i]", "widgetsJson parced!");
// }
// widgetsJsonBuf = [];
//
//====================================================================
}); });
socket[ws].addEventListener("close", (event) => { socket[ws].addEventListener("close", (event) => {
if (debug) console.log("[e]", ip, "connection closed"); if (debug) console.log("[e]", ip, "connection closed");
@@ -392,19 +341,10 @@
function sendConfigJson() { function sendConfigJson() {
wsSendMsg(wsSelected, "/gifnoc.json" + JSON.stringify(configJson)); wsSendMsg(wsSelected, "/gifnoc.json" + JSON.stringify(configJson));
//wsSendMsg(wsSelected, "/gifnoc.json" + strencode(configJson));
clearData(); clearData();
sendCurrentPageName(); sendCurrentPageName();
} }
function strencode(data) {
return unescape(encodeURIComponent(JSON.stringify(data)));
}
function strdecode(data) {
return JSON.parse(decodeURIComponent(escape(data)));
}
function clearData() { function clearData() {
configJson = []; configJson = [];
configJsonBuf = []; configJsonBuf = [];