Showing
2 changed files
with
10 additions
and
6 deletions
... | @@ -12,7 +12,7 @@ export interface RawMessage { | ... | @@ -12,7 +12,7 @@ export interface RawMessage { |
12 | export const MessageType = { | 12 | export const MessageType = { |
13 | LOGIN: "login", | 13 | LOGIN: "login", |
14 | ROOM_LIST_REQUEST: "roomList", | 14 | ROOM_LIST_REQUEST: "roomList", |
15 | - ROOM_JOIN: "room_join", | 15 | + ROOM_JOIN: "joinRoom", |
16 | ROOM_LEAVE: "room_leave", | 16 | ROOM_LEAVE: "room_leave", |
17 | ROOM_USER_UPDATE: "room_user_update", | 17 | ROOM_USER_UPDATE: "room_user_update", |
18 | ROOM_CHAT: "room_chat", | 18 | ROOM_CHAT: "room_chat", | ... | ... |
1 | -import React, { useContext } from 'react'; | 1 | +import React, { useCallback, useContext } from 'react'; |
2 | import { useHistory } from 'react-router'; | 2 | import { useHistory } from 'react-router'; |
3 | import SocketContext from '../../contexts/SocketContext'; | 3 | import SocketContext from '../../contexts/SocketContext'; |
4 | -import { MessageResponse, MessageType } from '../common/types'; | 4 | +import { MessageResponse, MessageType, RawMessage } from '../common/types'; |
5 | import { RoomData } from '../room/types'; | 5 | import { RoomData } from '../room/types'; |
6 | import { Room } from './types'; | 6 | import { Room } from './types'; |
7 | 7 | ||
... | @@ -12,9 +12,13 @@ interface RoomBlockProps { | ... | @@ -12,9 +12,13 @@ interface RoomBlockProps { |
12 | export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => { | 12 | export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => { |
13 | const history = useHistory(); | 13 | const history = useHistory(); |
14 | const socket = useContext(SocketContext); | 14 | const socket = useContext(SocketContext); |
15 | - const joinRoom = () => { | 15 | + const joinRoom = useCallback(() => { |
16 | if (room.currentUsers < room.maxUsers) { | 16 | if (room.currentUsers < room.maxUsers) { |
17 | - socket.emit(MessageType.ROOM_JOIN, (response: MessageResponse<RoomData>) => { | 17 | + const rawMessage: RawMessage = { |
18 | + type: MessageType.ROOM_JOIN, | ||
19 | + message: { uuid: room.uuid } | ||
20 | + } | ||
21 | + socket.emit('msg', rawMessage, (response: MessageResponse<RoomData>) => { | ||
18 | if (response.ok) { | 22 | if (response.ok) { |
19 | history.push({ | 23 | history.push({ |
20 | pathname: '/' + room.uuid, | 24 | pathname: '/' + room.uuid, |
... | @@ -27,7 +31,7 @@ export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => { | ... | @@ -27,7 +31,7 @@ export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => { |
27 | } else { | 31 | } else { |
28 | //TODO: 자리 꽉찼다는 MODAL | 32 | //TODO: 자리 꽉찼다는 MODAL |
29 | } | 33 | } |
30 | - } | 34 | + }, []); |
31 | 35 | ||
32 | return ( | 36 | return ( |
33 | <button className={`flex items-center place-content-between m-2 w-5/6 | 37 | <button className={`flex items-center place-content-between m-2 w-5/6 | ... | ... |
-
Please register or login to post a comment