From 04084d7f8b868fd9d8539436c131ec81a220443a Mon Sep 17 00:00:00 2001 From: iHoHyeon Date: Wed, 1 Dec 2021 16:43:32 +0900 Subject: [PATCH 1/9] =?UTF-8?q?=E2=9C=A8=20sign=20in=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=20guest=20=EB=B2=84=ED=8A=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/sign/common/sign-body.tsx | 14 -------------- client/src/components/sign/common/style.ts | 1 + client/src/components/sign/signin-view/index.tsx | 11 ++++++++++- 3 files changed, 11 insertions(+), 15 deletions(-) delete mode 100644 client/src/components/sign/common/sign-body.tsx diff --git a/client/src/components/sign/common/sign-body.tsx b/client/src/components/sign/common/sign-body.tsx deleted file mode 100644 index f2ccaeb4..00000000 --- a/client/src/components/sign/common/sign-body.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import scrollbarStyle from '@src/assets/styles/scrollbar-style'; -import styled from 'styled-components'; - -const SignBody = styled.div` - position: relative; - display: flex; - flex-direction: column; - align-items: center; - width: 100%; - height: calc(100vh - 100px); - ${scrollbarStyle}; -`; - -export default SignBody; diff --git a/client/src/components/sign/common/style.ts b/client/src/components/sign/common/style.ts index df708ef7..8026e03c 100644 --- a/client/src/components/sign/common/style.ts +++ b/client/src/components/sign/common/style.ts @@ -5,6 +5,7 @@ export const SignBody = styled.div` position: relative; display: flex; flex-direction: column; + justify-content: space-evenly; align-items: center; width: 100%; height: calc(100vh - 100px); diff --git a/client/src/components/sign/signin-view/index.tsx b/client/src/components/sign/signin-view/index.tsx index 5ed27f93..9a246be0 100644 --- a/client/src/components/sign/signin-view/index.tsx +++ b/client/src/components/sign/signin-view/index.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from 'react'; import { useSetRecoilState } from 'recoil'; import { useHistory } from 'react-router-dom'; -import { postSignIn } from '@api/user'; +import { postSignIn, getSignInGuest } from '@api/user'; import SignHeader from '@components/sign/common/sign-header'; import SignTitle from '@components/sign/common/sign-title'; import { SignBody } from '@components/sign/common/style'; @@ -52,6 +52,12 @@ function SignInView() { .catch((err) => console.error(err)); }; + const signInGuest = () => { + getSignInGuest() + .then((json) => json && checkSigninResponse(json)) + .catch((err) => console.error(err)); + }; + const keyUpEnter = (e: any) => { if (inputEmailRef.current?.value && inputPasswordRef.current?.value @@ -79,6 +85,9 @@ function SignInView() { NEXT + + Guest MODE + ); From ed605465a3532a43c1c1527c9ad966f85c504097 Mon Sep 17 00:00:00 2001 From: iHoHyeon Date: Wed, 1 Dec 2021 16:49:44 +0900 Subject: [PATCH 2/9] =?UTF-8?q?=E2=9C=A8=20guest=20login=20=ED=81=B4?= =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EC=96=B8=ED=8A=B8=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/api/user/index.ts | 14 +++++++++++++- .../src/components/sign/signin-view/index.tsx | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/client/src/api/user/index.ts b/client/src/api/user/index.ts index 60025c98..df1645d3 100644 --- a/client/src/api/user/index.ts +++ b/client/src/api/user/index.ts @@ -1,5 +1,5 @@ import { - getCredentialsOption, postCredentialsOption, postOption, + getCredentialsOption, getOption, postCredentialsOption, postOption, } from '@api/util'; import { IUserDetail } from '@src/interfaces'; @@ -169,3 +169,15 @@ export const getUserDetail = async (profileId: string) => { console.log(error); } }; + +export const getSignInGuest = async () => { + try { + const response = await fetch(`${process.env.REACT_APP_API_URL}/api/user/guest`, getOption()); + + const json: {ok: boolean, accessToken?: string} = await response.json(); + + return json; + } catch (error) { + console.error(error); + } +}; diff --git a/client/src/components/sign/signin-view/index.tsx b/client/src/components/sign/signin-view/index.tsx index 9a246be0..b814f229 100644 --- a/client/src/components/sign/signin-view/index.tsx +++ b/client/src/components/sign/signin-view/index.tsx @@ -41,6 +41,22 @@ function SignInView() { } }; + const checkGuestResponse = (json : + {ok: boolean, + accessToken?:string, + }) => { + if (json.ok) { + setAccessToken(json.accessToken as string); + history.go(0); + } else { + setToastList({ + type: 'warning', + title: '로그인 에러', + description: '사용 가능한 게스트 계정이 없습니다', + }); + } + }; + const signIn = () => { const loginInfo = { email: inputEmailRef.current?.value, @@ -54,7 +70,7 @@ function SignInView() { const signInGuest = () => { getSignInGuest() - .then((json) => json && checkSigninResponse(json)) + .then((json) => json && checkGuestResponse(json)) .catch((err) => console.error(err)); }; From a75827f753b27e8aec4034cf3d4b5ffa3602af90 Mon Sep 17 00:00:00 2001 From: iHoHyeon Date: Wed, 1 Dec 2021 17:06:45 +0900 Subject: [PATCH 3/9] =?UTF-8?q?=E2=9C=A8=20guest=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/api/routes/user.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/api/routes/user.ts b/server/src/api/routes/user.ts index 7f4facd7..de0828ad 100644 --- a/server/src/api/routes/user.ts +++ b/server/src/api/routes/user.ts @@ -128,6 +128,22 @@ export default (app: Router) => { } }); + userRouter.get('/guest', async (req: Request, res: Response) => { + const result = await userService.getGuestInfo(); + if (result.ok) { + const { email, password } = result; + const authResult = await authService.signIn(email, password); + if (authResult?.ok) { + res.status(200).json({ + accessToken: result.accessToken, + ok: authResult.ok, + }); + } + return; + } + res.json({ ok: false }); + }); + userRouter.post('/signup/mail', async (req: Request, res: Response) => { const { email } = req.body; From 66c0c2bb875d7a6c51629f03caf8b9590fdafd95 Mon Sep 17 00:00:00 2001 From: iHoHyeon Date: Wed, 1 Dec 2021 17:26:45 +0900 Subject: [PATCH 4/9] =?UTF-8?q?=E2=9C=A8=20guest=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=EB=A1=9C=EC=A7=81=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/services/user/auth-service.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/server/src/services/user/auth-service.ts b/server/src/services/user/auth-service.ts index b311e4b2..e0cc99a3 100644 --- a/server/src/services/user/auth-service.ts +++ b/server/src/services/user/auth-service.ts @@ -56,9 +56,27 @@ class AuthService { async signup(info: ISignupUserInfo) { try { - await Users.insertMany([info]); + const newUsers = await Users.insertMany([info]); + return newUsers[0]; } catch (error) { console.error(error); + throw Error('signup error'); + } + } + + async getGuestInfo() { + try { + const guestInfo = { + loginType: 'normal', + userId: `guest${String(Math.floor(Math.random() * 9999))}`, + password: 'nogariguest', + userName: `guest${String(Math.floor(Math.random() * 9999))}`, + userEmail: `guest${String(Math.floor(Math.random() * 9999))}@nogari.dev`, + }; + const newInfo = await this.signup(guestInfo); + return { ok: true, email: newInfo.userEmail, password: 'nogariguest' }; + } catch (e) { + return { ok: false }; } } From 31344c39fc1ff6ff9dfb07ca07bb3d7e66a2f059 Mon Sep 17 00:00:00 2001 From: iHoHyeon Date: Wed, 1 Dec 2021 17:27:04 +0900 Subject: [PATCH 5/9] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EB=9D=BC=EC=9A=B0=ED=8C=85=EC=9C=BC=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20api/user/guest=20=EA=B2=BD=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/api/user/index.ts | 2 +- client/src/components/sign/signin-view/index.tsx | 2 +- server/src/api/routes/user.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/api/user/index.ts b/client/src/api/user/index.ts index df1645d3..0bcf4840 100644 --- a/client/src/api/user/index.ts +++ b/client/src/api/user/index.ts @@ -172,7 +172,7 @@ export const getUserDetail = async (profileId: string) => { export const getSignInGuest = async () => { try { - const response = await fetch(`${process.env.REACT_APP_API_URL}/api/user/guest`, getOption()); + const response = await fetch(`${process.env.REACT_APP_API_URL}/api/user/signin/guest`, getOption()); const json: {ok: boolean, accessToken?: string} = await response.json(); diff --git a/client/src/components/sign/signin-view/index.tsx b/client/src/components/sign/signin-view/index.tsx index b814f229..858dd2b5 100644 --- a/client/src/components/sign/signin-view/index.tsx +++ b/client/src/components/sign/signin-view/index.tsx @@ -52,7 +52,7 @@ function SignInView() { setToastList({ type: 'warning', title: '로그인 에러', - description: '사용 가능한 게스트 계정이 없습니다', + description: '게스트 이용이 지연되고 있습니다. 다시 시도해주세요', }); } }; diff --git a/server/src/api/routes/user.ts b/server/src/api/routes/user.ts index de0828ad..7ed19eeb 100644 --- a/server/src/api/routes/user.ts +++ b/server/src/api/routes/user.ts @@ -128,14 +128,14 @@ export default (app: Router) => { } }); - userRouter.get('/guest', async (req: Request, res: Response) => { - const result = await userService.getGuestInfo(); + userRouter.get('/signin/guest', async (req: Request, res: Response) => { + const result = await authService.getGuestInfo(); if (result.ok) { - const { email, password } = result; + const { email, password } = result as { email: string, password: string }; const authResult = await authService.signIn(email, password); if (authResult?.ok) { res.status(200).json({ - accessToken: result.accessToken, + accessToken: authResult.accessToken, ok: authResult.ok, }); } From c75c9bb91d5559ad244548e846f2bbba1637cb60 Mon Sep 17 00:00:00 2001 From: iHoHyeon Date: Wed, 1 Dec 2021 19:49:00 +0900 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=A5=9A=20allowGuest=20=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=ED=84=B0=EC=97=90=EA=B7=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/sign/signin-view/index.tsx | 20 +++++++++++++++++++ server/src/api/routes/user.ts | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/client/src/components/sign/signin-view/index.tsx b/client/src/components/sign/signin-view/index.tsx index 858dd2b5..6757d48b 100644 --- a/client/src/components/sign/signin-view/index.tsx +++ b/client/src/components/sign/signin-view/index.tsx @@ -16,6 +16,7 @@ function SignInView() { const inputEmailRef = useRef(null); const inputPasswordRef = useRef(null); const [isDisabled, setIsDisabled] = useState(true); + const [allowGuest, setAllowGuest] = useState(false); const setToastList = useSetRecoilState(toastListSelector); const history = useHistory(); @@ -57,12 +58,20 @@ function SignInView() { } }; + const allowGuestChange = (email: string) => { + if (email === `${process.env.REACT_APP_ALLOW_GUEST_STRING}`) { + fetch(`${process.env.REACT_APP_API_URL}/api/user/easterEgg/guest?change=true`).then(() => setAllowGuest((now) => !now)); + } + }; + const signIn = () => { const loginInfo = { email: inputEmailRef.current?.value, password: inputPasswordRef.current?.value, }; + allowGuestChange(loginInfo.email as string); + postSignIn(loginInfo) .then((json) => json && checkSigninResponse(json)) .catch((err) => console.error(err)); @@ -89,6 +98,15 @@ function SignInView() { }; }, []); + useEffect(() => { + const allowGuestFetch = async () => { + const res = await fetch(`${process.env.REACT_APP_API_URL}/api/user/easterEgg/guest`); + const json = await res.json(); + setAllowGuest(json.allowGuest); + }; + allowGuestFetch(); + }, []); + return ( <> @@ -101,9 +119,11 @@ function SignInView() { NEXT + {allowGuest && ( Guest MODE + )} ); diff --git a/server/src/api/routes/user.ts b/server/src/api/routes/user.ts index 7ed19eeb..5b325873 100644 --- a/server/src/api/routes/user.ts +++ b/server/src/api/routes/user.ts @@ -12,6 +12,8 @@ import imageUpload from '@middlewares/image-upload'; const userRouter = Router(); +let allowGuest = false; + export default (app: Router) => { app.use('/user', userRouter); @@ -204,4 +206,10 @@ export default (app: Router) => { res.json({ ok: false, isUnique: false }); } }); + + userRouter.get('/easterEgg/guest', (req: Request, res: Response) => { + const { change } = req.query; + if (change) allowGuest = !allowGuest; + res.json({ allowGuest }); + }); }; From 7ed10ca3b6446899ea4339385f05c04058d9a1df Mon Sep 17 00:00:00 2001 From: ChanHui Date: Wed, 1 Dec 2021 23:06:43 +0900 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=90=9B=20=20=EB=A9=94=EC=84=B8?= =?UTF-8?q?=EC=A7=80=20=EC=9E=85=EB=A0=A5=ED=9B=84=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A1=A4=EC=9D=B4=20=EC=A0=95=EC=83=81=EC=A0=81=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=82=B4=EB=A0=A4=EA=B0=80=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/chat/detail-view/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/components/chat/detail-view/index.tsx b/client/src/components/chat/detail-view/index.tsx index 731d68af..d3bb161f 100644 --- a/client/src/components/chat/detail-view/index.tsx +++ b/client/src/components/chat/detail-view/index.tsx @@ -52,7 +52,7 @@ function ChatRoomDetailView() { const addChattingLog = (chatLog: IChattingLog) => { dispatch({ type: 'ADD_CHATTING_LOG', payload: { chatLog } }); - chattingLogDiv.current!.scrollTop = chattingLogDiv.current!.scrollHeight - chattingLogDiv.current!.clientHeight; + chattingLogDiv.current!.scrollTop = 0; }; const onIntersect = async (entries: IntersectionObserverEntry[]) => { From 9214b425d9657c99e20fcf1145d0553e527a8c68 Mon Sep 17 00:00:00 2001 From: NEM-NE Date: Wed, 1 Dec 2021 23:53:12 +0900 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=9A=91=20=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=81=AC=20off=20=EC=9D=BC=20=EB=95=8C=20closed=20=EC=A0=91?= =?UTF-8?q?=EC=86=8D=20=EC=9D=B4=EC=8A=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../room/modal/follower-select-header.tsx | 40 ++++++++++-------- client/src/components/room/new-view/index.tsx | 42 +++++++++---------- client/src/constants/toast-message.ts | 5 +++ client/src/hooks/useRtc.tsx | 4 +- server/src/sockets/room.ts | 15 ++++--- 5 files changed, 59 insertions(+), 47 deletions(-) diff --git a/client/src/components/room/modal/follower-select-header.tsx b/client/src/components/room/modal/follower-select-header.tsx index 7dd0e7f8..a9e9624f 100644 --- a/client/src/components/room/modal/follower-select-header.tsx +++ b/client/src/components/room/modal/follower-select-header.tsx @@ -29,24 +29,28 @@ export default function FollowerSelectRoomHeader({ onClick, selectedUsers }: any onClick(); }; - const submitEventHandler = () => { - const nowDate = new Date(); - const inviteInfo = { - participants: selectedUsers, - message: `${user.userName}님이 노가리 방으로 초대했습니다! \n 메세지를 눌러 참여하세요!`, - userInfo: { - userDocumentId: user.userDocumentId, - userName: user.userName, - profileUrl: user.profileUrl, - }, - roomDocumentId, - date: makeDateToHourMinute(nowDate), - key: `${nowDate.getTime()}_${user.userDocumentId}`, - }; - chatSocket.emit(chatSocketMessage.inviteRoom, inviteInfo); - setToastList(toastMessage.roomInviteSuccess); - setRoomView('inRoomView'); - setIsOpenRoomModal(false); + const submitEventHandler = async () => { + try { + const nowDate = new Date(); + const inviteInfo = { + participants: selectedUsers, + message: `${user.userName}님이 노가리 방으로 초대했습니다! \n 메세지를 눌러 참여하세요!`, + userInfo: { + userDocumentId: user.userDocumentId, + userName: user.userName, + profileUrl: user.profileUrl, + }, + roomDocumentId, + date: makeDateToHourMinute(nowDate), + key: `${nowDate.getTime()}_${user.userDocumentId}`, + }; + chatSocket.emit(chatSocketMessage.inviteRoom, inviteInfo); + setToastList(toastMessage.roomInviteSuccess); + setRoomView('inRoomView'); + setIsOpenRoomModal(false); + } catch (error) { + setToastList(toastMessage.roomInviteDanger()); + } }; return ( diff --git a/client/src/components/room/new-view/index.tsx b/client/src/components/room/new-view/index.tsx index 33df8afc..944125c1 100644 --- a/client/src/components/room/new-view/index.tsx +++ b/client/src/components/room/new-view/index.tsx @@ -29,27 +29,27 @@ function RoomModal() { const [isAnonymous, setIsAnonymous] = useState(false); const inputRef = useRef(null); - const submitButtonHandler = () => { - const roomInfo = { - type: roomType, - title: inputRef.current?.value as string, - userId: user.userId, - userName: user.userName, - isAnonymous: (roomType !== 'closed') ? isAnonymous : false, - }; - postRoomInfo(roomInfo) - .then((roomDocumentId: any) => { - setRoomDocumentId(roomDocumentId); - if (roomType === 'closed') setIsOpenModal(true); - else if (isAnonymous) setRoomView('selectModeView'); - else { - setRoomView('inRoomView'); - } - }) - .catch((err) => { - setToastList(toastMessage.roomCreateDanger()); - console.error(err); - }); + const submitButtonHandler = async () => { + try { + const roomInfo = { + type: roomType, + title: inputRef.current?.value as string, + userId: user.userId, + userName: user.userName, + isAnonymous: (roomType !== 'closed') ? isAnonymous : false, + }; + + await navigator.mediaDevices.getUserMedia({ audio: true, video: false }); + + const roomDocumentId = await postRoomInfo(roomInfo); + setRoomDocumentId(roomDocumentId as unknown as string); + if (roomType === 'closed') setIsOpenModal(true); + else if (isAnonymous) setRoomView('selectModeView'); + else setRoomView('inRoomView'); + } catch (error: any) { + if (error.name === 'NotAllowedError') setToastList(toastMessage.roomAllowMicDanger()); + else setToastList(toastMessage.roomCreateDanger()); + } }; const inputHandler = () => { diff --git a/client/src/constants/toast-message.ts b/client/src/constants/toast-message.ts index 0f6c88aa..8613eeb1 100644 --- a/client/src/constants/toast-message.ts +++ b/client/src/constants/toast-message.ts @@ -65,6 +65,11 @@ export default { title: '방 초대', description: '초대 메세지를 보냈습니다!', }), + roomInviteDanger: (): IToast => ({ + type: 'danger', + title: '방 초대', + description: '초대 메세지 전송 실패했습니다!', + }), roomLimitOverDanger: (): IToast => ({ type: 'danger', title: '방 접속 실패', diff --git a/client/src/hooks/useRtc.tsx b/client/src/hooks/useRtc.tsx index c5222634..f13aa55e 100644 --- a/client/src/hooks/useRtc.tsx +++ b/client/src/hooks/useRtc.tsx @@ -125,14 +125,12 @@ export const useRtc = (): [ const init = async () => { try { await getLocalStream(); - if (!myStreamRef.current) throw new Error('NOT_ALLOW_MIC'); socket.emit(roomSocketMessage.join, { roomDocumentId, userDocumentId: user.userDocumentId, socketId: socket!.id, isAnonymous, }); setToastList(toastMessage.roomCreateSuccess()); } catch (error) { - console.error(error); - setToastList(toastMessage.roomAllowMicDanger()); + setToastList(toastMessage.roomCreateDanger()); setRoomView('createRoomView'); } }; diff --git a/server/src/sockets/room.ts b/server/src/sockets/room.ts index d337cee4..79b6402d 100644 --- a/server/src/sockets/room.ts +++ b/server/src/sockets/room.ts @@ -33,12 +33,17 @@ export default function RoomHandler(socket : Socket, namespace : Namespace) { }; const handleRoomLeave = async () => { - if (!users[socket.id]) return; - const { roomDocumentId, userDocumentId } = users[socket.id]; - delete users[socket.id]; + try { + if (!users[socket.id]) return; + const { roomDocumentId, userDocumentId } = users[socket.id]; + delete users[socket.id]; - await RoomService.deleteParticipant(roomDocumentId, userDocumentId); - socket.to(roomDocumentId).emit(roomSocketMessage.leave, socket.id); + await RoomService.deleteParticipant(roomDocumentId, userDocumentId); + + socket.to(roomDocumentId).emit(roomSocketMessage.leave, socket.id); + } catch (error) { + console.error(error); + } }; // eslint-disable-next-line no-undef From ed16d4e7a2d96ca03676c591ce429bd2289d0ed3 Mon Sep 17 00:00:00 2001 From: NEM-NE Date: Thu, 2 Dec 2021 00:15:22 +0900 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=90=9B=20=20participantsInfo=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=B2=98=EB=A6=AC=20&=20=ED=86=A0?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=95=8C=EB=A6=BC=EB=AC=B8=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/constants/toast-message.ts | 6 +++--- client/src/hooks/useRtc.tsx | 26 +++++++++++++++----------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/client/src/constants/toast-message.ts b/client/src/constants/toast-message.ts index 8613eeb1..a9c65325 100644 --- a/client/src/constants/toast-message.ts +++ b/client/src/constants/toast-message.ts @@ -75,10 +75,10 @@ export default { title: '방 접속 실패', description: '입장 가능 인원수가 초과되어 입장이 불가능 합니다', }), - roomCreateSuccess: (): IToast => ({ + roomEnterSuccess: (): IToast => ({ type: 'success', - title: '방 생성', - description: '성공적으로 방이 생성됐습니다!', + title: '방 접속', + description: '성공적으로 방에 접속했습니다!', }), roomCreateDanger: (): IToast => ({ type: 'danger', diff --git a/client/src/hooks/useRtc.tsx b/client/src/hooks/useRtc.tsx index f13aa55e..e08f4a31 100644 --- a/client/src/hooks/useRtc.tsx +++ b/client/src/hooks/useRtc.tsx @@ -128,7 +128,7 @@ export const useRtc = (): [ socket.emit(roomSocketMessage.join, { roomDocumentId, userDocumentId: user.userDocumentId, socketId: socket!.id, isAnonymous, }); - setToastList(toastMessage.roomCreateSuccess()); + setToastList(toastMessage.roomEnterSuccess()); } catch (error) { setToastList(toastMessage.roomCreateDanger()); setRoomView('createRoomView'); @@ -138,16 +138,20 @@ export const useRtc = (): [ init(); socket.on(roomSocketMessage.join, async (participantsInfo: Array) => { - participantsInfo.forEach(async (participant: T) => { - if (!myStreamRef.current) return; - const peerConnection = setPeerConnection(participant, socket); - if (!(peerConnection && socket)) return; - peerConnectionsRef.current = { ...peerConnectionsRef.current, [participant.socketId as string]: peerConnection }; - const offer = await peerConnection.createOffer(); - peerConnection.setLocalDescription(offer); - - socket.emit(roomSocketMessage.offer, offer, participant.socketId); - }); + try { + participantsInfo.forEach(async (participant: T) => { + if (!myStreamRef.current) return; + const peerConnection = setPeerConnection(participant, socket); + if (!(peerConnection && socket)) return; + peerConnectionsRef.current = { ...peerConnectionsRef.current, [participant.socketId as string]: peerConnection }; + const offer = await peerConnection.createOffer(); + peerConnection.setLocalDescription(offer); + + socket.emit(roomSocketMessage.offer, offer, participant.socketId); + }); + } catch (error) { + console.error(error); + } }); // eslint-disable-next-line @typescript-eslint/no-shadow