diff --git a/apps/frontend/src/components/ui/servers/PanelSpinner.vue b/apps/frontend/src/components/ui/servers/PanelSpinner.vue new file mode 100644 index 000000000..d9b5721de --- /dev/null +++ b/apps/frontend/src/components/ui/servers/PanelSpinner.vue @@ -0,0 +1,22 @@ + + + + + + diff --git a/apps/frontend/src/pages/servers/manage/[id].vue b/apps/frontend/src/pages/servers/manage/[id].vue index c287f90e1..1d6b0bb3d 100644 --- a/apps/frontend/src/pages/servers/manage/[id].vue +++ b/apps/frontend/src/pages/servers/manage/[id].vue @@ -1,5 +1,12 @@ + + + {{ errorTitle }} - {{ errorMessage }} + - - - {{ errorTitle }} - {{ errorMessage }} - + + Something went wrong... + + + + + Hang on, we're reconnecting to your server. + (null); +const isReconnecting = ref(false); +const reconnectInterval = ref | null>(null); const route = useNativeRoute(); const serverId = route.params.id as string; @@ -174,6 +191,12 @@ const connectWebSocket = () => { socket.value.onopen = () => { socket.value?.send(JSON.stringify({ event: "auth", jwt: wsAuth.value?.token })); + isConnected.value = true; + isReconnecting.value = false; + if (reconnectInterval.value) { + clearInterval(reconnectInterval.value); + reconnectInterval.value = null; + } }; socket.value.onmessage = (event) => { @@ -184,15 +207,28 @@ const connectWebSocket = () => { socket.value.onclose = () => { consoleOutput.value.push("\nWS connection closed"); isConnected.value = false; + scheduleReconnect(); }; socket.value.onerror = (error) => { console.error("WebSocket error:", error); isConnected.value = false; + scheduleReconnect(); }; } catch (error) { console.error("Failed to connect WebSocket:", error); isConnected.value = false; + scheduleReconnect(); + } +}; + +const scheduleReconnect = () => { + if (!reconnectInterval.value) { + isReconnecting.value = true; + reconnectInterval.value = setInterval(() => { + console.log("Attempting to reconnect..."); + connectWebSocket(); + }, 5000); } }; @@ -407,6 +443,12 @@ onMounted(() => { onUnmounted(() => { stopPolling(); + if (reconnectInterval.value) { + clearInterval(reconnectInterval.value); + } + if (socket.value) { + socket.value.close(); + } }); watch(