mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-26 23:12:34 +03:00
версия с решенными вопросами api взаимодействия веба
This commit is contained in:
119
src/App.svelte
119
src/App.svelte
@@ -158,14 +158,10 @@
|
|||||||
|
|
||||||
//configuration
|
//configuration
|
||||||
let configJson = [];
|
let configJson = [];
|
||||||
let configJsonBuf = [];
|
|
||||||
let configJsonFlag = false;
|
let configJsonFlag = false;
|
||||||
let configJsonStart = "/st/config.json";
|
|
||||||
|
|
||||||
let widgetsJson = [];
|
let widgetsJson = [];
|
||||||
let widgetsJsonBuf = [];
|
|
||||||
let widgetsJsonFlag = false;
|
let widgetsJsonFlag = false;
|
||||||
let widgetsJsonStart = "/st/widgets.json";
|
|
||||||
|
|
||||||
//web sockets
|
//web sockets
|
||||||
let socket = [];
|
let socket = [];
|
||||||
@@ -186,13 +182,45 @@
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
//navigation
|
//***********************************************************blob**************************************************************/
|
||||||
|
var MyBlobBuilder = function () {
|
||||||
|
this.parts = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
MyBlobBuilder.prototype.append = function (part) {
|
||||||
|
this.parts.push(part);
|
||||||
|
this.blob = undefined; // Invalidate the blob
|
||||||
|
};
|
||||||
|
|
||||||
|
MyBlobBuilder.prototype.getBlob = function () {
|
||||||
|
if (!this.blob) {
|
||||||
|
this.blob = new Blob(this.parts, { type: "binary" });
|
||||||
|
}
|
||||||
|
return this.blob;
|
||||||
|
};
|
||||||
|
|
||||||
|
MyBlobBuilder.prototype.clear = function () {
|
||||||
|
this.parts = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
//***********************************************************navigation********************************************************/
|
||||||
let currentPageName = undefined;
|
let currentPageName = undefined;
|
||||||
let dataReceivingInProgress = false;
|
var configJsonBlob = new MyBlobBuilder();
|
||||||
|
var widgetsJsonBlob = new MyBlobBuilder();
|
||||||
router.subscribe(handleNavigation);
|
router.subscribe(handleNavigation);
|
||||||
|
|
||||||
//****************************************************functions section********************************************************/
|
function handleNavigation() {
|
||||||
//*****************************************************************************************************************************/
|
clearData();
|
||||||
|
currentPageName = $router.path.toString();
|
||||||
|
console.log("[i]", "user on page:", currentPageName);
|
||||||
|
sendCurrentPageName();
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendCurrentPageName() {
|
||||||
|
if (wsSelected !== undefined) {
|
||||||
|
wsSendMsg(wsSelected, currentPageName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//****************************************************web sockets section******************************************************/
|
//****************************************************web sockets section******************************************************/
|
||||||
function connectToAllDevices() {
|
function connectToAllDevices() {
|
||||||
@@ -281,50 +309,51 @@
|
|||||||
socket[ws].addEventListener("message", function (event) {
|
socket[ws].addEventListener("message", function (event) {
|
||||||
if (typeof event.data === "string") {
|
if (typeof event.data === "string") {
|
||||||
let data = event.data;
|
let data = event.data;
|
||||||
}
|
|
||||||
if (event.data instanceof Blob) {
|
|
||||||
let reader = new FileReader();
|
|
||||||
reader.readAsText(event.data);
|
|
||||||
reader.onload = () => {
|
|
||||||
let result = reader.result;
|
|
||||||
//сборщик configJson пакетов========================================
|
//сборщик configJson пакетов========================================
|
||||||
if (result === "/st/config.json") {
|
if (data === "/st/config.json") {
|
||||||
configJsonFlag = true;
|
|
||||||
if (debug) console.log("[i]", "configJson start!");
|
if (debug) console.log("[i]", "configJson start!");
|
||||||
|
configJsonFlag = true;
|
||||||
}
|
}
|
||||||
if (configJsonFlag && result != "/st/config.json" && result != "/end/config.json") {
|
if (data === "/end/config.json") {
|
||||||
configJsonBuf = configJsonBuf + result;
|
|
||||||
}
|
|
||||||
if (result === "/end/config.json") {
|
|
||||||
configJsonFlag = false;
|
|
||||||
if (debug) console.log("[i]", "configJson end!");
|
if (debug) console.log("[i]", "configJson end!");
|
||||||
//if (debug) console.log("[i]", configJsonBuf);
|
configJsonFlag = false;
|
||||||
if (IsJsonParse(configJsonBuf)) {
|
var bb = configJsonBlob.getBlob();
|
||||||
configJson = JSON.parse(configJsonBuf);
|
let configJsonReader = new FileReader();
|
||||||
|
configJsonReader.readAsText(bb);
|
||||||
|
configJsonReader.onload = () => {
|
||||||
|
let configJsonResult = configJsonReader.result;
|
||||||
|
if (IsJsonParse(configJsonResult)) {
|
||||||
|
configJson = JSON.parse(configJsonResult);
|
||||||
configJson = configJson;
|
configJson = configJson;
|
||||||
if (debug) console.log("[i]", "configJson parced!");
|
if (debug) console.log("[i]", "configJson parced!");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
//сборщик widgetsJson пакетов========================================
|
//сборщик widgetsJson пакетов========================================
|
||||||
if (result === "/st/widgets.json") {
|
if (data === "/st/widgets.json") {
|
||||||
widgetsJsonFlag = true;
|
|
||||||
if (debug) console.log("[i]", "widgetsJson start!");
|
if (debug) console.log("[i]", "widgetsJson start!");
|
||||||
|
widgetsJsonFlag = true;
|
||||||
}
|
}
|
||||||
if (widgetsJsonFlag && result != "/st/widgets.json" && result != "/end/widgets.json") {
|
if (data === "/end/widgets.json") {
|
||||||
widgetsJsonBuf = widgetsJsonBuf + result;
|
|
||||||
}
|
|
||||||
if (result === "/end/widgets.json") {
|
|
||||||
widgetsJsonFlag = false;
|
|
||||||
if (debug) console.log("[i]", "widgetsJson end!");
|
if (debug) console.log("[i]", "widgetsJson end!");
|
||||||
//if (debug) console.log("[i]", widgetsJsonBuf);
|
widgetsJsonFlag = false;
|
||||||
if (IsJsonParse(widgetsJsonBuf)) {
|
var bb = widgetsJsonBlob.getBlob();
|
||||||
widgetsJson = JSON.parse(widgetsJsonBuf);
|
let widgetsJsonReader = new FileReader();
|
||||||
|
widgetsJsonReader.readAsText(bb);
|
||||||
|
widgetsJsonReader.onload = () => {
|
||||||
|
let widgetsJsonResult = widgetsJsonReader.result;
|
||||||
|
if (IsJsonParse(widgetsJsonResult)) {
|
||||||
|
widgetsJson = JSON.parse(widgetsJsonResult);
|
||||||
widgetsJson = widgetsJson;
|
widgetsJson = widgetsJson;
|
||||||
if (debug) console.log("[i]", "widgetsJson parced!");
|
if (debug) console.log("[i]", "widgetsJson parced!");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (event.data instanceof Blob) {
|
||||||
|
if (configJsonFlag) configJsonBlob.append(event.data);
|
||||||
|
if (widgetsJsonFlag) widgetsJsonBlob.append(event.data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
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");
|
||||||
@@ -347,9 +376,11 @@
|
|||||||
|
|
||||||
function clearData() {
|
function clearData() {
|
||||||
configJson = [];
|
configJson = [];
|
||||||
configJsonBuf = [];
|
configJsonBlob.clear();
|
||||||
widgetsJson = [];
|
widgetsJson = [];
|
||||||
widgetsJsonBuf = [];
|
widgetsJsonBlob.clear();
|
||||||
|
|
||||||
|
if (debug) console.log("[i]", "all app data cleared");
|
||||||
}
|
}
|
||||||
|
|
||||||
function wsPush(ws, topic, status) {
|
function wsPush(ws, topic, status) {
|
||||||
@@ -453,20 +484,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//***********************************************************navigation************************************************************/
|
|
||||||
function handleNavigation() {
|
|
||||||
clearData();
|
|
||||||
currentPageName = $router.path.toString();
|
|
||||||
console.log("[i]", "user on page:", currentPageName);
|
|
||||||
sendCurrentPageName();
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendCurrentPageName() {
|
|
||||||
if (wsSelected !== undefined) {
|
|
||||||
wsSendMsg(wsSelected, currentPageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//****************************************************************json************************************************************/
|
//****************************************************************json************************************************************/
|
||||||
function getJsonObject(array, number) {
|
function getJsonObject(array, number) {
|
||||||
let num = 0;
|
let num = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user