20260719215738
This commit is contained in:
1 parent
35aa108a34
commit
cda7f16d3a
116 files changed
+11826
-3669
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { createContext, ReactNode, useCallback, useContext, useEffect, useRef } from "react";
|
||||
import { usePathname } from "expo-router";
|
||||
import { toast } from "sonner-native";
|
||||
import { useUserStore, useFamilyStore } from "@/store";
|
||||
import { useChatStore } from "@/store/chat";
|
||||
import { ChatMessage, OnlineUser, SendChatPayload, normalizeChatMessage } from "@/types/chat";
|
||||
@@ -45,10 +44,8 @@ function useChatWebSocketConnection(): ChatWebSocketValue {
|
||||
const userIdRef = useRef(userId);
|
||||
|
||||
const buildWsUrl = useCallback(() => {
|
||||
const apiUrl = process.env.EXPO_PUBLIC_API_URL || "";
|
||||
const wsProtocol = apiUrl.startsWith("https") ? "wss" : "ws";
|
||||
const host = apiUrl.replace(/^https?:\/\//, "");
|
||||
return `${wsProtocol}://${host}/chat/ws?token=${token}&family_id=${familyId}`;
|
||||
const base = process.env.EXPO_PUBLIC_WS_URL || "";
|
||||
return `${base}/chat/ws?token=${token}&family_id=${familyId}`;
|
||||
}, [token, familyId]);
|
||||
|
||||
const connect = useCallback(() => {
|
||||
@@ -63,9 +60,6 @@ function useChatWebSocketConnection(): ChatWebSocketValue {
|
||||
if (!mounted.current) return;
|
||||
useChatStore.getState().setConnected(true);
|
||||
reconnectDelay.current = RECONNECT_BASE;
|
||||
if (wasConnected.current) {
|
||||
toast.success("聊天已重连");
|
||||
}
|
||||
wasConnected.current = true;
|
||||
};
|
||||
|
||||
@@ -83,9 +77,6 @@ function useChatWebSocketConnection(): ChatWebSocketValue {
|
||||
if (!mounted.current) return;
|
||||
useChatStore.getState().setConnected(false);
|
||||
wsRef.current = null;
|
||||
if (wasConnected.current) {
|
||||
toast.error("聊天已断开");
|
||||
}
|
||||
if (shouldReconnect.current) {
|
||||
scheduleReconnect();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user