@@ -44,7 +44,7 @@ export type GameServices = NamespaceProxyTarget<
4444
4545export type ClientEmitEvents = NonNullable <
4646 Awaited < ReturnType < typeof createGameSocket > >
47- > [ "client" ] [ "emitEvents" ] ;
47+ > [ "client" ] [ "emitEvents" ] ;
4848
4949const checkAndAssociatePlayer = async (
5050 currentGame : CurrentGame ,
@@ -178,7 +178,8 @@ const startRound = (socket: GameServices) => {
178178
179179const finishRound = async ( gameServices : GameServices ) => {
180180 const { _socket, ...events } = gameServices ;
181- let { currentRound, currentGame } = _socket . data ;
181+ let { currentRound } = _socket . data ;
182+ const currentGame = _socket . data . currentGame ;
182183 console . log ( `Round ${ currentRound . id } finished` ) ;
183184 const missingScores = await getPlayersMissingRoundScore (
184185 _socket . data . currentRound ,
@@ -203,8 +204,7 @@ const finishRound = async (gameServices: GameServices) => {
203204 } else {
204205 currentRound = await setRoundTimes (
205206 currentGame ! . rounds . find (
206- ( { roundNumber } ) =>
207- roundNumber === currentRound . roundNumber ! + 1 ,
207+ ( { roundNumber } ) => roundNumber === currentRound . roundNumber ! + 1 ,
208208 ) ! ,
209209 ) ;
210210 const roundWithoutPersoncode : UnfinishedRound = {
@@ -350,7 +350,8 @@ const listenEvents = ({ _socket, ...events }: GameServices) => ({
350350 disconnect : async ( { _socket } : GameServices , reason : string ) => {
351351 if ( reason !== "client namespace disconnect" ) {
352352 if (
353- _socket && _socket . data . currentGame . gamePlayers . findIndex (
353+ _socket &&
354+ _socket . data . currentGame . gamePlayers . findIndex (
354355 ( { player } ) => player . id === _socket . data . user . id ,
355356 ) > 0
356357 ) {
@@ -363,7 +364,9 @@ const listenEvents = ({ _socket, ...events }: GameServices) => ({
363364 } ,
364365} ) ;
365366
366- const getPublicGame = async ( game : Awaited < ReturnType < typeof getGameWithRoundsDatasetPlayers > > ) => {
367+ const getPublicGame = async (
368+ game : Awaited < ReturnType < typeof getGameWithRoundsDatasetPlayers > > ,
369+ ) => {
367370 if ( ! game ) {
368371 return null ;
369372 }
@@ -408,29 +411,26 @@ export const createGameSocket = async (gameId: number) => {
408411
409412 console . log ( `Creating game socket for game ${ gameId } ` ) ;
410413
411- const { server, client } = useSocketEvents < typeof listenEvents , ClientListenEvents > (
412- namespaces . GAME . replace ( "{id}" , gameId . toString ( ) ) ,
413- {
414- listenEvents,
415- middlewares : [
416- (
417- { _socket, sendGame : sendGameEvent } ,
418- next : ( error ?: Error ) => void ,
419- ) => {
420- getPlayer ( _socket . handshake . auth ) . then ( async ( user ) => {
421- if ( user ) {
422- _socket . data . user = user ;
423- _socket . data . currentGame = currentGame ;
424- sendGameEvent ( await getPublicGame ( currentGame ) ) ;
425- next ( )
426- } else {
427- next ( new Error ( "User not found" ) ) ;
428- }
429- } ) ;
430- } ,
431- ] ,
432- } ,
433- )
414+ const { server, client } = useSocketEvents <
415+ typeof listenEvents ,
416+ ClientListenEvents
417+ > ( namespaces . GAME . replace ( "{id}" , gameId . toString ( ) ) , {
418+ listenEvents,
419+ middlewares : [
420+ ( { _socket, sendGame : sendGameEvent } , next : ( error ?: Error ) => void ) => {
421+ getPlayer ( _socket . handshake . auth ) . then ( async ( user ) => {
422+ if ( user ) {
423+ _socket . data . user = user ;
424+ _socket . data . currentGame = currentGame ;
425+ sendGameEvent ( await getPublicGame ( currentGame ) ) ;
426+ next ( ) ;
427+ } else {
428+ next ( new Error ( "User not found" ) ) ;
429+ }
430+ } ) ;
431+ } ,
432+ ] ,
433+ } ) ;
434434 server ( io ) ;
435435 return { client } ;
436436} ;
0 commit comments