Skip to content

Commit

Permalink
fix(#63): 메세지 수신 조건 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
uiop5809 committed Sep 4, 2024
1 parent 8ba6a59 commit 41379ae
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/app/chatting/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ const Chatting = () => {
const [messages, setMessages] = useState<ChattingMessageI[]>([])

// 1. 메시지 수신 핸들러 함수
const handleWebSocketMessage = (
newMessage: ChattingMessageI,
roomId: number,
) => {
console.log('Received WebSocket message:', newMessage)
if (roomId === currentChatRoomId) {
const handleWebSocketMessage = (newMessage: ChattingMessageI) => {
if (userInfo && userInfo.id !== Number(newMessage.memberId)) {
setMessages((prevMessages) => [...prevMessages, newMessage])
}
}
Expand All @@ -41,7 +37,7 @@ const Chatting = () => {
if (socket) {
socket.onmessage = (event) => {
const newMessage = JSON.parse(event.data)
handleWebSocketMessage(newMessage, roomId)
handleWebSocketMessage(newMessage)
}
} else {
console.error(`WebSocket is not connected for key: ${key}`)
Expand Down

0 comments on commit 41379ae

Please sign in to comment.