Fixed websocket reconnection logic

This commit is contained in:
Fabio Manganiello 2020-12-09 20:40:22 +01:00
parent fc718c907a
commit 79179746a7

View file

@ -28,12 +28,12 @@ export default {
methods: { methods: {
onWebsocketTimeout() { onWebsocketTimeout() {
return function() { console.log('Websocket reconnection timed out, retrying')
console.log('Websocket reconnection timed out, retrying') this.pending = false
this.pending = false if (this.ws)
this.close() this.ws.close()
this.onclose()
} this.onClose()
}, },
onMessage(event) { onMessage(event) {
@ -74,8 +74,10 @@ export default {
onOpen() { onOpen() {
if (this.opened) { if (this.opened) {
console.log("There's already an opened websocket connection, closing the newly opened one") console.log("There's already an opened websocket connection, closing the newly opened one")
this.onclose = () => {} if (this.ws) {
this.close() this.ws.onclose = () => {}
this.ws.close()
}
} }
console.log('Websocket connection successful') console.log('Websocket connection successful')