🐛 Websocket auto reconnecting
This commit is contained in:
parent
9ad11f4297
commit
49bd6ea363
@ -6,6 +6,7 @@ import { useRoute } from "vue-router"
|
|||||||
|
|
||||||
export const useChannels = defineStore("channels", () => {
|
export const useChannels = defineStore("channels", () => {
|
||||||
let socket: WebSocket
|
let socket: WebSocket
|
||||||
|
let reconnectCount = 0
|
||||||
|
|
||||||
const done = ref(false)
|
const done = ref(false)
|
||||||
|
|
||||||
@ -69,9 +70,16 @@ export const useChannels = defineStore("channels", () => {
|
|||||||
|
|
||||||
socket.addEventListener("open", (event) => {
|
socket.addEventListener("open", (event) => {
|
||||||
console.log("[MESSAGING] The unified websocket has been established... ", event.type)
|
console.log("[MESSAGING] The unified websocket has been established... ", event.type)
|
||||||
|
reconnectCount = 0
|
||||||
})
|
})
|
||||||
socket.addEventListener("close", (event) => {
|
socket.addEventListener("close", (event) => {
|
||||||
console.warn("[MESSAGING] The unified websocket is disconnected... ", event.reason, event.code)
|
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) => {
|
socket.addEventListener("message", (event) => {
|
||||||
const data = JSON.parse(event.data)
|
const data = JSON.parse(event.data)
|
||||||
|
@ -7,6 +7,7 @@ import { Capacitor } from "@capacitor/core"
|
|||||||
|
|
||||||
export const useNotifications = defineStore("notifications", () => {
|
export const useNotifications = defineStore("notifications", () => {
|
||||||
let socket: WebSocket
|
let socket: WebSocket
|
||||||
|
let reconnectCount = 0
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
@ -48,9 +49,16 @@ export const useNotifications = defineStore("notifications", () => {
|
|||||||
|
|
||||||
socket.addEventListener("open", (event) => {
|
socket.addEventListener("open", (event) => {
|
||||||
console.log("[NOTIFICATIONS] The listen websocket has been established... ", event.type)
|
console.log("[NOTIFICATIONS] The listen websocket has been established... ", event.type)
|
||||||
|
reconnectCount = 0
|
||||||
})
|
})
|
||||||
socket.addEventListener("close", (event) => {
|
socket.addEventListener("close", (event) => {
|
||||||
console.warn("[NOTIFICATIONS] The listen websocket is disconnected... ", event.reason, event.code)
|
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) => {
|
socket.addEventListener("message", (event) => {
|
||||||
const data = JSON.parse(event.data)
|
const data = JSON.parse(event.data)
|
||||||
|
Reference in New Issue
Block a user