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); }