mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-26 15:02:21 +03:00
в процессе
This commit is contained in:
130
src/App.svelte
130
src/App.svelte
@@ -254,6 +254,7 @@
|
|||||||
if (debug) console.log("[e]", "device list wrong");
|
if (debug) console.log("[e]", "device list wrong");
|
||||||
} else {
|
} else {
|
||||||
socket[ws] = new WebSocket("ws://" + ip + ":81");
|
socket[ws] = new WebSocket("ws://" + ip + ":81");
|
||||||
|
socket.binaryType = "blob";
|
||||||
//socket[ws] = new WebSocket("ws://" + ip + "/ws");
|
//socket[ws] = new WebSocket("ws://" + ip + "/ws");
|
||||||
if (debug) console.log("[i]", ip, "started connecting...");
|
if (debug) console.log("[i]", ip, "started connecting...");
|
||||||
}
|
}
|
||||||
@@ -280,53 +281,100 @@
|
|||||||
//socket[ws].send("HELLO");
|
//socket[ws].send("HELLO");
|
||||||
});
|
});
|
||||||
socket[ws].addEventListener("message", function (event) {
|
socket[ws].addEventListener("message", function (event) {
|
||||||
let data = event.data.toString();
|
let data;
|
||||||
|
if (typeof event.data === "string") {
|
||||||
|
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 (debug) console.log("[i]", "binary frame");
|
||||||
|
let reader = new FileReader();
|
||||||
|
reader.readAsText(event.data);
|
||||||
|
reader.onload = () => {
|
||||||
|
let result = reader.result;
|
||||||
|
//сборщик configJson пакетов========================================
|
||||||
|
if (configJsonFlag) {
|
||||||
|
configJsonBuf = configJsonBuf + result;
|
||||||
|
if (result.includes("]")) {
|
||||||
|
if (debug) console.log("[i]", "stop receiving configJson");
|
||||||
|
if (debug) console.log("[i]", configJsonBuf);
|
||||||
|
if (IsJsonParse(configJsonBuf)) {
|
||||||
|
configJson = JSON.parse(configJsonBuf);
|
||||||
|
configJson = configJson;
|
||||||
|
if (debug) console.log("[i]", "configJson parced!");
|
||||||
|
configJsonFlag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//сборщик widgetsJson пакетов========================================
|
||||||
|
if (widgetsJsonFlag) {
|
||||||
|
widgetsJsonBuf = widgetsJsonBuf + result;
|
||||||
|
if (result.includes("]")) {
|
||||||
|
if (debug) console.log("[i]", "stop receiving widgetsJson");
|
||||||
|
if (debug) console.log("[i]", widgetsJsonBuf);
|
||||||
|
if (IsJsonParse(widgetsJsonBuf)) {
|
||||||
|
widgetsJson = JSON.parse(widgetsJsonBuf);
|
||||||
|
widgetsJson = widgetsJson;
|
||||||
|
if (debug) console.log("[i]", "widgetsJson parced!");
|
||||||
|
widgetsJsonFlag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
//if (debug) console.log("[i]", "data:", data);
|
//if (debug) console.log("[i]", "data:", data);
|
||||||
//if (data.includes("[log]")) {
|
//if (data.includes("[log]")) {
|
||||||
// data = data.replace("[log]", "");
|
// data = data.replace("[log]", "");
|
||||||
// addCoreMsg(data);
|
// addCoreMsg(data);
|
||||||
//}
|
//}
|
||||||
//сборщик configJson пакетов========================================
|
//сборщик configJson пакетов========================================
|
||||||
if (data === configJsonStart) {
|
//if (data === configJsonStart) {
|
||||||
if (debug) console.log("[i]", "start receiving configJson");
|
// if (debug) console.log("[i]", "start receiving configJson");
|
||||||
configJsonFlag = true;
|
// configJsonFlag = true;
|
||||||
configJsonBuf = [];
|
// configJsonBuf = [];
|
||||||
configJson = [];
|
// configJson = [];
|
||||||
}
|
//}
|
||||||
if (configJsonFlag && data != configJsonStart && data != configJsonEnd) {
|
//if (configJsonFlag && data != configJsonStart && data != configJsonEnd) {
|
||||||
//data = strdecode(data);
|
// configJsonBuf = configJsonBuf + data;
|
||||||
configJsonBuf = configJsonBuf + data;
|
//}
|
||||||
}
|
//if (data === configJsonEnd) {
|
||||||
if (data === configJsonEnd) {
|
// if (debug) console.log("[i]", "comleted receiving configJson");
|
||||||
if (debug) console.log("[i]", "comleted receiving configJson");
|
// configJsonFlag = false;
|
||||||
configJsonFlag = false;
|
// 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!");
|
// }
|
||||||
}
|
// configJsonBuf = [];
|
||||||
configJsonBuf = [];
|
//}
|
||||||
}
|
////сборщик widgetsJson пакетов========================================
|
||||||
//сборщик widgetsJson пакетов========================================
|
//if (data === widgetsJsonStart) {
|
||||||
if (data === widgetsJsonStart) {
|
// if (debug) console.log("[i]", "start receiving widgetsJson");
|
||||||
if (debug) console.log("[i]", "start receiving widgetsJson");
|
// widgetsJsonFlag = true;
|
||||||
widgetsJsonFlag = true;
|
// widgetsJsonBuf = [];
|
||||||
widgetsJsonBuf = [];
|
// widgetsJson = [];
|
||||||
widgetsJson = [];
|
//}
|
||||||
}
|
//if (widgetsJsonFlag && data != widgetsJsonStart && data != widgetsJsonEnd) {
|
||||||
if (widgetsJsonFlag && data != widgetsJsonStart && data != widgetsJsonEnd) {
|
// widgetsJsonBuf = widgetsJsonBuf + data;
|
||||||
widgetsJsonBuf = widgetsJsonBuf + data;
|
//}
|
||||||
}
|
//if (data === widgetsJsonEnd) {
|
||||||
if (data === widgetsJsonEnd) {
|
// if (debug) console.log("[i]", "comleted receiving widgetsJson");
|
||||||
if (debug) console.log("[i]", "comleted receiving widgetsJson");
|
// widgetsJsonFlag = false;
|
||||||
widgetsJsonFlag = false;
|
// 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!");
|
// }
|
||||||
}
|
// widgetsJsonBuf = [];
|
||||||
widgetsJsonBuf = [];
|
|
||||||
}
|
//
|
||||||
//====================================================================
|
//====================================================================
|
||||||
});
|
});
|
||||||
socket[ws].addEventListener("close", (event) => {
|
socket[ws].addEventListener("close", (event) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user