add spectatorIds to game

This commit is contained in:
Halit Aksoy 2022-09-02 00:33:31 +03:00
parent 9f9160eaf6
commit 7a88eb4f54
3 changed files with 13 additions and 0 deletions

View File

@ -12,4 +12,6 @@ export interface GameStore {
setGameByUser(userId: string, game: Game): void; setGameByUser(userId: string, game: Game): void;
getGameByUser(userId: string): Game | undefined; getGameByUser(userId: string): Game | undefined;
removeGameByPlayer(userId: string): void; removeGameByPlayer(userId: string): void;
getSpeactatingGameIdsByUser(userId: string): string[]
} }

View File

@ -35,4 +35,14 @@ export class GameStoreImpl implements GameStore {
removeGameByPlayer(userId: string): void { removeGameByPlayer(userId: string): void {
this.removeGameIdByPlayer(userId); this.removeGameIdByPlayer(userId);
} }
getSpeactatingGameIdsByUser(userId: string): string[] {
const speactatingGameIds = [];
for (const gameId in this.gameStore.keys()) {
const game = this.gameStore.get(gameId) as Game;
const isSpectator = game.spectatorIds.find((value) => value === userId);
isSpectator && speactatingGameIds.push(game.id);
}
return speactatingGameIds;
}
} }

View File

@ -5,6 +5,7 @@ export interface Game {
id: string; id: string;
mancalaGame: MancalaGame; mancalaGame: MancalaGame;
gameUsersConnectionInfo: GameUsersConnectionInfo; gameUsersConnectionInfo: GameUsersConnectionInfo;
spectatorIds: string[];
} }
export interface GameUsersConnectionInfo { export interface GameUsersConnectionInfo {