Обновление веб-интерфейса
This commit is contained in:
+3
-37
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user