Skip to content

Commit d9a7be7

Browse files
committed
Add support for continuing chat with existing WebSocket connection
1 parent 04c8b73 commit d9a7be7

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/app/(layout)/chat/page.jsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useRouter } from "next/navigation";
44
import Chatlist from "@/components/Chatlist";
55
import Image from "next/image";
66
import ChatMessages from "@/components/ChatMessages";
7-
import { newChatWebSocket } from "@/lib/websocket";
7+
import { newChatWebSocket, continueChatWebSocket } from "@/lib/websocket";
88

99
export default function MainPage() {
1010
const router = useRouter();
@@ -111,14 +111,25 @@ export default function MainPage() {
111111
console.log("메타데이터:", id, title, description);
112112
}
113113

114-
// WebSocket 연결 설정
115-
const socket = newChatWebSocket(
116-
formData.content,
117-
localStorage.getItem("jwtToken"),
118-
modelNameHandler,
119-
modelResponseHandler,
120-
metadataHandler
121-
);
114+
if (chat.chatList.length > 0) {
115+
// 기존 채팅이 있는 경우
116+
const socket = continueChatWebSocket(
117+
chat.chattingId,
118+
formData.content,
119+
localStorage.getItem("jwtToken"),
120+
modelNameHandler,
121+
modelResponseHandler
122+
);
123+
} else {
124+
// WebSocket 연결 설정
125+
const socket = newChatWebSocket(
126+
formData.content,
127+
localStorage.getItem("jwtToken"),
128+
modelNameHandler,
129+
modelResponseHandler,
130+
metadataHandler
131+
);
132+
}
122133
};
123134

124135
const handleInputKeyDown = (e) => {

0 commit comments

Comments
 (0)