Skip to content

Commit

Permalink
Handle player join
Browse files Browse the repository at this point in the history
  • Loading branch information
takumihara committed Feb 22, 2024
1 parent c05e918 commit 08d529e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions backend/src/events/events.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions frontend/app/pong/[id]/PongBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ function PongBoard({ id }: PongBoardProps) {
});
}
break;
case "ready": {
{
const { user } = payload;
setRightPlayer(user);
}
break;
}
}
},
[currentUser, setUserMode, getGame, getPlayerSetterFromPlayerNumber],
Expand Down

0 comments on commit 08d529e

Please sign in to comment.