Skip to content

Commit

Permalink
fix: timelimit 인식 못하는 문제 해결 (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
nowChae authored Nov 19, 2024
1 parent 354f863 commit 749b560
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/server/src/module/game/game.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
private readonly redisService: RedisService,
private readonly gameService: GameService,
) {}

// 클라이언트가 연결했을 때 처리하는 메서드
async handleConnection(client: Socket) {
console.log(`Client connected: ${client.id}`);
}

// 클라이언트가 연결을 끊었을 때 처리하는 메서드
async handleDisconnect(client: Socket) {
//대기 중에 사람이 나갈 경우 갱신해주는 부분 추가 필요
console.log(`Client disconnected: ${client.id}`);
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 749b560

Please sign in to comment.