added Context

This commit is contained in:
Gavin McDonald
2025-06-25 17:04:18 -04:00
parent 59aa904c5a
commit e7ebb0223b
6 changed files with 75 additions and 16 deletions

View File

@@ -4,7 +4,7 @@ import { Server as SocketIOServer, type Socket } from 'socket.io';
import GameStore from '@/lib/GameStore';
import omit from '@/tools/omit';
import type { ClientUpdate, GameUpdate } from '@/types';
import type { ClientUpdate, GameUpdate, Tilt } from '@/types';
const dev = process.env.NODE_ENV !== 'production';
const hostname = '0.0.0.0';
@@ -119,6 +119,16 @@ app.prepare().then(() => {
}
});
socket.on('tilt', ({ gameID, tilt }: { gameID: string; tilt: Tilt }) => {
try {
const gameState = gameStore.getGame(gameID);
broadcast('tilt', gameState);
} catch (e) {
const error = e instanceof Error ? e.message : e;
console.error(Date.now(), 'Error[tilt]', error);
}
});
socket.on('disconnect', () => {
try {
const game = gameStore.playerExit(socket.id);