Update environment configurations for client and server, refactor ChatPopup to accept sessionId as a prop, enhance chat message handling with senderName and guestId, and improve error logging in chat message processing. Adjust useChatHistory and useWebRTC hooks for better state management and message retrieval.

This commit is contained in:
2025-10-30 19:27:35 +05:00
parent 1cacd070eb
commit 000c4caacb
11 changed files with 309 additions and 134 deletions
+22 -7
View File
@@ -10,22 +10,37 @@ interface ChatHistoryResponse {
}
export const useChatHistory = (sessionId: string | undefined, enabled = true) => {
console.log("[useChatHistory] Hook called with:", { sessionId, enabled, willExecute: enabled && !!sessionId });
return useQuery({
queryKey: ["chat-history", sessionId],
queryFn: async () => {
console.log("[useChatHistory] Fetching chat history for session:", sessionId);
if (!sessionId) {
console.error("[useChatHistory] Session ID is required but not provided");
throw new Error("Session ID is required");
}
const response = await api
.get(`sessions/${sessionId}/messages`)
.json<ChatHistoryResponse>();
try {
console.log("[useChatHistory] Making API request to:", `sessions/${sessionId}/messages`);
const response = await api
.get(`sessions/${sessionId}/messages`)
.json<ChatHistoryResponse>();
if (!response.success) {
throw new Error(response.error || "Failed to load chat history");
console.log("[useChatHistory] API response:", response);
if (!response.success) {
console.error("[useChatHistory] API returned error:", response.error);
throw new Error(response.error || "Failed to load chat history");
}
console.log("[useChatHistory] Successfully loaded", response.messages.length, "messages");
return response.messages;
} catch (error) {
console.error("[useChatHistory] Error fetching chat history:", error);
throw error;
}
return response.messages;
},
enabled: enabled && !!sessionId,
staleTime: 1000 * 60 * 5, // 5 минут - история считается актуальной
+2 -2
View File
@@ -202,9 +202,9 @@ export const useWebRTC = (roomId?: string, autoJoin = false) => {
setIsVideoMuted(!newState);
};
const sendMessage = (content: string) => {
const sendMessage = (content: string, senderName?: string, isAuthenticated?: boolean) => {
if (!webrtcServiceInstance) return;
webrtcServiceInstance.sendChatMessage(content);
webrtcServiceInstance.sendChatMessage(content, senderName, isAuthenticated);
};
const joinRoom = async (roomId: string) => {