From 96b425fe4de7d592f9bed630af1e143b98dec6e2 Mon Sep 17 00:00:00 2001 From: HeoJiye Date: Thu, 22 Feb 2024 15:54:55 +0900 Subject: [PATCH 01/13] =?UTF-8?q?remove:=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatbot/clova-studio/clova-studio.service.spec.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/backend/was/src/chatbot/clova-studio/clova-studio.service.spec.ts b/backend/was/src/chatbot/clova-studio/clova-studio.service.spec.ts index aeae30d9..fb78c976 100644 --- a/backend/was/src/chatbot/clova-studio/clova-studio.service.spec.ts +++ b/backend/was/src/chatbot/clova-studio/clova-studio.service.spec.ts @@ -33,16 +33,6 @@ describe('ClovaStudioService', () => { expect(clovaStudioService).toBeDefined(); }); - describe('function getAPIKeys()', () => { - it('getAPIKeys(): clova api key 불러 와서 객체로 만들어서 반환', () => { - const apiKeys = getAPIKeys(configServieMock); - - CLOVA_API_KEY_NAMES.forEach((key) => { - expect(apiKeys[key.replaceAll('_', '-')]).toBe(key); - }); - }); - }); - describe('ClovaStudioService.generateTalk()', () => { it('사용자의 메세지 입력으로 AI의 답변을 생성해서 token stream 형식으로 반환', async () => { setApiMock(tokens); From 1f64dc0c96bee472b0a13829ff8675cfeee35639 Mon Sep 17 00:00:00 2001 From: HeoJiye Date: Thu, 22 Feb 2024 15:58:21 +0900 Subject: [PATCH 02/13] =?UTF-8?q?remove:=20=EA=B8=B0=EC=A1=B4=20npm=20pack?= =?UTF-8?q?age=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=ED=83=80=EC=9E=85=20=EA=B3=B5=EC=9C=A0=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/signal/package-lock.json | 6 ------ backend/signal/package.json | 1 - backend/signal/src/events/events.gateway.ts | 16 ++++++---------- backend/was/package-lock.json | 11 ----------- backend/was/package.json | 1 - frontend/package.json | 2 -- frontend/pnpm-lock.yaml | 14 -------------- packages/ai-socketio-event/LICENSE | 21 --------------------- packages/ai-socketio-event/README.md | 1 - packages/ai-socketio-event/index.d.ts | 2 -- packages/ai-socketio-event/index.js | 4 ---- packages/ai-socketio-event/package.json | 13 ------------- packages/ai-socketio-event/pnpm-lock.yaml | 5 ----- packages/human-socketio-event/LICENSE | 21 --------------------- packages/human-socketio-event/README.md | 1 - packages/human-socketio-event/index.d.ts | 2 -- packages/human-socketio-event/index.js | 4 ---- packages/human-socketio-event/package.json | 13 ------------- 18 files changed, 6 insertions(+), 132 deletions(-) delete mode 100644 packages/ai-socketio-event/LICENSE delete mode 100644 packages/ai-socketio-event/README.md delete mode 100644 packages/ai-socketio-event/index.d.ts delete mode 100644 packages/ai-socketio-event/index.js delete mode 100644 packages/ai-socketio-event/package.json delete mode 100644 packages/ai-socketio-event/pnpm-lock.yaml delete mode 100644 packages/human-socketio-event/LICENSE delete mode 100644 packages/human-socketio-event/README.md delete mode 100644 packages/human-socketio-event/index.d.ts delete mode 100644 packages/human-socketio-event/index.js delete mode 100644 packages/human-socketio-event/package.json diff --git a/backend/signal/package-lock.json b/backend/signal/package-lock.json index 2f403073..e01223ec 100644 --- a/backend/signal/package-lock.json +++ b/backend/signal/package-lock.json @@ -16,7 +16,6 @@ "@nestjs/platform-express": "^10.0.0", "@nestjs/platform-socket.io": "^10.2.10", "@nestjs/websockets": "^10.2.10", - "@tarotmilktea/human-socketio-event": "^2.0.2", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1", "socket.io": "^4.7.2", @@ -1935,11 +1934,6 @@ "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz", "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==" }, - "node_modules/@tarotmilktea/human-socketio-event": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@tarotmilktea/human-socketio-event/-/human-socketio-event-2.0.2.tgz", - "integrity": "sha512-GNuloLBcHMO6icB7hH4CvjFSTwbHMZJqYry2o/W27VvDLOH89c3zF/RVBIlOlcouvHf8U5YJkl3J2HW/hEzoOw==" - }, "node_modules/@trivago/prettier-plugin-sort-imports": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/@trivago/prettier-plugin-sort-imports/-/prettier-plugin-sort-imports-4.3.0.tgz", diff --git a/backend/signal/package.json b/backend/signal/package.json index 7c2f71b6..f69e9e79 100644 --- a/backend/signal/package.json +++ b/backend/signal/package.json @@ -27,7 +27,6 @@ "@nestjs/platform-express": "^10.0.0", "@nestjs/platform-socket.io": "^10.2.10", "@nestjs/websockets": "^10.2.10", - "@tarotmilktea/human-socketio-event": "^2.0.2", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1", "socket.io": "^4.7.2", diff --git a/backend/signal/src/events/events.gateway.ts b/backend/signal/src/events/events.gateway.ts index b08824be..976e6fa9 100644 --- a/backend/signal/src/events/events.gateway.ts +++ b/backend/signal/src/events/events.gateway.ts @@ -6,10 +6,6 @@ import { WebSocketGateway, WebSocketServer, } from '@nestjs/websockets'; -import type { - HumanClientEvent, - HumanServerEvent, -} from '@tarotmilktea/human-socketio-event'; import { Server, Socket } from 'socket.io'; import { LoggerService } from 'src/logger/logger.service'; import { v4 } from 'uuid'; @@ -76,7 +72,7 @@ export class EventsGateway } } - @SubscribeMessage('generateRoomName') + @SubscribeMessage('generateRoomName') handleCreateRoomEvent(socket: Socket) { const roomId: string = v4(); @@ -84,7 +80,7 @@ export class EventsGateway this.logger.debug(`🚀 Room Name Generated : ${roomId}`); } - @SubscribeMessage('createRoom') + @SubscribeMessage('createRoom') handleSetRoomPassword(socket: Socket, [roomId, password]: [string, string]) { const userId = socket.id; this.socketRooms[roomId] = { users: [userId], password: password }; @@ -96,7 +92,7 @@ export class EventsGateway this.logger.debug(`🚀 Room Created : ${roomId}`); } - @SubscribeMessage('joinRoom') + @SubscribeMessage('joinRoom') handleJoinRoomEvent(socket: Socket, [roomId, password]: [string, string]) { const userId = socket.id; @@ -158,7 +154,7 @@ export class EventsGateway } } - @SubscribeMessage('checkRoomExist') + @SubscribeMessage('checkRoomExist') handleCheckRoomExistEvent(socket: Socket, roomName: string) { const existRoom: any = this.socketRooms[roomName]; @@ -171,13 +167,13 @@ export class EventsGateway } } - public eventEmit(socket: Socket, event: HumanServerEvent, ...args: any[]) { + public eventEmit(socket: Socket, event: string, ...args: any[]) { socket.emit(event, ...args); } public eventEmitToRoom( socket: Socket, roomName: string, - event: HumanServerEvent | 'connection', + event: string, ...args: any[] ) { socket.to(roomName).emit(event, ...args); diff --git a/backend/was/package-lock.json b/backend/was/package-lock.json index 6f051d7b..50759df7 100644 --- a/backend/was/package-lock.json +++ b/backend/was/package-lock.json @@ -25,7 +25,6 @@ "@sentry/node": "^7.85.0", "@sentry/profiling-node": "^1.2.6", "@slack/client": "^5.0.2", - "@tarotmilktea/ai-socketio-event": "^2.0.3", "cache-manager-redis-store": "^3.0.1", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", @@ -2675,11 +2674,6 @@ "resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.5.tgz", "integrity": "sha512-Uy0+khmZqUrUGm5dmMqVlnvufZRSK0FbYzVgp0UMstm+F5+W2/jnEEQyc9vo1ZR/E5ZI/B1WjjoTqBqwJL6Krw==" }, - "node_modules/@tarotmilktea/ai-socketio-event": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@tarotmilktea/ai-socketio-event/-/ai-socketio-event-2.0.3.tgz", - "integrity": "sha512-K8IRKzKJaCf4lU8KcbobVHi6Xmxil/5a/uWAwTUkuLPKAtUj8BkuNTG/6XiCQUXjTpfBdSWvIKsQVZuQSoaD7Q==" - }, "node_modules/@tootallnate/once": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", @@ -15477,11 +15471,6 @@ "resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.5.tgz", "integrity": "sha512-Uy0+khmZqUrUGm5dmMqVlnvufZRSK0FbYzVgp0UMstm+F5+W2/jnEEQyc9vo1ZR/E5ZI/B1WjjoTqBqwJL6Krw==" }, - "@tarotmilktea/ai-socketio-event": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@tarotmilktea/ai-socketio-event/-/ai-socketio-event-2.0.3.tgz", - "integrity": "sha512-K8IRKzKJaCf4lU8KcbobVHi6Xmxil/5a/uWAwTUkuLPKAtUj8BkuNTG/6XiCQUXjTpfBdSWvIKsQVZuQSoaD7Q==" - }, "@tootallnate/once": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", diff --git a/backend/was/package.json b/backend/was/package.json index 4c7964f7..2a542adb 100644 --- a/backend/was/package.json +++ b/backend/was/package.json @@ -36,7 +36,6 @@ "@sentry/node": "^7.85.0", "@sentry/profiling-node": "^1.2.6", "@slack/client": "^5.0.2", - "@tarotmilktea/ai-socketio-event": "^2.0.3", "cache-manager-redis-store": "^3.0.1", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", diff --git a/frontend/package.json b/frontend/package.json index b0690b92..2984d807 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -16,8 +16,6 @@ "dependencies": { "@tanstack/react-query": "^5.12.2", "@tanstack/react-query-devtools": "^5.12.2", - "@tarotmilktea/ai-socketio-event": "^2.0.2", - "@tarotmilktea/human-socketio-event": "^2.0.1", "axios": "^1.6.2", "detect-browser": "^5.3.0", "html2canvas": "^1.4.1", diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index ad4cdab5..d7f89e24 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -11,12 +11,6 @@ dependencies: '@tanstack/react-query-devtools': specifier: ^5.12.2 version: 5.12.2(@tanstack/react-query@5.12.2)(react@18.2.0) - '@tarotmilktea/ai-socketio-event': - specifier: ^2.0.2 - version: 2.0.2 - '@tarotmilktea/human-socketio-event': - specifier: ^2.0.1 - version: 2.0.1 axios: specifier: ^1.6.2 version: 1.6.2 @@ -4118,14 +4112,6 @@ packages: react: 18.2.0 dev: false - /@tarotmilktea/ai-socketio-event@2.0.2: - resolution: {integrity: sha512-bXWzxAHQo5a6fMee9WJ8uqW4AMiKU0fnk8PmYn+xH3SX/6J1bIdrq6JdNlzqKcSVSvtDg5yrkYIe44RuPnrGtg==} - dev: false - - /@tarotmilktea/human-socketio-event@2.0.1: - resolution: {integrity: sha512-V8cIxWr8dL0Yo/5DrLNoiqN0e6EQV+D02Dc148/UAK2PglSybI8P3yKx+rWyry3uPMMecybB9nUIkXe5aWMM1w==} - dev: false - /@testing-library/dom@9.3.4: resolution: {integrity: sha512-FlS4ZWlp97iiNWig0Muq8p+3rVDjRiYE+YKGbAqXOu9nwJFFOdL00kFpz42M+4huzYi86vAK1sOOfyOG45muIQ==} engines: {node: '>=14'} diff --git a/packages/ai-socketio-event/LICENSE b/packages/ai-socketio-event/LICENSE deleted file mode 100644 index e101c998..00000000 --- a/packages/ai-socketio-event/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 David Fong - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/packages/ai-socketio-event/README.md b/packages/ai-socketio-event/README.md deleted file mode 100644 index 8ffcf348..00000000 --- a/packages/ai-socketio-event/README.md +++ /dev/null @@ -1 +0,0 @@ -# @tarotmilktea/ai-socketio-event diff --git a/packages/ai-socketio-event/index.d.ts b/packages/ai-socketio-event/index.d.ts deleted file mode 100644 index 77e8a533..00000000 --- a/packages/ai-socketio-event/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type AIServerEvent = "tarotCard" | "chatEnd" | "streamStart" | "streaming" | "streamEnd"; -export type AIClientEvent = "message" | "tarotRead"; diff --git a/packages/ai-socketio-event/index.js b/packages/ai-socketio-event/index.js deleted file mode 100644 index 763b7927..00000000 --- a/packages/ai-socketio-event/index.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - AIServerEvent, - AIClientEvent, -}; diff --git a/packages/ai-socketio-event/package.json b/packages/ai-socketio-event/package.json deleted file mode 100644 index 62de835f..00000000 --- a/packages/ai-socketio-event/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "@tarotmilktea/ai-socketio-event", - "version": "2.0.3", - "description": "`@tarotmilktea/ai-socketio-event` is a TypeScript library facilitating consistent and type-safe communication between frontend and backend WebSocket components, ensuring cross-layer reliability and ease of maintenance.", - "main": "index.js", - "types": "index.d.ts", - "files": [ - "index.d.ts" - ], - "author": "tarotmilktea ", - "license": "MIT", - "homepage": "https://github.com/boostcampwm2023/web09-MagicConch/tree/release/packages/ai-socketio-event#readme" -} diff --git a/packages/ai-socketio-event/pnpm-lock.yaml b/packages/ai-socketio-event/pnpm-lock.yaml deleted file mode 100644 index 2b9f1883..00000000 --- a/packages/ai-socketio-event/pnpm-lock.yaml +++ /dev/null @@ -1,5 +0,0 @@ -lockfileVersion: '6.0' - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false diff --git a/packages/human-socketio-event/LICENSE b/packages/human-socketio-event/LICENSE deleted file mode 100644 index e101c998..00000000 --- a/packages/human-socketio-event/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 David Fong - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/packages/human-socketio-event/README.md b/packages/human-socketio-event/README.md deleted file mode 100644 index cfa52190..00000000 --- a/packages/human-socketio-event/README.md +++ /dev/null @@ -1 +0,0 @@ -# @tarotmilktea/human-socketio-event diff --git a/packages/human-socketio-event/index.d.ts b/packages/human-socketio-event/index.d.ts deleted file mode 100644 index 664ce190..00000000 --- a/packages/human-socketio-event/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type HumanServerEvent = "welcome" | "offer" | "answer" | "candidate" | "roomFull" | "userExit" | "hostExit" | "roomCreated" | "joinRoomFailed" | "joinRoomSuccess" | "createRoomFailed" | "createRoomSuccess" | "roomNameGenerated" | "roomExist" | "roomNotExist"; -export type HumanClientEvent = "offer" | "answer" | "candidate" | "joinRoom" | "createRoom" | "generateRoomName" | "checkRoomExist"; diff --git a/packages/human-socketio-event/index.js b/packages/human-socketio-event/index.js deleted file mode 100644 index 35cc4164..00000000 --- a/packages/human-socketio-event/index.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - HumanServerEvent, - HumanClientEvent, -}; diff --git a/packages/human-socketio-event/package.json b/packages/human-socketio-event/package.json deleted file mode 100644 index 00988c5c..00000000 --- a/packages/human-socketio-event/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "@tarotmilktea/human-socketio-event", - "version": "2.0.2", - "description": "`@tarotmilktea/human-socketio-event` is a TypeScript library facilitating consistent and type-safe communication between frontend and backend WebSocket components, ensuring cross-layer reliability and ease of maintenance.", - "main": "index.js", - "types": "index.d.ts", - "files": [ - "index.d.ts" - ], - "author": "tarotmilktea ", - "license": "MIT", - "homepage": "https://github.com/boostcampwm2023/web09-MagicConch/tree/release/packages/human-socketio-event#readme" -} From 0abec7f30a634e25192085ca62a4e6ba1853b5d4 Mon Sep 17 00:00:00 2001 From: HeoJiye Date: Thu, 22 Feb 2024 17:57:59 +0900 Subject: [PATCH 03/13] =?UTF-8?q?feat:=20=EC=99=B8=EB=B6=80=EC=97=90=20soc?= =?UTF-8?q?ket=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- @types/event.d.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 @types/event.d.ts diff --git a/@types/event.d.ts b/@types/event.d.ts new file mode 100644 index 00000000..3b4529c2 --- /dev/null +++ b/@types/event.d.ts @@ -0,0 +1,23 @@ +interface AiSocketEvent { + ServerToClientEvent: { + streamStart: () => void; + streaming: (token: string) => void; + streamEnd: () => void; + tarotCard: () => void; // 타로 카드 펼치기 요청 + chatEnd: (resultId: string) => void; + error: (message: string) => void; + }; + ClientToServerEvent: { + message: (message: string) => void; + tarotRead: (cardIdx: number) => void; // 타로 카드 해설 요청 + }; + InterServerEvents: {}; + SocketData: {}; +} + +interface HumanSocketEvent { + ServerToClientEvent: {}; + ClientToServerEvent: {}; + InterServerEvents: {}; + SocketData: {}; +} From db88cb29e0d99c38de95f7164a04c71f79db4e59 Mon Sep 17 00:00:00 2001 From: HeoJiye Date: Thu, 22 Feb 2024 17:58:32 +0900 Subject: [PATCH 04/13] =?UTF-8?q?feat:=20frontend=20=EC=AA=BD=20socket=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=ED=83=80=EC=9E=85=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/SocketManager/AISocketManager.ts | 14 +++----------- .../services/SocketManager/HumanSocketManager.ts | 12 ++---------- .../services/SocketManager/SocketManager.ts | 16 ++++++++++------ frontend/tsconfig.json | 4 ++-- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/frontend/src/business/services/SocketManager/AISocketManager.ts b/frontend/src/business/services/SocketManager/AISocketManager.ts index 21ccc93c..4bead895 100644 --- a/frontend/src/business/services/SocketManager/AISocketManager.ts +++ b/frontend/src/business/services/SocketManager/AISocketManager.ts @@ -1,6 +1,6 @@ -import { SocketManager } from '.'; +import { SocketManager } from './SocketManager'; -export class AISocketManager extends SocketManager { +export class AISocketManager extends SocketManager { static instance: AISocketManager | null = null; private constructor() { @@ -17,12 +17,4 @@ export class AISocketManager extends SocketManager { connect() { super.connect({ withCredentials: true }); } - - on(eventName: string, eventListener: (args: U) => void) { - super.on(eventName, eventListener); - } - - emit(eventName: string, ...eventArgs: unknown[]) { - super.emit(eventName, ...eventArgs); - } -} +} \ No newline at end of file diff --git a/frontend/src/business/services/SocketManager/HumanSocketManager.ts b/frontend/src/business/services/SocketManager/HumanSocketManager.ts index 489d8f1b..27b3df17 100644 --- a/frontend/src/business/services/SocketManager/HumanSocketManager.ts +++ b/frontend/src/business/services/SocketManager/HumanSocketManager.ts @@ -1,6 +1,6 @@ -import { SocketManager } from '.'; +import { SocketManager } from './SocketManager'; -export class HumanSocketManager extends SocketManager { +export class HumanSocketManager extends SocketManager { static instance: HumanSocketManager | null = null; private constructor() { @@ -13,12 +13,4 @@ export class HumanSocketManager extends SocketManager { } return this.instance; } - - on(eventName: string, eventListener: (args: U) => void) { - super.on(eventName, eventListener); - } - - emit(eventName: string, ...eventArgs: unknown[]) { - super.emit(eventName, ...eventArgs); - } } diff --git a/frontend/src/business/services/SocketManager/SocketManager.ts b/frontend/src/business/services/SocketManager/SocketManager.ts index b24f3903..9a273586 100644 --- a/frontend/src/business/services/SocketManager/SocketManager.ts +++ b/frontend/src/business/services/SocketManager/SocketManager.ts @@ -1,7 +1,11 @@ import { Socket, io } from 'socket.io-client'; -export class SocketManager { - #socket: Socket | undefined; +interface EventsMap { + [event: string]: any; +} + +export class SocketManager { + #socket: Socket | undefined; #url: string; #path?: string; @@ -35,17 +39,17 @@ export class SocketManager { this.#socket = undefined; } - on(eventName: string, eventListener: (args: U) => void) { + on(...params: Parameters) { if (!this.socket) { throw new Error('소켓이 존재하지 않습니다.'); } - this.socket.on(eventName, eventListener); + this.socket.on(...params); } - emit(eventName: string, ...eventArgs: unknown[]) { + emit(...params: Parameters) { if (!this.socket) { throw new Error('소켓이 존재하지 않습니다.'); } - this.socket.emit(eventName, ...eventArgs); + this.socket.emit(...params); } } diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 575b570d..1fd0d51d 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -32,7 +32,7 @@ }, }, - "typeRoots": ["./node_modules/@types", "./src/@types"], - "include": ["src", "@types", ".src/setup-vitest.ts", "__mocks__"], + "typeRoots": ["./node_modules/@types", "./src/@types", "../@types"], + "include": ["src", "@types", ".src/setup-vitest.ts", "__mocks__", "../@types"], "references": [{ "path": "./tsconfig.node.json" }] } From a8a170c083cf7265bf6e304997cd8c92625a8030 Mon Sep 17 00:00:00 2001 From: HeoJiye Date: Thu, 22 Feb 2024 17:59:17 +0900 Subject: [PATCH 05/13] =?UTF-8?q?feat:=20was=20=EC=AA=BD=20socket=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=ED=83=80=EC=9E=85=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/was/src/common/types/socket.ts | 19 ++++++++-- backend/was/src/socket/socket.gateway.ts | 44 ++++++++++++++---------- backend/was/src/socket/socket.service.ts | 14 ++++---- backend/was/tsconfig.json | 4 ++- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/backend/was/src/common/types/socket.ts b/backend/was/src/common/types/socket.ts index cda44249..404ebb84 100644 --- a/backend/was/src/common/types/socket.ts +++ b/backend/was/src/common/types/socket.ts @@ -1,12 +1,27 @@ -import { Socket as originalSocket } from 'socket.io'; +import { Server, Socket } from 'socket.io'; import { ChatLog } from './chatbot'; export interface UserInfo { email: string; providerId: number; } -export interface Socket extends originalSocket { + +export type AiServer = Server< + AiSocketEvent['ClientToServerEvent'], + AiSocketEvent['ServerToClientEvent'] +>; + +export interface AiSocket + extends Socket< + AiSocketEvent['ClientToServerEvent'], + AiSocketEvent['ServerToClientEvent'] + > { user?: UserInfo; chatLog: ChatLog[]; chatEnd: boolean; } + +export type AiSocketClientEvent = keyof AiSocketEvent['ClientToServerEvent']; + +export type AiSocketClientEventParams = + Parameters; diff --git a/backend/was/src/socket/socket.gateway.ts b/backend/was/src/socket/socket.gateway.ts index cb245988..bca70f95 100644 --- a/backend/was/src/socket/socket.gateway.ts +++ b/backend/was/src/socket/socket.gateway.ts @@ -8,9 +8,13 @@ import { WebSocketServer, } from '@nestjs/websockets'; import * as dotenv from 'dotenv'; -import { Server } from 'socket.io'; import { SocketJwtAuthGuard } from 'src/auth/guard'; -import type { Socket } from 'src/common/types/socket'; +import type { + AiServer, + AiSocket, + AiSocketClientEvent, + AiSocketClientEventParams, +} from 'src/common/types/socket'; import { LoggerService } from 'src/logger/logger.service'; import { SocketService } from './socket.service'; @@ -23,50 +27,52 @@ export class SocketGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect { @WebSocketServer() - readonly server: Server; + readonly server: AiServer; constructor( private readonly socketService: SocketService, private readonly logger: LoggerService, ) {} - afterInit(server: Server) { + afterInit(server: AiServer) { this.logger.info('🚀 웹소켓 서버 초기화'); } - handleConnection(client: any) { + handleConnection(client: AiSocket) { this.logger.debug(`🚀 Client Connected : ${client.id}`); this.socketService.initClient(client); this.socketService.sendWelcomeMessage(client); } - @SubscribeMessage('message') - async handleMessageEvent(client: Socket, message: string) { + @SubscribeMessage('message') + async handleMessageEvent( + client: AiSocket, + ...params: AiSocketClientEventParams<'message'> + ) { this.logger.debug(`🚀 Received a message from ${client.id}`); - const sentMessage = await this.socketService.handleMessageEvent( - client, - message, - ); - this.logger.debug(`🚀 Send a message to ${client.id}: ${sentMessage}`); + await this.socketService.handleMessageEvent(client, ...params); + + this.logger.debug(`🚀 Send a message to ${client.id}`); } @UseGuards(SocketJwtAuthGuard) - @SubscribeMessage('tarotRead') - async handleTarotReadEvent(client: Socket, cardIdx: number) { - this.logger.debug( - `🚀 TarotRead request received from ${client.id}: ${cardIdx}`, - ); + @SubscribeMessage('tarotRead') + async handleTarotReadEvent( + client: AiSocket, + ...params: AiSocketClientEventParams<'tarotRead'> + ) { + this.logger.debug(`🚀 TarotRead request received from ${client.id}`); const sentMessage = await this.socketService.handleTarotReadEvent( client, - cardIdx, + ...params, ); this.logger.debug(`🚀 Send a message to ${client.id}: ${sentMessage}`); } - handleDisconnect(client: Socket) { + handleDisconnect(client: AiSocket) { this.logger.debug(`🚀 Client Disconnected : ${client.id}`); } } diff --git a/backend/was/src/socket/socket.service.ts b/backend/was/src/socket/socket.service.ts index ec1a4215..2ae306ba 100644 --- a/backend/was/src/socket/socket.service.ts +++ b/backend/was/src/socket/socket.service.ts @@ -9,7 +9,7 @@ import { WELCOME_MESSAGE, } from 'src/common/constants/socket'; import { ChatLog } from 'src/common/types/chatbot'; -import type { Socket, UserInfo } from 'src/common/types/socket'; +import type { AiSocket } from 'src/common/types/socket'; import { readStream, string2Uint8ArrayStream } from 'src/common/utils/stream'; import { LoggerService } from 'src/logger/logger.service'; import { CreateTarotResultDto } from 'src/tarot/dto'; @@ -24,12 +24,12 @@ export class SocketService { private readonly logger: LoggerService, ) {} - initClient(client: Socket) { + initClient(client: AiSocket) { client.chatLog = []; client.chatEnd = false; } - async sendWelcomeMessage(client: Socket) { + async sendWelcomeMessage(client: AiSocket) { try { const sentMessage = await this.streamMessage(client, () => string2Uint8ArrayStream(WELCOME_MESSAGE), @@ -47,7 +47,7 @@ export class SocketService { } } - async handleMessageEvent(client: Socket, message: string) { + async handleMessageEvent(client: AiSocket, message: string) { try { const sentMessage = await this.streamMessage(client, () => this.chatbotService.generateTalk(client.chatLog, message), @@ -76,7 +76,7 @@ export class SocketService { } } - async handleTarotReadEvent(client: Socket, cardIdx: number) { + async handleTarotReadEvent(client: AiSocket, cardIdx: number) { try { const sentMessage = await this.streamMessage(client, () => this.chatbotService.generateTarotReading(client.chatLog, cardIdx), @@ -105,7 +105,7 @@ export class SocketService { } async streamMessage( - client: Socket, + client: AiSocket, generateStream: () => Promise>, ) { client.emit('streamStart'); @@ -120,7 +120,7 @@ export class SocketService { return sentMessage; } - private async createRoom(client: Socket) { + private async createRoom(client: AiSocket) { try { const chattingInfo = await this.chatService.createRoom(client.user); return chattingInfo; diff --git a/backend/was/tsconfig.json b/backend/was/tsconfig.json index a1c778d1..9f31220a 100644 --- a/backend/was/tsconfig.json +++ b/backend/was/tsconfig.json @@ -17,5 +17,7 @@ "strictBindCallApply": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true - } + }, + "typeRoots": ["../../@types"], + "include": ["src", "../../@types"] } From b7a7280bc83bd0079874829405ec6806cd9b5958 Mon Sep 17 00:00:00 2001 From: HeoJiye Date: Fri, 23 Feb 2024 09:29:44 +0900 Subject: [PATCH 06/13] =?UTF-8?q?style:=20prettier=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/business/services/SocketManager/AISocketManager.ts | 7 +++++-- .../business/services/SocketManager/HumanSocketManager.ts | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/frontend/src/business/services/SocketManager/AISocketManager.ts b/frontend/src/business/services/SocketManager/AISocketManager.ts index 4bead895..1092b47c 100644 --- a/frontend/src/business/services/SocketManager/AISocketManager.ts +++ b/frontend/src/business/services/SocketManager/AISocketManager.ts @@ -1,6 +1,9 @@ import { SocketManager } from './SocketManager'; -export class AISocketManager extends SocketManager { +export class AISocketManager extends SocketManager< + AiSocketEvent['ServerToClientEvent'], + AiSocketEvent['ClientToServerEvent'] +> { static instance: AISocketManager | null = null; private constructor() { @@ -17,4 +20,4 @@ export class AISocketManager extends SocketManager { +export class HumanSocketManager extends SocketManager< + HumanSocketEvent['ServerToClientEvent'], + HumanSocketEvent['ClientToServerEvent'] +> { static instance: HumanSocketManager | null = null; private constructor() { From 249f8b0053f819e2ff2904a45ba8dba746d0a00b Mon Sep 17 00:00:00 2001 From: HeoJiye Date: Fri, 23 Feb 2024 09:30:21 +0900 Subject: [PATCH 07/13] =?UTF-8?q?feat:=20socketManager=20on,=20emit=20?= =?UTF-8?q?=EC=A0=95=ED=95=B4=EC=A7=84=20api=EB=A1=9C=EB=A7=8C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EA=B0=80=EB=8A=A5=ED=95=98=EA=B2=8C=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/SocketManager/SocketManager.ts | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/frontend/src/business/services/SocketManager/SocketManager.ts b/frontend/src/business/services/SocketManager/SocketManager.ts index 9a273586..09d11130 100644 --- a/frontend/src/business/services/SocketManager/SocketManager.ts +++ b/frontend/src/business/services/SocketManager/SocketManager.ts @@ -20,36 +20,36 @@ export class SocketManager { } get connected(): boolean { - if (!this.socket) return false; - return this.socket.connected; + if (!this.#socket) return false; + return this.#socket.connected; } connect({ withCredentials = false } = {}) { - if (this.socket?.connected) { + if (this.#socket?.connected) { return; } this.#socket = io(this.#url, { path: this.#path, withCredentials }); } disconnect() { - if (!this.socket?.connected) { + if (!this.#socket?.connected) { return; } - this.socket.disconnect(); + this.#socket.disconnect(); this.#socket = undefined; } - on(...params: Parameters) { - if (!this.socket) { + on(...params: Parameters['on']>) { + if (!this.#socket) { throw new Error('소켓이 존재하지 않습니다.'); } - this.socket.on(...params); + this.#socket.on(...params); } - emit(...params: Parameters) { - if (!this.socket) { + emit(...params: Parameters['emit']>) { + if (!this.#socket) { throw new Error('소켓이 존재하지 않습니다.'); } - this.socket.emit(...params); + this.#socket.emit(...params); } } From 64169261ed3d29d680c55f21733e2dc571e048a8 Mon Sep 17 00:00:00 2001 From: HeoJiye Date: Fri, 23 Feb 2024 09:30:43 +0900 Subject: [PATCH 08/13] =?UTF-8?q?feat:=20human=20socket=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=ED=83=80=EC=9E=85=20=EC=84=A0=EC=96=B8=20?= =?UTF-8?q?(=EC=9E=84=EC=8B=9C=EB=A1=9C=20=EC=A3=BC=EC=84=9D=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- @types/event.d.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/@types/event.d.ts b/@types/event.d.ts index 3b4529c2..9bac0260 100644 --- a/@types/event.d.ts +++ b/@types/event.d.ts @@ -16,8 +16,28 @@ interface AiSocketEvent { } interface HumanSocketEvent { - ServerToClientEvent: {}; - ClientToServerEvent: {}; + ServerToClientEvent: DefaultEventsMap; + // { + // connection: (data: { description?: RTCSessionDescription; candidate?: RTCIceCandidate }) => void; + // welcome: () => void; + // userExit: () => void; + // hostExit: () => void; + // roomCreated: () => void; + // roomNameGenerated: (roomId: string) => void; + // joinRoomFailed: () => void; + // joinRoomSuccess: () => void; + // roomExist: () => void; + // roomNotExist: () => void; + // roomFull: () => void; + // }; + ClientToServerEvent: DefaultEventsMap; + // { + // connection: (data: { description?: RTCSessionDescription; candidate?: RTCIceCandidate; roomName: string }) => void; + // generateRoomName: () => void; + // createRoom: (roomId: string, password: string) => void; + // joinRoom: (roomId: string, password: string) => void; + // checkRoomExist: (roomName: string) => void; + // }; InterServerEvents: {}; SocketData: {}; } From 2e31d289982d6c801754d8c3213adffa9c4f2474 Mon Sep 17 00:00:00 2001 From: HeoJiye Date: Fri, 23 Feb 2024 10:17:12 +0900 Subject: [PATCH 09/13] =?UTF-8?q?feat:=20signal=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=EC=97=90=EC=84=9C=20socket=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- @types/event.d.ts | 42 +++++----- backend/signal/src/events/events.gateway.ts | 92 ++++++++++----------- backend/signal/src/events/type.ts | 17 ++++ backend/signal/tsconfig.json | 4 +- 4 files changed, 84 insertions(+), 71 deletions(-) create mode 100644 backend/signal/src/events/type.ts diff --git a/@types/event.d.ts b/@types/event.d.ts index 9bac0260..d8b607d3 100644 --- a/@types/event.d.ts +++ b/@types/event.d.ts @@ -16,28 +16,26 @@ interface AiSocketEvent { } interface HumanSocketEvent { - ServerToClientEvent: DefaultEventsMap; - // { - // connection: (data: { description?: RTCSessionDescription; candidate?: RTCIceCandidate }) => void; - // welcome: () => void; - // userExit: () => void; - // hostExit: () => void; - // roomCreated: () => void; - // roomNameGenerated: (roomId: string) => void; - // joinRoomFailed: () => void; - // joinRoomSuccess: () => void; - // roomExist: () => void; - // roomNotExist: () => void; - // roomFull: () => void; - // }; - ClientToServerEvent: DefaultEventsMap; - // { - // connection: (data: { description?: RTCSessionDescription; candidate?: RTCIceCandidate; roomName: string }) => void; - // generateRoomName: () => void; - // createRoom: (roomId: string, password: string) => void; - // joinRoom: (roomId: string, password: string) => void; - // checkRoomExist: (roomName: string) => void; - // }; + ServerToClientEvent: { + connection: (data: { description?: RTCSessionDescription; candidate?: RTCIceCandidate }) => void; + welcome: (otherUsers: any) => void; + userExit: (data: { id: string }) => void; + hostExit: () => void; + roomCreated: () => void; + roomNameGenerated: (roomId: string) => void; + joinRoomFailed: () => void; + joinRoomSuccess: (roomId: string) => void; + roomExist: () => void; + roomNotExist: () => void; + roomFull: () => void; + }; + ClientToServerEvent: { + connection: (data: { description?: RTCSessionDescription; candidate?: RTCIceCandidate; roomName: string }) => void; + generateRoomName: () => void; + createRoom: (roomId: string, password: string) => void; + joinRoom: (roomId: string, password: string) => void; + checkRoomExist: (roomName: string) => void; + }; InterServerEvents: {}; SocketData: {}; } diff --git a/backend/signal/src/events/events.gateway.ts b/backend/signal/src/events/events.gateway.ts index 976e6fa9..96dea2f2 100644 --- a/backend/signal/src/events/events.gateway.ts +++ b/backend/signal/src/events/events.gateway.ts @@ -6,9 +6,14 @@ import { WebSocketGateway, WebSocketServer, } from '@nestjs/websockets'; -import { Server, Socket } from 'socket.io'; import { LoggerService } from 'src/logger/logger.service'; import { v4 } from 'uuid'; +import type { + HumanServer, + HumanSocket, + HumanSocketClientEvent, + HumanSocketClientEventParams, +} from './type'; const MAXIMUM = 2; @@ -22,20 +27,20 @@ export class EventsGateway constructor(private readonly logger: LoggerService) {} @WebSocketServer() - server: Server; + server: HumanServer; private socketRooms: any = {}; private users: any = {}; - afterInit(server: Server) { + afterInit(server: HumanServer) { this.logger.info('🚀 시그널링 서버 초기화'); } - handleConnection(socket: Socket) { + handleConnection(socket: HumanSocket) { this.logger.debug(`🚀 Client Connected : ${socket.id}`); } - handleDisconnect(socket: Socket) { + handleDisconnect(socket: HumanSocket) { this.logger.debug(`🚀 Client Disconnected : ${socket.id}`); const userId = socket.id; @@ -56,7 +61,7 @@ export class EventsGateway } if (role === 'host') { - this.eventEmitToRoom(socket, roomId, 'hostExit'); + socket.to(roomId).emit('hostExit'); delete this.socketRooms[roomId]; this.logger.debug(`🚀 host Exit from ${roomId}`); @@ -66,34 +71,40 @@ export class EventsGateway (_userId: string) => _userId !== userId, ); - this.eventEmitToRoom(socket, roomId, 'userExit', { id: userId }); + socket.to(roomId).emit('userExit', { id: userId }); this.logger.debug(`🚀 User Exit from ${roomId}`); } } - @SubscribeMessage('generateRoomName') - handleCreateRoomEvent(socket: Socket) { + @SubscribeMessage('generateRoomName') + handleCreateRoomEvent(socket: HumanSocket) { const roomId: string = v4(); - this.eventEmit(socket, 'roomNameGenerated', roomId); + socket.emit('roomNameGenerated', roomId); this.logger.debug(`🚀 Room Name Generated : ${roomId}`); } - @SubscribeMessage('createRoom') - handleSetRoomPassword(socket: Socket, [roomId, password]: [string, string]) { + @SubscribeMessage('createRoom') + handleSetRoomPassword( + socket: HumanSocket, + [roomId, password]: HumanSocketClientEventParams<'createRoom'>, + ) { const userId = socket.id; this.socketRooms[roomId] = { users: [userId], password: password }; this.users[userId] = { roomId, role: 'host' }; socket.join(roomId); - this.eventEmit(socket, 'roomCreated'); + socket.emit('roomCreated'); this.logger.debug(`🚀 Room Created : ${roomId}`); } - @SubscribeMessage('joinRoom') - handleJoinRoomEvent(socket: Socket, [roomId, password]: [string, string]) { + @SubscribeMessage('joinRoom') + handleJoinRoomEvent( + socket: HumanSocket, + [roomId, password]: HumanSocketClientEventParams<'joinRoom'>, + ) { const userId = socket.id; const existRoom: any = this.socketRooms[roomId]; @@ -101,7 +112,7 @@ export class EventsGateway this.socketRooms[roomId]?.password !== password; if (!existRoom || wrongPassword) { - this.eventEmit(socket, 'joinRoomFailed'); + socket.emit('joinRoomFailed'); const logMessage: string = !existRoom ? `🚀 Invalid Room : ${roomId}` : `🚀 Wrong Password for ${roomId}`; @@ -112,7 +123,7 @@ export class EventsGateway const fullRoom: boolean = this.socketRooms[roomId].users.length === MAXIMUM; if (fullRoom) { this.logger.debug(`🚀 Cannot Join to full room ${roomId}`); - this.eventEmit(socket, 'roomFull'); + socket.emit('roomFull'); return; } @@ -124,58 +135,43 @@ export class EventsGateway const otherUsers = this.socketRooms[roomId].users.filter( (_userId: string) => _userId !== userId, ); - this.eventEmitToRoom(socket, roomId, 'welcome', otherUsers); - this.eventEmit(socket, 'joinRoomSuccess', roomId); + socket.to(roomId).emit('welcome', otherUsers); + socket.emit('joinRoomSuccess', roomId); } - @SubscribeMessage('connection') + @SubscribeMessage('connection') handleConnectionEvent( - socket: Socket, - { - description, - candidate, - roomName, - }: { - description?: RTCSessionDescription; - candidate?: RTCIceCandidate; - roomName: string; - }, + socket: HumanSocket, + [ + { description, candidate, roomName }, + ]: HumanSocketClientEventParams<'connection'>, ) { try { if (description) { this.logger.debug(`🚀 ${description.type} Received from ${socket.id}`); - this.eventEmitToRoom(socket, roomName, 'connection', { description }); + socket.to(roomName).emit('connection', { description }); } else if (candidate) { this.logger.debug(`🚀 Candidate Received from ${socket.id}`); - this.eventEmitToRoom(socket, roomName, 'connection', { candidate }); + socket.to(roomName).emit('connection', { candidate }); } } catch (error) { this.logger.error(`🚀 Error in handleMessageEvent : ${error}`); } } - @SubscribeMessage('checkRoomExist') - handleCheckRoomExistEvent(socket: Socket, roomName: string) { + @SubscribeMessage('checkRoomExist') + handleCheckRoomExistEvent( + socket: HumanSocket, + [roomName]: HumanSocketClientEventParams<'checkRoomExist'>, + ) { const existRoom: any = this.socketRooms[roomName]; if (existRoom) { - this.eventEmit(socket, 'roomExist'); + socket.emit('roomExist'); this.logger.debug(`🚀 Room Exist : ${roomName}`); } else { - this.eventEmit(socket, 'roomNotExist'); + socket.emit('roomNotExist'); this.logger.debug(`🚀 Room Not Exist : ${roomName}`); } } - - public eventEmit(socket: Socket, event: string, ...args: any[]) { - socket.emit(event, ...args); - } - public eventEmitToRoom( - socket: Socket, - roomName: string, - event: string, - ...args: any[] - ) { - socket.to(roomName).emit(event, ...args); - } } diff --git a/backend/signal/src/events/type.ts b/backend/signal/src/events/type.ts new file mode 100644 index 00000000..92968ba4 --- /dev/null +++ b/backend/signal/src/events/type.ts @@ -0,0 +1,17 @@ +import { Server, Socket } from 'socket.io'; + +export type HumanServer = Server< + HumanSocketEvent['ClientToServerEvent'], + HumanSocketEvent['ServerToClientEvent'] +>; + +export type HumanSocket = Socket< + HumanSocketEvent['ClientToServerEvent'], + HumanSocketEvent['ServerToClientEvent'] +>; + +export type HumanSocketClientEvent = + keyof HumanSocketEvent['ClientToServerEvent']; + +export type HumanSocketClientEventParams = + Parameters; diff --git a/backend/signal/tsconfig.json b/backend/signal/tsconfig.json index a7e94a9a..7258faeb 100644 --- a/backend/signal/tsconfig.json +++ b/backend/signal/tsconfig.json @@ -17,5 +17,7 @@ "strictBindCallApply": false, "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": true - } + }, + "typeRoots": ["../../@types"], + "include": ["src", "../../@types"] } From e0f1b48e98317297fc67b3b3a22baebd295f9109 Mon Sep 17 00:00:00 2001 From: HeoJiye Date: Fri, 23 Feb 2024 10:17:49 +0900 Subject: [PATCH 10/13] =?UTF-8?q?chore:=20human=20socket=20manger=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=9D=BC=EB=8B=A8=20any=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=A0=81=EC=9A=A9=20(=ED=83=80=EC=9E=85?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=EC=A0=90=EA=B2=80=20=ED=95=84=EC=9A=94?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/SocketManager/HumanSocketManager.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/business/services/SocketManager/HumanSocketManager.ts b/frontend/src/business/services/SocketManager/HumanSocketManager.ts index 8c485a2c..ed26deb3 100644 --- a/frontend/src/business/services/SocketManager/HumanSocketManager.ts +++ b/frontend/src/business/services/SocketManager/HumanSocketManager.ts @@ -1,9 +1,11 @@ import { SocketManager } from './SocketManager'; -export class HumanSocketManager extends SocketManager< - HumanSocketEvent['ServerToClientEvent'], - HumanSocketEvent['ClientToServerEvent'] -> { +// export class HumanSocketManager extends SocketManager< +// HumanSocketEvent['ServerToClientEvent'], +// HumanSocketEvent['ClientToServerEvent'] +// > { + +export class HumanSocketManager extends SocketManager { static instance: HumanSocketManager | null = null; private constructor() { From d933414e20d2e1cf31b7657b4d28463ccb33d3a3 Mon Sep 17 00:00:00 2001 From: Song_Minhyung Date: Fri, 23 Feb 2024 15:24:11 +0900 Subject: [PATCH 11/13] =?UTF-8?q?feat:=20HumanSocketManager=EC=97=90=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EB=90=9C=20=ED=83=80=EC=9E=85=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/SocketManager/HumanSocketManager.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/frontend/src/business/services/SocketManager/HumanSocketManager.ts b/frontend/src/business/services/SocketManager/HumanSocketManager.ts index ed26deb3..8c485a2c 100644 --- a/frontend/src/business/services/SocketManager/HumanSocketManager.ts +++ b/frontend/src/business/services/SocketManager/HumanSocketManager.ts @@ -1,11 +1,9 @@ import { SocketManager } from './SocketManager'; -// export class HumanSocketManager extends SocketManager< -// HumanSocketEvent['ServerToClientEvent'], -// HumanSocketEvent['ClientToServerEvent'] -// > { - -export class HumanSocketManager extends SocketManager { +export class HumanSocketManager extends SocketManager< + HumanSocketEvent['ServerToClientEvent'], + HumanSocketEvent['ClientToServerEvent'] +> { static instance: HumanSocketManager | null = null; private constructor() { From b976289932d1f003a7f67cf133459bf16378ec91 Mon Sep 17 00:00:00 2001 From: Song_Minhyung Date: Fri, 23 Feb 2024 15:33:47 +0900 Subject: [PATCH 12/13] =?UTF-8?q?feat:=20socket=20event=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20connection=20=EB=B6=80=EB=B6=84=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 - null 타입이 추가 되어야해서 추가함 --- @types/event.d.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/@types/event.d.ts b/@types/event.d.ts index d8b607d3..14745747 100644 --- a/@types/event.d.ts +++ b/@types/event.d.ts @@ -17,7 +17,10 @@ interface AiSocketEvent { interface HumanSocketEvent { ServerToClientEvent: { - connection: (data: { description?: RTCSessionDescription; candidate?: RTCIceCandidate }) => void; + connection: (data: { + description?: RTCSessionDescription | null; + candidate?: RTCIceCandidate | null; + }) => void; welcome: (otherUsers: any) => void; userExit: (data: { id: string }) => void; hostExit: () => void; @@ -30,7 +33,11 @@ interface HumanSocketEvent { roomFull: () => void; }; ClientToServerEvent: { - connection: (data: { description?: RTCSessionDescription; candidate?: RTCIceCandidate; roomName: string }) => void; + connection: (data: { + description?: RTCSessionDescription | null; + candidate?: RTCIceCandidate | null; + roomName: string; + }) => void; generateRoomName: () => void; createRoom: (roomId: string, password: string) => void; joinRoom: (roomId: string, password: string) => void; From 6d9338b424ef12e8595cfffd977d949da17a4c0c Mon Sep 17 00:00:00 2001 From: Song_Minhyung Date: Fri, 23 Feb 2024 15:34:51 +0900 Subject: [PATCH 13/13] =?UTF-8?q?test:=20=EB=B3=80=EA=B2=BD=EB=90=9C=20?= =?UTF-8?q?=EC=86=8C=EC=BC=93=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/HumanSocketManager.spec.ts | 61 ++++++++++++++++--- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/frontend/src/business/services/SocketManager/__tests__/HumanSocketManager.spec.ts b/frontend/src/business/services/SocketManager/__tests__/HumanSocketManager.spec.ts index 125fa04c..b08e5a2f 100644 --- a/frontend/src/business/services/SocketManager/__tests__/HumanSocketManager.spec.ts +++ b/frontend/src/business/services/SocketManager/__tests__/HumanSocketManager.spec.ts @@ -21,7 +21,7 @@ describe('HumanSocketManager 클래스 테스트', () => { it('on(): super.on()을 호출한다.', () => { const socketManager = HumanSocketManager.getInstance(); const spyOn = vi.spyOn(SocketManager.prototype, 'on'); - const eventName = 'answer'; + const eventName = 'eventName' as any; const eventListener = vi.fn(); socketManager.connect(); @@ -30,15 +30,58 @@ describe('HumanSocketManager 클래스 테스트', () => { expect(spyOn).toBeCalledWith(eventName, eventListener); }); - it('emit(): super.emit()을 호출한다.', () => { - const socketManager = HumanSocketManager.getInstance(); - const spyOn = vi.spyOn(SocketManager.prototype, 'emit'); - const eventName = 'answer'; - const eventArgs = ['test']; + describe('emit(): super.emit()을 호출한다.', () => { + [ + { + scenario: 'data: { description: RTCSessionDescription; roomName: string } 형식 인수 emit', + eventName: 'connection' as any, + eventArgs: [{ description: 'description', roomName: 'roomName' }], + }, + { + scenario: 'data: { candidate: RTCIceCandidate; roomName: string } 형식 인수 emit', + eventName: 'connection' as any, + eventArgs: [{ candidate: 'candidate', roomName: 'roomName' }], + }, + { + scenario: 'roomName: string 형식 인수 emit', + eventName: 'checkRoomExist' as any, + eventArgs: ['roomName'], + }, + { + scenario: 'roomId: string, password: string 형식 인수 emit', + eventName: 'createRoom' as any, + eventArgs: ['roomId', 'password'], + }, + ].forEach(({ scenario, eventName, eventArgs }: { scenario: string; eventName: any; eventArgs: any[] }) => { + it(scenario, () => { + const socketManager = HumanSocketManager.getInstance(); + const spyOn = vi.spyOn(SocketManager.prototype, 'emit'); - socketManager.connect(); - socketManager.emit(eventName, ...eventArgs); + socketManager.connect(); + + if (eventArgs.length === 0) { + socketManager.emit(eventName); + } + if (eventArgs.length === 1) { + socketManager.emit(eventName, eventArgs[0]); + } + if (eventArgs.length === 2) { + socketManager.emit(eventName, eventArgs[0], eventArgs[1]); + } - expect(spyOn).toBeCalledWith(eventName, ...eventArgs); + expect(spyOn).toBeCalledWith(eventName, ...eventArgs); + }); + }); }); + // it('', () => { + // const socketManager = HumanSocketManager.getInstance(); + // const spyOn = vi.spyOn(SocketManager.prototype, 'emit'); + // const eventName = 'answer' as any; + // const eventArgs = ['id', 'password'] as [string, string]; + + // socketManager.connect(); + // socketManager.emit(eventName, ...eventArgs); + + // expect(spyOn).toBeCalledWith(eventName, ...eventArgs); + // }); });