update logging
This commit is contained in:
@@ -43,12 +43,10 @@ export default function GamePage() {
|
|||||||
socket.emit('join', gameID);
|
socket.emit('join', gameID);
|
||||||
|
|
||||||
socket.on('init', (data: GameUpdate) => {
|
socket.on('init', (data: GameUpdate) => {
|
||||||
console.log('init', data);
|
|
||||||
setGameData(data);
|
setGameData(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('game-update', (data: GameUpdate) => {
|
socket.on('game-update', (data: GameUpdate) => {
|
||||||
console.log('>>>', data);
|
|
||||||
setGameData(data);
|
setGameData(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
22
server.ts
22
server.ts
@@ -4,7 +4,7 @@ import { Server as SocketIOServer, type Socket } from 'socket.io';
|
|||||||
|
|
||||||
import GameStore from '@/lib/GameStore';
|
import GameStore from '@/lib/GameStore';
|
||||||
import omit from '@/tools/omit';
|
import omit from '@/tools/omit';
|
||||||
import type { ClientUpdate, GameUpdate, Settings } from '@/types';
|
import type { ClientUpdate, GameUpdate } from '@/types';
|
||||||
|
|
||||||
const dev = process.env.NODE_ENV !== 'production';
|
const dev = process.env.NODE_ENV !== 'production';
|
||||||
const hostname = '0.0.0.0';
|
const hostname = '0.0.0.0';
|
||||||
@@ -26,12 +26,12 @@ app.prepare().then(() => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
io.on('connection', (socket: Socket) => {
|
io.on('connection', (socket: Socket) => {
|
||||||
console.log(`Client connected: ${socket.id}`);
|
console.log(Date.now(), `Client connected: ${socket.id}`);
|
||||||
|
|
||||||
socket.on('start', () => {
|
socket.on('start', () => {
|
||||||
const gameUpdate = gameStore.createGame();
|
const gameUpdate = gameStore.createGame();
|
||||||
|
|
||||||
console.log(`Socket ${socket.id} started game ${gameUpdate.dmID}`);
|
console.log(Date.now(), `Socket ${socket.id} started game ${gameUpdate.dmID}`);
|
||||||
|
|
||||||
socket.emit('new-game', gameUpdate);
|
socket.emit('new-game', gameUpdate);
|
||||||
});
|
});
|
||||||
@@ -40,7 +40,7 @@ app.prepare().then(() => {
|
|||||||
try {
|
try {
|
||||||
const gameUpdate = gameStore.joinGame(gameID, socket.id);
|
const gameUpdate = gameStore.joinGame(gameID, socket.id);
|
||||||
|
|
||||||
console.log(`Socket ${socket.id} joined game ${gameID}`);
|
console.log(Date.now(), `Socket ${socket.id} joined game ${gameID}`);
|
||||||
|
|
||||||
socket.join(gameID);
|
socket.join(gameID);
|
||||||
|
|
||||||
@@ -52,14 +52,14 @@ app.prepare().then(() => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = e instanceof Error ? e.message : e;
|
const error = e instanceof Error ? e.message : e;
|
||||||
|
|
||||||
console.error('Error', error);
|
console.error(Date.now(), 'Error', error);
|
||||||
socket.emit('join-error', error);
|
socket.emit('join-error', error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('flip-card', ({ gameID, cardIndex }: ClientUpdate) => {
|
socket.on('flip-card', ({ gameID, cardIndex }: ClientUpdate) => {
|
||||||
try {
|
try {
|
||||||
console.log('Card flipped:', { gameID, cardIndex });
|
console.log(Date.now(), 'Card flipped:', { gameID, cardIndex });
|
||||||
|
|
||||||
const gameUpdate = gameStore.flipCard(gameID, cardIndex);
|
const gameUpdate = gameStore.flipCard(gameID, cardIndex);
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ app.prepare().then(() => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = e instanceof Error ? e.message : e;
|
const error = e instanceof Error ? e.message : e;
|
||||||
|
|
||||||
console.error('Error', error);
|
console.error(Date.now(), 'Error', error);
|
||||||
socket.emit('flip-error', error);
|
socket.emit('flip-error', error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -78,21 +78,21 @@ app.prepare().then(() => {
|
|||||||
broadcast('game-update', gameUpdate);
|
broadcast('game-update', gameUpdate);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = e instanceof Error ? e.message : e;
|
const error = e instanceof Error ? e.message : e;
|
||||||
console.error('Error', error);
|
console.error(Date.now(), 'Error', error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
console.log(`Client disconnected: ${socket.id}`);
|
console.log(Date.now(), `Client disconnected: ${socket.id}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
httpServer
|
httpServer
|
||||||
.once('error', (err) => {
|
.once('error', (err) => {
|
||||||
console.error('Server error:', err);
|
console.error(Date.now(), 'Server error:', err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
})
|
})
|
||||||
.listen(port, () => {
|
.listen(port, () => {
|
||||||
console.log(`> Ready on http://${hostname}:${port}`);
|
console.log(Date.now(), `> Ready on http://${hostname}:${port}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user