Исправил таймаут WS

This commit is contained in:
saber-nyan 2019-05-11 00:45:14 +03:00
parent 43591bd269
commit 824bec994c
No known key found for this signature in database
GPG Key ID: 7B069E9C295E6B4A

View File

@ -40,8 +40,7 @@ export default {
reloadNavbar() {
this.$refs.navbar.getCtfServices();
},
},
mounted() {
connectWs() {
const wsUrl = this.$store.state.apiUrl + '/ws';
this.socket = new SockJS(wsUrl);
this.socket.onopen = function () {
@ -49,6 +48,10 @@ export default {
};
this.socket.onclose = function (ev) {
console.debug('WS disconnected', ev.code, ev.reason);
if (ev.code === 1008) {
console.info('Security timeout, reconnecting...');
this.connectWs();
}
};
this.socket.onmessage = ev => {
const parsed = JSON.parse(ev.data);
@ -64,6 +67,10 @@ export default {
console.warn('WS err', ev);
};
},
},
mounted() {
this.connectWs();
},
beforeDestroy() {
this.socket.close();
},