rommapp_romm/backend/handler/socket_handler.py
Michael Manganiello d837070ad0
fix: SocketIO JSON dumps with sane defaults
Similar to how `engineio` provides a JSON-compatible module, this change
adds a custom JSON encoder with support for additional types.

Changing SocketIO's JSON module fixes the encoding issue when the
scanning process tried to send a datetime, failing and the frontend not
displaying the scanned game (commonly, when it had sibling games)
2025-01-12 00:41:15 -03:00

23 lines
598 B
Python

import socketio # type: ignore
from config import REDIS_URL
from utils import json as json_module
class SocketHandler:
def __init__(self) -> None:
self.socket_server = socketio.AsyncServer(
cors_allowed_origins="*",
async_mode="asgi",
json=json_module,
logger=False,
engineio_logger=False,
client_manager=socketio.AsyncRedisManager(str(REDIS_URL)),
)
self.socket_app = socketio.ASGIApp(
self.socket_server, socketio_path="/ws/socket.io"
)
socket_handler = SocketHandler()