From 749b560d0305e7e95b71388b166f8cbfb223df8f Mon Sep 17 00:00:00 2001 From: nowChae <99425616+nowChae@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:44:22 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20timelimit=20=EC=9D=B8=EC=8B=9D=20?= =?UTF-8?q?=EB=AA=BB=ED=95=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=20(#87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/src/module/game/game.gateway.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/server/src/module/game/game.gateway.ts b/packages/server/src/module/game/game.gateway.ts index 12037105..072f6cd0 100644 --- a/packages/server/src/module/game/game.gateway.ts +++ b/packages/server/src/module/game/game.gateway.ts @@ -24,6 +24,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect { private readonly redisService: RedisService, private readonly gameService: GameService, ) {} + // 클라이언트가 연결했을 때 처리하는 메서드 async handleConnection(client: Socket) { console.log(`Client connected: ${client.id}`); @@ -31,6 +32,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect { // 클라이언트가 연결을 끊었을 때 처리하는 메서드 async handleDisconnect(client: Socket) { + //대기 중에 사람이 나갈 경우 갱신해주는 부분 추가 필요 console.log(`Client disconnected: ${client.id}`); } @@ -100,27 +102,26 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect { // 만일 레디스에 퀴즈가 저장되어있지않다면, 퀴즈를 다시 캐싱해오는 로직이 필요할지도. const quizData = JSON.parse(await this.redisService.get(`classId=${classId}`)); - // {id, content, choice[]} const currentQuizData = quizData[currentOrder]; - // this.server.to(pinCode).emit('show quiz', currentQuizData); client.emit('show quiz', currentQuizData); client.to(pinCode).emit('show quiz', currentQuizData); - gameInfo.currentOrder += 1; + //gameInfo.currentOrder += 1; await this.redisService.set(`gameId=${pinCode}`, JSON.stringify(gameInfo)); - setTimeout(() => { - this.startTimer(pinCode, currentQuizData.timeLimit); - }, 2000); - - // redis currentOrder + 1 + // 로딩 2초 지나면, 시간잰다고 알림 + // setTimeout(() => { + // client.emit('time check', { is_timestart: true }); + // this.startTimer(client, pinCode, currentQuizData['timeLimit']); + // }, 2000); } - startTimer(pinCode: string, timeLimit: number) { + startTimer(client: Socket, pinCode: string, timeLimit: number) { // 제한시간이 끝나면. setTimeout(() => { - this.server.to(pinCode).emit('timeout', {}); + client.emit('timeout', { is_timeout: true }); + client.to(pinCode).emit('timeout', { is_timeout: true }); }, timeLimit * 1000); }