Обновление веб-интерфейса

This commit is contained in:
2024-02-21 11:45:53 +03:00
parent 4043250ca5
commit 20b3cea0b0
7 changed files with 61 additions and 52 deletions
+3 -37
View File
@@ -36,46 +36,12 @@ function InitDispatcher() {
window.dispatcher.AddCommand("statistics", window.statistics);
}
function InitSocket() {
// Создание сокета
window.is_socket_open = false;
window.socket = new WebSocket("ws://localhost:9555");
// При создании сокета
window.socket.onopen = function(event) {
console.log("connected to server");
window.is_socket_open = true;
};
// При получении ответа
window.socket.onmessage = function(event) {
console.log(`received: '${event.data}'`);
let response = JSON.parse(event.data);
window.dispatcher.Dispatch(response);
};
// При закрытии сокета
window.socket.onclose = function(event) {
if (event.wasClean)
console.log("connection closed");
else
console.log("failed to close connection");
};
// При ошибке
window.socket.onerror = function(error) {
alert(`Возникла ошибка при подключении к серверу. Пожалуйста, сообщите о ней разработчикам: ${error}`);
};
}
// Инициализация документа
document.addEventListener("DOMContentLoaded", function() {
InitSocket();
let url = "ws://localhost:9555";
InitStatistics();
InitAnomalyLogs();
InitStatistics(url);
InitAnomalyLogs(url);
InitDispatcher();