mirror of
https://github.com/Av0idD4rk/packmate.git
synced 2026-10-23 16:31:01 +00:00
Переподключение вебсокетов при обрыве
This commit is contained in:
parent
4c5522bbcc
commit
c9732eb5b4
@ -42,16 +42,22 @@
|
||||
},
|
||||
methods: {
|
||||
connectWs() {
|
||||
if (this.websocket !== null) return;
|
||||
this.websocket = new SockJS(this.$http.defaults.baseURL + '/ws');
|
||||
this.websocket.onopen = () => {
|
||||
console.info('[WS] Connected');
|
||||
};
|
||||
this.websocket.onclose = (ev) => {
|
||||
console.info('[WS] Disconnected', ev.code, ev.reason);
|
||||
this.websocket = null;
|
||||
if (ev.code === 1008) {
|
||||
console.info('[WS] Security timeout, reconnecting...');
|
||||
this.connectWs();
|
||||
}
|
||||
if (ev.code !== 1000) { // Normal closure
|
||||
setTimeout(this.connectWs, 3000);
|
||||
console.info('[WS] Reconnecting...');
|
||||
}
|
||||
};
|
||||
this.websocket.onmessage = (ev) => {
|
||||
const parsed = JSON.parse(ev.data);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user