Исправил таймаут 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,29 +40,36 @@ export default {
reloadNavbar() {
this.$refs.navbar.getCtfServices();
},
connectWs() {
const wsUrl = this.$store.state.apiUrl + '/ws';
this.socket = new SockJS(wsUrl);
this.socket.onopen = function () {
console.debug('WS connected');
};
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);
console.debug('WS got message', parsed);
const currentPort = this.$route.params.servicePort;
if (!(currentPort === undefined || currentPort === parsed.service.port)) {
console.debug('not related port, skipping...');
return;
}
this.$refs.sidebar.onGotNewStream(parsed);
};
this.socket.onerror = function (ev) {
console.warn('WS err', ev);
};
},
},
mounted() {
const wsUrl = this.$store.state.apiUrl + '/ws';
this.socket = new SockJS(wsUrl);
this.socket.onopen = function () {
console.debug('WS connected');
};
this.socket.onclose = function (ev) {
console.debug('WS disconnected', ev.code, ev.reason);
};
this.socket.onmessage = ev => {
const parsed = JSON.parse(ev.data);
console.debug('WS got message', parsed);
const currentPort = this.$route.params.servicePort;
if (!(currentPort === undefined || currentPort === parsed.service.port)) {
console.debug('not related port, skipping...');
return;
}
this.$refs.sidebar.onGotNewStream(parsed);
};
this.socket.onerror = function (ev) {
console.warn('WS err', ev);
};
this.connectWs();
},
beforeDestroy() {
this.socket.close();