import { GameWebSocketService } from './src/Application/Services/GameWebSocketService'; import { GameRepository } from './src/Infrastructure/Repository/GameRepository'; import { UserRepository } from './src/Infrastructure/Repository/UserRepository'; import { RedisService } from './src/Application/Services/RedisService'; import { Server as SocketIOServer } from 'socket.io'; import { createServer } from 'http'; async function testGameWebSocketService() { console.log('Testing Game WebSocket Service initialization...'); try { // Create a test HTTP server const httpServer = createServer(); // Create Socket.IO server const io = new SocketIOServer(httpServer, { cors: { origin: ['http://localhost:3000'], credentials: true } }); // Initialize dependencies const gameRepository = new GameRepository(); const userRepository = new UserRepository(); const redisService = RedisService.getInstance(); // Create GameWebSocketService const gameWebSocketService = new GameWebSocketService( io, gameRepository, userRepository, redisService ); console.log('โœ… Game WebSocket Service initialized successfully!'); console.log('๐Ÿ“ก Namespace: /game'); console.log('๐ŸŽฎ Dynamic rooms: game_{gameCode}'); console.log('๐Ÿ”ง Available events:'); console.log(' - game:join'); console.log(' - game:leave'); console.log(' - game:action'); console.log(' - game:chat'); console.log(' - game:ready'); console.log(' - game:state-update'); console.log(' - game:player-joined'); console.log(' - game:player-left'); // Test public methods console.log('\n๐Ÿงช Testing public methods...'); // Test broadcast methods (these won't do anything without connected clients) await gameWebSocketService.broadcastGameStateUpdate('TEST123', { message: 'test' }); await gameWebSocketService.broadcastGameEvent('TEST123', 'test:event', { data: 'test' }); console.log('โœ… Public methods work correctly!'); console.log('\n๐ŸŽ‰ Game WebSocket Service test completed successfully!'); // Clean up httpServer.close(); } catch (error) { console.error('โŒ Test failed:', error); process.exit(1); } } testGameWebSocketService();