Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강동현
/
nodejs-game
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Overnap
2021-06-08 04:41:13 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
aea829f602a740e022c1c016cbffcf9047ee0f24
aea829f6
1 parent
0d4e90c7
handleChatData 프로토콜에 맞게 수정
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
web/src/components/room/Chat.tsx
web/src/components/room/Chat.tsx
View file @
aea829f
...
...
@@ -11,12 +11,16 @@ export const Chat: React.FC = () => {
const messageEndRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
socket.on(MessageType.ROOM_CHAT, (data: ChatData) => {
setChatLines([...chatLines, data]);
});
const handleChatData = (message: RawMessage) => {
if (message.type === MessageType.ROOM_CHAT) {
setChatLines(oldChatLines => [...oldChatLines, message.message as ChatData]);
}
}
socket.on('msg', handleChatData);
return () => {
socket.off(
MessageType.ROOM_CHAT
);
socket.off(
'msg', handleChatData
);
}
}, []);
...
...
@@ -28,7 +32,7 @@ export const Chat: React.FC = () => {
const handleEnter = useCallback((e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
setChatLines([...chatLines, { sender: 'me', message: input }]);
//
setChatLines([...chatLines, { sender: 'me', message: input }]);
const rawMessage: RawMessage = {
type: MessageType.ROOM_CHAT,
...
...
Please
register
or
login
to post a comment