From 64d59d3e6ab50071b8e6027241e703bcdf593936 Mon Sep 17 00:00:00 2001 From: hj1n Date: Thu, 8 Dec 2022 17:53:17 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[feat]=20#51=20=EC=83=88=EB=A1=9C=EC=9A=B4?= =?UTF-8?q?=ED=83=AD=20=EC=A0=91=EC=86=8D=EC=8B=9C=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?=EC=86=8C=EC=BC=93=20=EC=97=B0=EA=B2=B0=ED=95=B4=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/socket/socket.gateway.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/src/socket/socket.gateway.ts b/backend/src/socket/socket.gateway.ts index 33ecb32..82ae272 100644 --- a/backend/src/socket/socket.gateway.ts +++ b/backend/src/socket/socket.gateway.ts @@ -52,11 +52,17 @@ export class SocketGateway implements OnGatewayConnection, OnGatewayDisconnect { const key = client.handshake?.headers?.authorization; const roomName = client.handshake?.headers?.room; const userData = this.authService.verify(key); - if (!userData || !roomName || this.socketIdByUser.get(userData['id'])) { + if (!userData || !roomName) { client.disconnect(); return; } + if (this.socketIdByUser.get(userData['id'])) { + this.server.sockets.sockets + .get(this.socketIdByUser.get(userData['id'])) + .disconnect(); + } + client['userData'] = { ...userData, x: -25, From 813392cd88b48685b695976bbb48cc7ee0a51b36 Mon Sep 17 00:00:00 2001 From: hj1n Date: Thu, 8 Dec 2022 19:03:59 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[feat]=20#164=20#165=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=EB=B0=8F=20=ED=86=B5=ED=99=94=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=86=8C=EC=BC=93=EC=9D=B4=EB=B2=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/socket/socket.gateway.ts | 101 +++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/backend/src/socket/socket.gateway.ts b/backend/src/socket/socket.gateway.ts index 82ae272..6b77d66 100644 --- a/backend/src/socket/socket.gateway.ts +++ b/backend/src/socket/socket.gateway.ts @@ -170,6 +170,107 @@ export class SocketGateway implements OnGatewayConnection, OnGatewayDisconnect { }); } + @SubscribeMessage('callRequested') + handleCallRequested(client: any, payload: any) { + const { calleeUserId } = payload; + const callerUserId = client['userData']['id']; + // busy 로 상태 변경 + client['userData']['userState'] = 'busy'; + this.server.sockets.sockets.get(this.socketIdByUser.get(calleeUserId))[ + 'userData' + ]['userState'] = 'busy'; + + this.server + .to(this.socketIdByUser.get(calleeUserId)) + .emit('callRequested', { + callerUserId: client['userData']['id'], + }); + + this.server.to(client['userData']['roomName']).emit('userStateChanged', { + userIdList: [calleeUserId, callerUserId], + userState: 'busy', + }); + } + + // 건 사람이 마음 바뀜 끊음. => 상대방만 on으로 변경 + @SubscribeMessage('callCanceled') + handleCallCanceled(client: any, payload: any) { + const { calleeUserId } = payload; + const callerUserId = client['userData']['id']; + + this.server.sockets.sockets.get(this.socketIdByUser.get(calleeUserId))[ + 'userData' + ]['userState'] = 'on'; + + this.server.to(this.socketIdByUser.get(calleeUserId)).emit('callCanceled', { + callerUserId: client['userData']['id'], + }); + + this.server.to(client['userData']['roomName']).emit('userStateChanged', { + userIdList: [calleeUserId], + userState: 'on', + }); + } + + @SubscribeMessage('callDenied') + handleCallDenied(client: any, payload: any) { + const { callerUserId } = payload; + const calleeUserId = client['userData']['id']; + + client['userData']['userState'] = 'on'; + + this.server.to(this.socketIdByUser.get(callerUserId)).emit('callDenied', { + calleeUserId: client['userData']['id'], + }); + + this.server.to(client['userData']['roomName']).emit('userStateChanged', { + userIdList: [calleeUserId], + userState: 'on', + }); + } + + // 전화 수락!! + @SubscribeMessage('callEntered') + handleCallEntered(client: any, payload: any) { + const { callerUserId } = payload; + const calleeUserId = client['userData']['id']; + + client['userData']['userState'] = 'busy'; + this.server.sockets.sockets.get(this.socketIdByUser.get(calleeUserId))[ + 'userData' + ]['userState'] = 'busy'; + + this.server.to(this.socketIdByUser.get(callerUserId)).emit('callEntered', { + calleeUserId: client['userData']['id'], + }); + + this.server.to(client['userData']['roomName']).emit('userStateChanged', { + userIdList: [callerUserId, calleeUserId], + userState: 'busy', + }); + // webRTC 연결 맺애주는 과정 필요 + // 기존에 그룹에 통화하고잇던 리스트를 받아서 userData어딘가에 갖고있어야할듯? + // 내가 아무도없는 상태에서 너한테 거는거랑 ( 진짜로 webRTC룸이 첫 생성) + // 내가 누군가랑 하다가 너까지 끌어들이는 시점 (룸이 잇는데 너를 끌어드림) + // 프론트에서 저장하고잇다가 request할떄 같이 참여자들 리스트? + } + // 전화 나오기! + + @SubscribeMessage('callLeaved') + handleCallLeaved(client: any, payload: any) { + const leavingUserId = client['userData']['id']; + const { callingUserList } = payload; + + this.server.to(callingUserList).emit('callLeaved', { + leavingUserId, + }); + + this.server.to(client['userData']['roomName']).emit('userStateChanged', { + userIdList: [leavingUserId], + userState: 'on', + }); + } + @SubscribeMessage('disconnecting') handleDisconnecting(client: any) { client.disconnect(); From 5ebe463d52f78c2e28acb0dd7d20458a1b964f70 Mon Sep 17 00:00:00 2001 From: Hyungjin Lee <65952531+hj1n@users.noreply.github.com> Date: Fri, 9 Dec 2022 00:45:19 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[feat]=20#49=20Github=20action=EC=9D=84=20?= =?UTF-8?q?=EC=9D=B4=EC=9A=A9=ED=95=9C=20=EB=B0=B0=ED=8F=AC=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - frontend --- .github/workflows/frontend_deploy.yml | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/frontend_deploy.yml diff --git a/.github/workflows/frontend_deploy.yml b/.github/workflows/frontend_deploy.yml new file mode 100644 index 0000000..da60410 --- /dev/null +++ b/.github/workflows/frontend_deploy.yml @@ -0,0 +1,43 @@ +name: Frontend CD +on: + push: + branches: + - main + +jobs: + Auto-Deploy: + name: Frontend Deploy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Node 설정 + uses: actions/setup-node@v1 + with: + node-version: "18.x" + + - name: node_modules 폴더 캐싱 + uses: actions/cache@v2 + id: cache + with: + path: "**/frontend/node_modules" + key: ${{ runner.os }}-modules-${{ hashFiles('**/frontend/package-lock.json') }} + + - name: node_modules 폴더 캐시가 없다면 dependencies 설치 + working-directory: "./frontend" + if: steps.cache.outputs.cache-hit != 'true' + run: npm install + + - name: Client 소스 빌드 + working-directory: "./frontend" + run: npm run build + + - name: SCP 프로토콜을 통한 서버로 파일 전송 처리 + uses: appleboy/scp-action@master + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USER }} + password: ${{ secrets.SSH_PASSWORD }} + port: ${{ secrets.SSH_PORT }} + source: "./frontend/dist/*" + target: "/root/production/" From 9d2fd55595557d232464dee7b16e3a6e59aa91b2 Mon Sep 17 00:00:00 2001 From: Hyungjin Lee <65952531+hj1n@users.noreply.github.com> Date: Fri, 9 Dec 2022 00:46:04 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[feat]=20#49=20Github=20action=EC=9D=84=20?= =?UTF-8?q?=EC=9D=B4=EC=9A=A9=ED=95=9C=20=EB=B0=B0=ED=8F=AC=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - backend --- .github/workflows/backend_deploy.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/backend_deploy.yml diff --git a/.github/workflows/backend_deploy.yml b/.github/workflows/backend_deploy.yml new file mode 100644 index 0000000..88aa6fb --- /dev/null +++ b/.github/workflows/backend_deploy.yml @@ -0,0 +1,24 @@ +name: Backend CD +on: + push: + branches: + - main + +jobs: + Auto-Deploy: + name: Backend Deploy + runs-on: ubuntu-latest + steps: + - name: SSH RemoteCommands + uses: appleboy/ssh-action@v0.1.5 + with: + host: ${{secrets.SSH_HOST}} + port: ${{secrets.SSH_PORT}} + username: ${{secrets.SSH_USER}} + password: ${{secrets.SSH_PASSWORD}} + script: | + cd /root/production/web05-SleepyWoods/backend + git pull origin main + npm install + npm run build + pm2 reload main From c5393fbc4e02c0b93e4619d40c94b4c253af1bfd Mon Sep 17 00:00:00 2001 From: hj1n Date: Fri, 9 Dec 2022 01:16:13 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[fix]=20#4=20=EC=B9=B4=EC=B9=B4=EC=98=A4?= =?UTF-8?q?=EA=B3=84=EC=A0=95=20=EA=B0=80=EC=9E=85=EC=8B=9C=20=EC=83=81?= =?UTF-8?q?=EC=88=98=EA=B0=92=20=EC=A4=91=EB=B3=B5=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EC=9D=B4=EC=8A=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/auth/user.controller.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/src/auth/user.controller.ts b/backend/src/auth/user.controller.ts index caf1fae..d1ed269 100644 --- a/backend/src/auth/user.controller.ts +++ b/backend/src/auth/user.controller.ts @@ -108,15 +108,18 @@ export class UserController { ) { const { id, social }: UserDataDto = req.user; // body안에 nickname, characterName FE에 전송 요청 + await this.userService.createUser({ - id: social === socialPlatform.KAKAO ? `k${id}` : id, + id: + social === socialPlatform.KAKAO && !id.startsWith('k') ? `k${id}` : id, social, nickname: signupData['nickname'], characterName: signupData['characterName'], }); const jwt = await this.authService.jwtTokenGenerator({ - id: social === socialPlatform.KAKAO ? `k${id}` : id, + id: + social === socialPlatform.KAKAO && !id.startsWith('k') ? `k${id}` : id, social, nickname: signupData['nickname'], characterName: signupData['characterName'],