Overnap

메세지 인터페이스 추가

1 import React, { useContext, useState } from 'react'; 1 import React, { useContext, useState } from 'react';
2 import { RouteComponentProps } from 'react-router'; 2 import { RouteComponentProps } from 'react-router';
3 import { Footer } from './Footer'; 3 import { Footer } from './Footer';
4 +import { MessageResponse } from './Message';
4 import SocketContext from './SocketContext'; 5 import SocketContext from './SocketContext';
5 6
6 export const Login: React.FC<RouteComponentProps> = ({ history }) => { 7 export const Login: React.FC<RouteComponentProps> = ({ history }) => {
...@@ -8,8 +9,8 @@ export const Login: React.FC<RouteComponentProps> = ({ history }) => { ...@@ -8,8 +9,8 @@ export const Login: React.FC<RouteComponentProps> = ({ history }) => {
8 const [ username, setUsername ] = useState(""); 9 const [ username, setUsername ] = useState("");
9 10
10 const login = () => { 11 const login = () => {
11 - socket.emit('login', username, ({ ok } : { ok: boolean }) => { 12 + socket.emit('login', username, (response : MessageResponse<null>) => {
12 - if (ok) { 13 + if (response.ok) {
13 history.push('/rooms'); 14 history.push('/rooms');
14 } else { 15 } else {
15 console.error('login error!'); // TODO: 팝업 에러? 16 console.error('login error!'); // TODO: 팝업 에러?
......
1 +export interface MessageResponse<T> {
2 + ok: boolean;
3 + reason?: string;
4 + result?: T;
5 +}
6 +
7 +export class MessageType {
8 + static readonly LOGIN = "login";
9 + static readonly ROOM_LIST_REQUEST = "room_list_request";
10 + static readonly ROOM_JOIN = "room_join";
11 + static readonly ROOM_LEAVE = "room_leave";
12 + static readonly ROOM_USER_UPDATE = "room_user_update";
13 + static readonly ROOM_CHAT = "room_chat";
14 +}