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