- ConnectionManager: Add redis_factory constructor parameter - GameService: Add engine_factory constructor parameter - AuthHandler: New class replacing standalone functions with token_verifier and conn_manager injection - Update all tests to use constructor DI instead of patch() - Update CLAUDE.md with factory injection patterns - Update services README with new patterns - Add socketio README documenting AuthHandler and events Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
"""Socket.IO module for real-time game communication.
|
|
|
|
This module provides WebSocket-based real-time communication for:
|
|
- Active game sessions (actions, state updates, turn notifications)
|
|
- Connection management with session recovery
|
|
- Turn timeout handling
|
|
- JWT-based authentication
|
|
|
|
Architecture:
|
|
- Uses python-socketio with ASGI mode for FastAPI integration
|
|
- /game namespace handles all active game communication
|
|
- /lobby namespace (Phase 6) will handle matchmaking
|
|
- JWT authentication on connect (WS-004)
|
|
|
|
Usage:
|
|
The Socket.IO server is mounted alongside FastAPI in app/main.py.
|
|
Clients connect to ws://host/socket.io/ and join the /game namespace.
|
|
|
|
Client connection example:
|
|
socket = io("ws://host", {
|
|
auth: { token: "JWT_ACCESS_TOKEN" }
|
|
});
|
|
"""
|
|
|
|
from app.socketio.auth import (
|
|
AuthHandler,
|
|
AuthResult,
|
|
auth_handler,
|
|
extract_token,
|
|
get_session_user_id,
|
|
require_auth,
|
|
)
|
|
from app.socketio.server import create_socketio_app, sio
|
|
|
|
__all__ = [
|
|
# Server
|
|
"create_socketio_app",
|
|
"sio",
|
|
# Auth
|
|
"AuthHandler",
|
|
"AuthResult",
|
|
"auth_handler",
|
|
"extract_token",
|
|
"get_session_user_id",
|
|
"require_auth",
|
|
]
|