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-05-31 04:03:12 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6037546b60ebfb57fec6ec0e4332c7f4614ca258
6037546b
1 parent
c841fd41
메세지 인터페이스 수정
메세지 인터페이스 수정
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
19 deletions
web/src/Message.ts
web/src/components/common/types.ts
web/src/pages/Login.tsx
web/src/pages/Rooms.tsx
web/src/Message.ts
deleted
100644 → 0
View file @
c841fd4
export
interface
MessageResponse
<
T
>
{
ok
:
boolean
;
reason
?:
string
;
result
?:
T
;
}
export
class
MessageType
{
static
readonly
LOGIN
=
"login"
;
static
readonly
ROOM_LIST_REQUEST
=
"room_list_request"
;
static
readonly
ROOM_JOIN
=
"room_join"
;
static
readonly
ROOM_LEAVE
=
"room_leave"
;
static
readonly
ROOM_USER_UPDATE
=
"room_user_update"
;
static
readonly
ROOM_CHAT
=
"room_chat"
;
}
web/src/components/common/types.ts
0 → 100644
View file @
6037546
export
interface
MessageResponse
<
T
>
{
ok
:
boolean
;
reason
?:
string
;
result
?:
T
;
}
export
const
MessageType
=
{
LOGIN
:
"login"
,
ROOM_LIST_REQUEST
:
"room_list_request"
,
ROOM_JOIN
:
"room_join"
,
ROOM_LEAVE
:
"room_leave"
,
ROOM_USER_UPDATE
:
"room_user_update"
,
ROOM_CHAT
:
"room_chat"
,
}
as
const
\ No newline at end of file
web/src/pages/Login.tsx
View file @
6037546
import React, { useContext, useState } from 'react';
import { RouteComponentProps } from 'react-router';
import { Footer } from '../components/common/Footer';
import
type { MessageRespons
e } from '../components/common/types';
import SocketContext from '../SocketContext';
import
{ MessageResponse, MessageTyp
e } from '../components/common/types';
import SocketContext from '../
contexts/
SocketContext';
export const Login: React.FC<RouteComponentProps> = ({ history }) => {
const socket = useContext(SocketContext);
const [ username, setUsername ] = useState("");
const login = () => {
socket.emit(
'login'
, username, (response : MessageResponse<null>) => {
socket.emit(
MessageType.LOGIN
, username, (response : MessageResponse<null>) => {
if (response.ok) {
history.push('/rooms');
} else {
...
...
web/src/pages/Rooms.tsx
View file @
6037546
import React, { useContext, useEffect, useState } from 'react';
import { RouteComponentProps } from 'react-router';
import
type
{ MessageResponse, MessageType } from '../components/common/types';
import { MessageResponse, MessageType } from '../components/common/types';
import SocketContext from '../contexts/SocketContext';
interface Room {
...
...
@@ -15,7 +15,7 @@ export const Rooms: React.FC<RouteComponentProps> = ({ history }) => {
const [ rooms, setRooms ] = useState<Room[]>([]);
const refreshRooms = () => {
socket.emit(
"room_list_request"
, (response: MessageResponse<Room[]>) => {
socket.emit(
MessageType.ROOM_LIST_REQUEST
, (response: MessageResponse<Room[]>) => {
if (response.ok) {
setRooms(response.result!);
} else {
...
...
Please
register
or
login
to post a comment