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 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/" 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'], diff --git a/backend/src/socket/socket.gateway.ts b/backend/src/socket/socket.gateway.ts index 33ecb32..6b77d66 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, @@ -164,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();