Overnap

handleChatData 프로토콜에 맞게 수정

...@@ -11,12 +11,16 @@ export const Chat: React.FC = () => { ...@@ -11,12 +11,16 @@ export const Chat: React.FC = () => {
11 const messageEndRef = useRef<HTMLDivElement | null>(null); 11 const messageEndRef = useRef<HTMLDivElement | null>(null);
12 12
13 useEffect(() => { 13 useEffect(() => {
14 - socket.on(MessageType.ROOM_CHAT, (data: ChatData) => { 14 + const handleChatData = (message: RawMessage) => {
15 - setChatLines([...chatLines, data]); 15 + if (message.type === MessageType.ROOM_CHAT) {
16 - }); 16 + setChatLines(oldChatLines => [...oldChatLines, message.message as ChatData]);
17 + }
18 + }
19 +
20 + socket.on('msg', handleChatData);
17 21
18 return () => { 22 return () => {
19 - socket.off(MessageType.ROOM_CHAT); 23 + socket.off('msg', handleChatData);
20 } 24 }
21 }, []); 25 }, []);
22 26
...@@ -28,7 +32,7 @@ export const Chat: React.FC = () => { ...@@ -28,7 +32,7 @@ export const Chat: React.FC = () => {
28 32
29 const handleEnter = useCallback((e: React.KeyboardEvent) => { 33 const handleEnter = useCallback((e: React.KeyboardEvent) => {
30 if (e.key === 'Enter') { 34 if (e.key === 'Enter') {
31 - setChatLines([...chatLines, { sender: 'me', message: input }]); 35 + // setChatLines([...chatLines, { sender: 'me', message: input }]);
32 36
33 const rawMessage: RawMessage = { 37 const rawMessage: RawMessage = {
34 type: MessageType.ROOM_CHAT, 38 type: MessageType.ROOM_CHAT,
......