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 db = require('../database');
|
||||||
const { triggerWebhook } = require('../utils/webhooks');
|
const { triggerWebhook } = require('../utils/webhooks');
|
||||||
const { getWebSocketManager } = require('../utils/websocket-manager');
|
const { getWebSocketManager } = require('../utils/websocket-manager');
|
||||||
const { stopPlayerCountCheck } = require('../utils/player-count-checker');
|
const { startMonitor, stopMonitor } = require('../utils/ecast-shard-client');
|
||||||
const { startRoomMonitor, stopRoomMonitor } = require('../utils/room-monitor');
|
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@@ -394,7 +393,7 @@ router.post('/:id/games', authenticateToken, (req, res) => {
|
|||||||
// Automatically start room monitoring if room code was provided
|
// Automatically start room monitoring if room code was provided
|
||||||
if (room_code) {
|
if (room_code) {
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
console.error('Error starting room monitor:', 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
|
// Stop room monitor and player count check if game is no longer playing
|
||||||
if (status !== 'playing') {
|
if (status !== 'playing') {
|
||||||
try {
|
try {
|
||||||
stopRoomMonitor(sessionId, gameId);
|
stopMonitor(sessionId, gameId);
|
||||||
stopPlayerCountCheck(sessionId, gameId);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error stopping room monitor/player count check:', 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
|
// Stop room monitor and player count check before deleting
|
||||||
try {
|
try {
|
||||||
stopRoomMonitor(sessionId, gameId);
|
stopMonitor(sessionId, gameId);
|
||||||
stopPlayerCountCheck(sessionId, gameId);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error stopping room monitor/player count check:', 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)
|
// 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({
|
res.json({
|
||||||
message: 'Room monitor started',
|
message: 'Room monitor started',
|
||||||
@@ -880,8 +877,7 @@ router.post('/:sessionId/games/:gameId/stop-player-check', authenticateToken, (r
|
|||||||
const { sessionId, gameId } = req.params;
|
const { sessionId, gameId } = req.params;
|
||||||
|
|
||||||
// Stop both room monitor and player count check
|
// Stop both room monitor and player count check
|
||||||
stopRoomMonitor(sessionId, gameId);
|
stopMonitor(sessionId, gameId);
|
||||||
stopPlayerCountCheck(sessionId, gameId);
|
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
message: 'Room monitor and player count check stopped',
|
message: 'Room monitor and player count check stopped',
|
||||||
|
|||||||
Reference in New Issue
Block a user