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 03:19:15 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c16ed2fb221bbaac34a70fc5499d8e5ed8f5c80f
c16ed2fb
1 parent
b25168cf
handleUpdateRoomUser 프로토콜에 맞게 수정
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
web/src/components/room/RoomInfo.tsx
web/src/components/room/RoomInfo.tsx
View file @
c16ed2f
...
...
@@ -20,33 +20,36 @@ export const RoomInfo: React.FC = () => {
users: []
});
const handleUpdateRoomUser = useCallback((data: UpdateRoomUser) => {
if (data.state == 'added') {
setRoomData({
...roomData,
users: [data.user, ...roomData.users] // TODO: immutable.js로 바꾸면 좋을 듯
});
} else if (data.state == 'removed') {
const newUsers = roomData.users;
const index = newUsers.indexOf(data.user);
if (index < 0) {
console.log('존재하지 않는 유저를 제거 시도');
} else {
newUsers.splice(index, 1);
const handleUpdateRoomUser = useCallback((rawMessage: RawMessage) => {
if (rawMessage.type == MessageType.ROOM_USER_UPDATE) {
const data = rawMessage.message as UpdateRoomUser;
if (data.state == 'added') {
setRoomData({
...roomData,
users: [data.user, ...roomData.users] // TODO: immutable.js로 바꾸면 좋을 듯
});
} else if (data.state == 'removed') {
const newUsers = roomData.users;
const index = newUsers.indexOf(data.user);
if (index < 0) {
console.log('존재하지 않는 유저를 제거 시도');
} else {
newUsers.splice(index, 1);
}
setRoomData({
...roomData,
users: newUsers
});
}
setRoomData({
...roomData,
users: newUsers
});
}
}, []);
useEffect(() => {
setRoomData(location.state.roomData);
socket.on(
MessageType.ROOM_USER_UPDATE
, handleUpdateRoomUser);
socket.on(
'msg'
, handleUpdateRoomUser);
return () => {
socket.off(
MessageType.ROOM_USER_UPDATE
, handleUpdateRoomUser);
socket.off(
'msg'
, handleUpdateRoomUser);
const rawMessage: RawMessage = {
type: MessageType.ROOM_LEAVE,
...
...
Please
register
or
login
to post a comment