68 lines
2.5 KiB
TypeScript
68 lines
2.5 KiB
TypeScript
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(); |