From 08d529e8ca13a1e5ed758d2dfc1350cf40431091 Mon Sep 17 00:00:00 2001 From: Takumi Hara Date: Thu, 22 Feb 2024 01:21:06 -0600 Subject: [PATCH] Handle player join --- backend/src/events/events.gateway.ts | 7 +++++-- frontend/app/pong/[id]/PongBoard.tsx | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/src/events/events.gateway.ts b/backend/src/events/events.gateway.ts index 2fbb8404..3c12f521 100644 --- a/backend/src/events/events.gateway.ts +++ b/backend/src/events/events.gateway.ts @@ -139,8 +139,11 @@ export class EventsGateway implements OnGatewayDisconnect { user, }); this.emitUpdateStatus(client, 'joined-as-player'); - if (Object.keys(this.players[gameId]).length == 2) { - this.emitUpdateStatus(client, 'ready'); + const opponent = getOpponent(this.players, gameId, client.id); + if (opponent) { + this.emitUpdateStatus(client, 'ready', { + user: this.users[opponent], + }); } this.lostPoints[client.id] = 0; return; diff --git a/frontend/app/pong/[id]/PongBoard.tsx b/frontend/app/pong/[id]/PongBoard.tsx index fc92fa1c..af703653 100644 --- a/frontend/app/pong/[id]/PongBoard.tsx +++ b/frontend/app/pong/[id]/PongBoard.tsx @@ -180,6 +180,13 @@ function PongBoard({ id }: PongBoardProps) { }); } break; + case "ready": { + { + const { user } = payload; + setRightPlayer(user); + } + break; + } } }, [currentUser, setUserMode, getGame, getPlayerSetterFromPlayerNumber],