Overnap

RawMessage 타입 추가하고 적용

...@@ -4,9 +4,14 @@ export interface MessageResponse<T> { ...@@ -4,9 +4,14 @@ export interface MessageResponse<T> {
4 result?: T; 4 result?: T;
5 } 5 }
6 6
7 +export interface RawMessage {
8 + type: string;
9 + message: any;
10 +}
11 +
7 export const MessageType = { 12 export const MessageType = {
8 LOGIN: "login", 13 LOGIN: "login",
9 - ROOM_LIST_REQUEST: "room_list_request", 14 + ROOM_LIST_REQUEST: "roomList",
10 ROOM_JOIN: "room_join", 15 ROOM_JOIN: "room_join",
11 ROOM_LEAVE: "room_leave", 16 ROOM_LEAVE: "room_leave",
12 ROOM_USER_UPDATE: "room_user_update", 17 ROOM_USER_UPDATE: "room_user_update",
......
1 import React, { useCallback, useContext, useState } from 'react'; 1 import React, { useCallback, useContext, useState } from 'react';
2 import { useHistory } from 'react-router'; 2 import { useHistory } from 'react-router';
3 import { Main } from '../components/common/Main'; 3 import { Main } from '../components/common/Main';
4 -import { MessageResponse, MessageType } from '../components/common/types'; 4 +import { MessageResponse, MessageType, RawMessage } from '../components/common/types';
5 import SocketContext from '../contexts/SocketContext'; 5 import SocketContext from '../contexts/SocketContext';
6 6
7 export const Login: React.FC = () => { 7 export const Login: React.FC = () => {
...@@ -10,9 +10,11 @@ export const Login: React.FC = () => { ...@@ -10,9 +10,11 @@ export const Login: React.FC = () => {
10 const [ username, setUsername ] = useState(""); 10 const [ username, setUsername ] = useState("");
11 11
12 const login = useCallback(() => { 12 const login = useCallback(() => {
13 - console.log("emitted."); 13 + const rawMessage: RawMessage = {
14 - socket.emit('msg', {type: MessageType.LOGIN, message: {username}}, (response : MessageResponse<undefined>) => { 14 + type: MessageType.LOGIN,
15 - console.log("responsed."); 15 + message: { username }
16 + }
17 + socket.emit('msg', rawMessage, (response : MessageResponse<undefined>) => {
16 if (response.ok) { 18 if (response.ok) {
17 history.push('/rooms'); 19 history.push('/rooms');
18 } else { 20 } else {
......
1 import React, { useCallback, useContext, useEffect, useState } from 'react'; 1 import React, { useCallback, useContext, useEffect, useState } from 'react';
2 import { Main } from '../components/common/Main'; 2 import { Main } from '../components/common/Main';
3 -import { MessageResponse, MessageType } from '../components/common/types'; 3 +import { MessageResponse, MessageType, RawMessage } from '../components/common/types';
4 import { RoomBlock } from '../components/rooms/RoomBlock'; 4 import { RoomBlock } from '../components/rooms/RoomBlock';
5 import { Room } from '../components/rooms/types'; 5 import { Room } from '../components/rooms/types';
6 import SocketContext from '../contexts/SocketContext'; 6 import SocketContext from '../contexts/SocketContext';
...@@ -10,12 +10,17 @@ export const Rooms: React.FC = () => { ...@@ -10,12 +10,17 @@ export const Rooms: React.FC = () => {
10 const [ rooms, setRooms ] = useState<Room[]>([]); 10 const [ rooms, setRooms ] = useState<Room[]>([]);
11 11
12 const refreshRooms = useCallback(() => { 12 const refreshRooms = useCallback(() => {
13 - socket.emit(MessageType.ROOM_LIST_REQUEST, (response: MessageResponse<Room[]>) => { 13 + const rawMessage: RawMessage = {
14 + type: MessageType.ROOM_LIST_REQUEST,
15 + message: {}
16 + }
17 + socket.emit('msg', rawMessage, (response: MessageResponse<Room[]>) => {
14 if (response.ok) { 18 if (response.ok) {
15 setRooms(response.result!); 19 setRooms(response.result!);
16 } else { 20 } else {
17 // TODO: 에러 핸들링 21 // TODO: 에러 핸들링
18 console.log("방 목록을 수신하지 못함"); 22 console.log("방 목록을 수신하지 못함");
23 + console.log(response);
19 } 24 }
20 }); 25 });
21 }, []); 26 }, []);
......