diff --git a/src/App.vue b/src/App.vue index a41df54..8b935ba 100644 --- a/src/App.vue +++ b/src/App.vue @@ -25,11 +25,15 @@ export default class App extends Vue { } = {}; mounted() { + this.connectWebsocket(); + } + + connectWebsocket() { let loc = window.location; const ws_uri: string = (loc.protocol === 'https:' ? 'wss://' : 'ws://') + loc.host + '/ws'; this.websocket = new WebSocket(ws_uri); - this.websocket.onmessage = (ev: MessageEvent) => { + this.websocket.addEventListener('message', (ev: MessageEvent) => { const event: messages.ExtendedMessage = JSON.parse(ev.data as string); console.log(event); @@ -39,8 +43,14 @@ export default class App extends Vue { this.$set(this.printers, event.printer, event.current); } else if ('history' in event) { this.$set(this.printers, event.printer, event.history); + } else if ('remote_ws_status' in event) { } - }; + }); + + this.websocket.addEventListener('close', () => { + console.log('Lost connection to server reconnecting in 5 sec'); + window.setTimeout(this.connectWebsocket, 5000); + }); } }