dynamic
This commit is contained in:
+43
-5
@@ -601,18 +601,43 @@
|
||||
if (ws) {
|
||||
ws.close();
|
||||
}
|
||||
// Используем wss для соответствия HTTPS
|
||||
ws = new WebSocket(`wss://${window.location.host}/ws`);
|
||||
ws.onmessage = function(event) {
|
||||
allInstalls = JSON.parse(event.data);
|
||||
displayInstalls(allInstalls.filter(i => !selectedFolderId || i.folder_id == selectedFolderId));
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === "update") {
|
||||
const updatedInstall = data.data;
|
||||
const index = allInstalls.findIndex(i => i.id === updatedInstall.id);
|
||||
if (index !== -1) {
|
||||
allInstalls[index] = updatedInstall;
|
||||
} else {
|
||||
allInstalls.push(updatedInstall);
|
||||
alert(`Новое подключение добавлено: ${updatedInstall.computer_name} (ID: ${updatedInstall.rust_id})`);
|
||||
}
|
||||
displayInstalls(allInstalls.filter(i => !selectedFolderId || i.folder_id == selectedFolderId));
|
||||
}
|
||||
};
|
||||
ws.onerror = function(error) {
|
||||
console.error('WebSocket error:', error);
|
||||
};
|
||||
ws.onclose = function() {
|
||||
console.log('WebSocket disconnected, retrying in 5 seconds...');
|
||||
setTimeout(connectWebSocket, 5000);
|
||||
console.log('WebSocket disconnected, retrying...');
|
||||
let retryDelay = 1000; // Начальная задержка 1 секунда
|
||||
const maxDelay = 30000; // Максимальная задержка 30 секунд
|
||||
const maxAttempts = 10;
|
||||
let attempts = 0;
|
||||
|
||||
function reconnect() {
|
||||
if (attempts < maxAttempts) {
|
||||
setTimeout(() => {
|
||||
connectWebSocket();
|
||||
retryDelay = Math.min(retryDelay * 2, maxDelay);
|
||||
attempts++;
|
||||
}, retryDelay);
|
||||
} else {
|
||||
console.error('Max reconnect attempts reached');
|
||||
}
|
||||
}
|
||||
reconnect();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1162,6 +1187,19 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function startPeriodicSync() {
|
||||
setInterval(() => {
|
||||
$.getJSON(`${API_URL}/installs`, function (data) {
|
||||
allInstalls = data;
|
||||
displayInstalls(allInstalls.filter(i => !selectedFolderId || i.folder_id == selectedFolderId));
|
||||
}).fail(function(jqxhr, textStatus, error) {
|
||||
console.error("Error syncing installs:", textStatus, error);
|
||||
});
|
||||
}, 60000); // Каждые 60 секунд
|
||||
}
|
||||
|
||||
startPeriodicSync();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user