Додан моніторінг застосунку

Додани веб компоненти карточок територій та повідомлень
This commit is contained in:
2025-12-08 00:14:56 +02:00
parent e41590546c
commit 85483b85bb
206 changed files with 2370 additions and 595 deletions

View File

@@ -9,11 +9,13 @@ const Cloud = {
Cloud.status = 'sync';
const uuid = localStorage.getItem("uuid");
if(!navigator.onLine) alert("[APP] Інтернет з'єднання відсутнє!")
if (Cloud.socket && Cloud.socket.readyState <= 1) return;
const ws = new WebSocket(CONFIG.wss, uuid);
Cloud.socket = ws;
ws.onopen = () => {
console.log("[WebSocket] З'єднання встановлено");
Cloud.status = 'ok';
@@ -25,10 +27,10 @@ const Cloud = {
}
}));
if(Cloud.reconnecting == true) {
Router.navigate(location.pathname);
if (Cloud.reconnecting == true) {
Cloud.reconnect();
}
Cloud.reconnecting = true;
Cloud.reconnectAttempts = 0;
clearTimeout(Cloud.reconnectTimeout);
@@ -37,7 +39,7 @@ const Cloud = {
ws.onmessage = (e) => {
const data = JSON.parse(e.data);
if (data.event === 'user_connected' && data.user.id !== USER.id) {
console.log(`Новий користувач: ${data.user.name}`);
console.log(`[WebSocket] Новий користувач: ${data.user.name}`);
}
if (data.event === 'message') {
switch (data.type) {
@@ -54,7 +56,7 @@ const Cloud = {
case "stand_update":
Stand_card.cloud.update(data);
break;
default:
break;
}
@@ -65,7 +67,7 @@ const Cloud = {
console.warn("[WebSocket] З'єднання розірвано");
Cloud.status = 'err';
if (!Cloud.reconnecting) return; // защита от дублирования
if (!Cloud.reconnecting) return; // захист від дублювання
if (Cloud.reconnectAttempts < 5) {
Cloud.reconnectAttempts++;
@@ -73,7 +75,7 @@ const Cloud = {
Cloud.reconnectTimeout = setTimeout(() => {
Cloud.start();
}, 1000);
}, 500);
} else {
Cloud.reconnecting = false;
@@ -90,6 +92,19 @@ const Cloud = {
ws.onerror = (err) => {
console.error("[WebSocket] Помилка", err);
Cloud.status = 'err';
ws.close();
};
},
async reconnect(){
switch (page) {
case "Territory_card":
Territory_card.reload();
break;
default:
Router.navigate(location.pathname);
break;
}
}
}