diff --git a/src/stores/channels.ts b/src/stores/channels.ts index 1c690ea..c9f637c 100644 --- a/src/stores/channels.ts +++ b/src/stores/channels.ts @@ -6,6 +6,7 @@ import { useRoute } from "vue-router" export const useChannels = defineStore("channels", () => { let socket: WebSocket + let reconnectCount = 0 const done = ref(false) @@ -69,9 +70,16 @@ export const useChannels = defineStore("channels", () => { socket.addEventListener("open", (event) => { console.log("[MESSAGING] The unified websocket has been established... ", event.type) + reconnectCount = 0 }) socket.addEventListener("close", (event) => { console.warn("[MESSAGING] The unified websocket is disconnected... ", event.reason, event.code) + if(reconnectCount <= 3) { + connect().then(() => { + console.warn("[MESSAGING] Now reconnecting!") + reconnectCount++ + }) + } }) socket.addEventListener("message", (event) => { const data = JSON.parse(event.data) diff --git a/src/stores/notifications.ts b/src/stores/notifications.ts index d0fdf3f..ce5d67e 100644 --- a/src/stores/notifications.ts +++ b/src/stores/notifications.ts @@ -7,6 +7,7 @@ import { Capacitor } from "@capacitor/core" export const useNotifications = defineStore("notifications", () => { let socket: WebSocket + let reconnectCount = 0 const loading = ref(false) @@ -48,9 +49,16 @@ export const useNotifications = defineStore("notifications", () => { socket.addEventListener("open", (event) => { console.log("[NOTIFICATIONS] The listen websocket has been established... ", event.type) + reconnectCount = 0 }) socket.addEventListener("close", (event) => { console.warn("[NOTIFICATIONS] The listen websocket is disconnected... ", event.reason, event.code) + if(reconnectCount <= 3) { + connect().then(() => { + console.warn("[NOTIFICATIONS] Now reconnecting!") + reconnectCount++ + }) + } }) socket.addEventListener("message", (event) => { const data = JSON.parse(event.data)