Overnap

handleUpdateRoomUser 프로토콜에 맞게 수정

......@@ -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,
......