refactor: rewire sessions routes to use ecast shard client
Made-with: Cursor
This commit is contained in:
@@ -4,8 +4,7 @@ const { authenticateToken } = require('../middleware/auth');
|
||||
const db = require('../database');
|
||||
const { triggerWebhook } = require('../utils/webhooks');
|
||||
const { getWebSocketManager } = require('../utils/websocket-manager');
|
||||
const { stopPlayerCountCheck } = require('../utils/player-count-checker');
|
||||
const { startRoomMonitor, stopRoomMonitor } = require('../utils/room-monitor');
|
||||
const { startMonitor, stopMonitor } = require('../utils/ecast-shard-client');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -394,7 +393,7 @@ router.post('/:id/games', authenticateToken, (req, res) => {
|
||||
// Automatically start room monitoring if room code was provided
|
||||
if (room_code) {
|
||||
try {
|
||||
startRoomMonitor(req.params.id, result.lastInsertRowid, room_code, game.max_players);
|
||||
startMonitor(req.params.id, result.lastInsertRowid, room_code, game.max_players);
|
||||
} catch (error) {
|
||||
console.error('Error starting room monitor:', error);
|
||||
}
|
||||
@@ -617,8 +616,7 @@ router.patch('/:sessionId/games/:gameId/status', authenticateToken, (req, res) =
|
||||
// Stop room monitor and player count check if game is no longer playing
|
||||
if (status !== 'playing') {
|
||||
try {
|
||||
stopRoomMonitor(sessionId, gameId);
|
||||
stopPlayerCountCheck(sessionId, gameId);
|
||||
stopMonitor(sessionId, gameId);
|
||||
} catch (error) {
|
||||
console.error('Error stopping room monitor/player count check:', error);
|
||||
}
|
||||
@@ -637,8 +635,7 @@ router.delete('/:sessionId/games/:gameId', authenticateToken, (req, res) => {
|
||||
|
||||
// Stop room monitor and player count check before deleting
|
||||
try {
|
||||
stopRoomMonitor(sessionId, gameId);
|
||||
stopPlayerCountCheck(sessionId, gameId);
|
||||
stopMonitor(sessionId, gameId);
|
||||
} catch (error) {
|
||||
console.error('Error stopping room monitor/player count check:', error);
|
||||
}
|
||||
@@ -863,7 +860,7 @@ router.post('/:sessionId/games/:gameId/start-player-check', authenticateToken, (
|
||||
}
|
||||
|
||||
// Start room monitoring (will hand off to player count check when game starts)
|
||||
startRoomMonitor(sessionId, gameId, game.room_code, game.max_players);
|
||||
startMonitor(sessionId, gameId, game.room_code, game.max_players);
|
||||
|
||||
res.json({
|
||||
message: 'Room monitor started',
|
||||
@@ -880,8 +877,7 @@ router.post('/:sessionId/games/:gameId/stop-player-check', authenticateToken, (r
|
||||
const { sessionId, gameId } = req.params;
|
||||
|
||||
// Stop both room monitor and player count check
|
||||
stopRoomMonitor(sessionId, gameId);
|
||||
stopPlayerCountCheck(sessionId, gameId);
|
||||
stopMonitor(sessionId, gameId);
|
||||
|
||||
res.json({
|
||||
message: 'Room monitor and player count check stopped',
|
||||
|
||||
Reference in New Issue
Block a user