Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…leepyWoods into develop
  • Loading branch information
JJongBin committed Dec 8, 2022
2 parents 42d9226 + 3dfb804 commit a3372e9
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 3 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/backend_deploy.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
43 changes: 43 additions & 0 deletions .github/workflows/frontend_deploy.yml
Original file line number Diff line number Diff line change
@@ -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/"
7 changes: 5 additions & 2 deletions backend/src/auth/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
109 changes: 108 additions & 1 deletion backend/src/socket/socket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: 800,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a3372e9

Please sign in to comment.