feat: add periodic game.status broadcast and live status REST endpoint
Add 20-second game.status WebSocket heartbeat from active shard monitors containing full game state, and GET /status-live REST endpoint for on-demand polling. Fix missing token destructuring in SessionInfo causing crash. Relax frontend polling from 3s to 60s since WebSocket events now cover real-time updates. Bump version to 0.6.0. Made-with: Cursor
This commit is contained in:
@@ -4,7 +4,7 @@ const { authenticateToken } = require('../middleware/auth');
|
||||
const db = require('../database');
|
||||
const { triggerWebhook } = require('../utils/webhooks');
|
||||
const { getWebSocketManager } = require('../utils/websocket-manager');
|
||||
const { startMonitor, stopMonitor } = require('../utils/ecast-shard-client');
|
||||
const { startMonitor, stopMonitor, getMonitorSnapshot } = require('../utils/ecast-shard-client');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -838,6 +838,55 @@ router.get('/:id/export', authenticateToken, (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Get live game status from shard monitor or DB fallback
|
||||
router.get('/:sessionId/games/:gameId/status-live', (req, res) => {
|
||||
try {
|
||||
const { sessionId, gameId } = req.params;
|
||||
|
||||
const snapshot = getMonitorSnapshot(sessionId, gameId);
|
||||
if (snapshot) {
|
||||
return res.json(snapshot);
|
||||
}
|
||||
|
||||
const game = db.prepare(`
|
||||
SELECT
|
||||
sg.room_code,
|
||||
sg.player_count,
|
||||
sg.player_count_check_status,
|
||||
g.title,
|
||||
g.pack_name,
|
||||
g.max_players
|
||||
FROM session_games sg
|
||||
JOIN games g ON sg.game_id = g.id
|
||||
WHERE sg.session_id = ? AND sg.id = ?
|
||||
`).get(sessionId, gameId);
|
||||
|
||||
if (!game) {
|
||||
return res.status(404).json({ error: 'Session game not found' });
|
||||
}
|
||||
|
||||
res.json({
|
||||
sessionId: parseInt(sessionId, 10),
|
||||
gameId: parseInt(gameId, 10),
|
||||
roomCode: game.room_code,
|
||||
appTag: null,
|
||||
maxPlayers: game.max_players,
|
||||
playerCount: game.player_count,
|
||||
players: [],
|
||||
lobbyState: null,
|
||||
gameState: null,
|
||||
gameStarted: false,
|
||||
gameFinished: game.player_count_check_status === 'completed',
|
||||
monitoring: false,
|
||||
title: game.title,
|
||||
packName: game.pack_name,
|
||||
status: game.player_count_check_status,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Start player count check for a session game (admin only)
|
||||
router.post('/:sessionId/games/:gameId/start-player-check', authenticateToken, (req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user