Обновление веб-интерфейса
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
class ControllerBase {
|
||||
ProcessResponse(response) {
|
||||
alert("Вызов нереализованного метода. Сообщите об этой ошибке разработчикам");
|
||||
}
|
||||
|
||||
constructor(url, path) {
|
||||
this.socket_ = new WebSocket(url + "/" + path);
|
||||
|
||||
// При создании сокета
|
||||
this.socket_.onopen = function(event) {
|
||||
console.log("connected to server");
|
||||
};
|
||||
|
||||
// При получении ответа
|
||||
var self = this;
|
||||
this.socket_.onmessage = function(event) {
|
||||
console.log(`received: '${event.data}'`);
|
||||
|
||||
let response = JSON.parse(event.data);
|
||||
self.ProcessResponse(response);
|
||||
};
|
||||
|
||||
// При закрытии сокета
|
||||
this.socket_.onclose = function(event) {
|
||||
if (event.wasClean)
|
||||
console.log("connection closed");
|
||||
else
|
||||
console.log("failed to close connection");
|
||||
};
|
||||
|
||||
// При ошибке
|
||||
this.socket_.onerror = function(error) {
|
||||
alert(`Возникла ошибка при подключении к серверу. Пожалуйста, сообщите о ней разработчикам: ${error}`);
|
||||
};
|
||||
}
|
||||
|
||||
SendRequestImpl(request) {
|
||||
this.socket_.send(request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user