|
|
@@ -1,6 +1,7 @@
|
|
|
import { defineStore } from "pinia";
|
|
|
import { ref } from "vue";
|
|
|
import { getCurrentUser } from "@/lib/api";
|
|
|
+import { getWsUrl } from "@/lib/utils";
|
|
|
import { toast } from "vue-sonner";
|
|
|
|
|
|
export const useAuthStore = defineStore("auth", () => {
|
|
|
@@ -32,11 +33,9 @@ export const useAuthStore = defineStore("auth", () => {
|
|
|
let pingInterval: number | null = null;
|
|
|
const unreadMessagesCount = ref(0);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
let globalWs: WebSocket | null = null;
|
|
|
let reconnectTimer: number | null = null;
|
|
|
- const WS_BASE_URL = import.meta.env.VITE_WS_URL || "ws://localhost:8000";
|
|
|
+ const WS_BASE_URL = getWsUrl();
|
|
|
|
|
|
// ── Audio ──────────────────────────────────────────────────────────────────
|
|
|
// Single shared AudioContext, created lazily on first user gesture.
|
|
|
@@ -200,8 +199,12 @@ export const useAuthStore = defineStore("auth", () => {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (user.value && !wsAuthFailed.value) { // If still logged in and no auth error, try reconnecting
|
|
|
- reconnectTimer = window.setTimeout(startPing, 5000);
|
|
|
+ if (user.value) {
|
|
|
+ // If still logged in, try reconnecting.
|
|
|
+ // We only don't reconnect if wsAuthFailed is set during onclose for specific codes.
|
|
|
+ if (!wsAuthFailed.value) {
|
|
|
+ reconnectTimer = window.setTimeout(startPing, 5000);
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|