diff --git a/src/App.vue b/src/App.vue index d001ea1..1fb9e3a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,7 +3,7 @@ - @@ -86,11 +86,10 @@ function actionMenuItemClick(event) { function handleOpenChange(keys) { openKeys.value = keys.length ? [keys[keys.length - 1]] : []; } + function setupEventWebSocket() { - // process.env.NODE_ENV === 'production' ? `/api/${name}` : `http://localhost:80/api/${name}` - // const ws = new WebSocket('ws://localhost:80/api/v1/app/ws/event'); - const ws = new WebSocket(process.env.NODE_ENV === 'production' ? `ws://${window.location.host}:80/api/v1/app/ws/event` - : `ws://localhost:80/api/v1/app/ws/event`); + let ws = createWebSocket('event'); + ws.onmessage = (event) => { let report = JSON.parse(event.data); console.info(report); @@ -107,16 +106,17 @@ function setupEventWebSocket() { width: 600, }); } + }; + ws.onclose = () => { + setTimeout(() => { + ws = createWebSocket('event'); + }, 1000); }; } - function setupStateUpdateWebSocket() { - // const ws = new WebSocket('ws://localhost:80/api/v1/app/ws/state'); - // const ws = new WebSocket(process.env.NODE_ENV === 'production' ? `/api/v1/app/ws/state` : `ws://localhost:80/api/v1/app/ws/state`); - const ws = new WebSocket(process.env.NODE_ENV === 'production' ? `ws://${window.location.host}:80/api/v1/app/ws/state` : - `ws://localhost:80/api/v1/app/ws/state`); + let ws = createWebSocket('state'); ws.onmessage = (event) => { const data = JSON.parse(event.data); @@ -139,6 +139,18 @@ function setupStateUpdateWebSocket() { } } }; + + ws.onclose = () => { + setTimeout(() => { + ws = createWebSocket('state'); + }, 1000); + }; +} + +function createWebSocket(type) { + const url = process.env.NODE_ENV === 'production' ? `ws://${window.location.host}:80/api/v1/app/ws/${type}` + : `ws://localhost:80/api/v1/app/ws/${type}`; + return new WebSocket(url); } function showMessageBoxList() {