feat: improve reconnect, add ESLint configuration for common and socket

This commit is contained in:
Ralex
2025-10-19 00:37:26 +02:00
parent 8bdb8f47ef
commit 96bff164c0
36 changed files with 1571 additions and 677 deletions

View File

@@ -1,29 +1,28 @@
import { Socket } from "@rahoot/common/types/game/socket"
import Game from "@rahoot/socket/services/game"
import Registry from "@rahoot/socket/services/registry"
export const withGame = <T>(
export const withGame = (
gameId: string | undefined,
socket: Socket,
games: Game[],
handler: (game: Game) => T
): T | void => {
let game = null
if (gameId) {
game = games.find((g) => g.gameId === gameId)
} else {
game = games.find(
(g) =>
g.players.find((p) => p.id === socket.id) || g.manager.id === socket.id
)
}
if (!game) {
callback: (_game: Game) => void
): void => {
if (!gameId) {
socket.emit("game:errorMessage", "Game not found")
return
}
return handler(game)
const registry = Registry.getInstance()
const game = registry.getGameById(gameId)
if (!game) {
socket.emit("game:errorMessage", "Game not found")
return
}
callback(game)
}
export const createInviteCode = (length = 6) => {
@@ -50,25 +49,3 @@ export const timeToPoint = (startTime: number, secondes: number): number => {
return points
}
export const findPlayerGameByClientId = (clientId: string, games: Game[]) => {
const playerGame = games.find((g) =>
g.players.find((p) => p.clientId === clientId)
)
if (playerGame) {
return playerGame
}
return null
}
export const findManagerGameByClientId = (clientId: string, games: Game[]) => {
const managerGame = games.find((g) => g.manager.clientId === clientId)
if (managerGame) {
return managerGame
}
return null
}