Aniworld/src/server/web/controllers/api/v1/websocket_handlers.py
2025-10-04 20:24:00 +02:00

54 lines
1.6 KiB
Python

"""
WebSocket event handlers for real-time updates.
"""
from flask_socketio import emit
# Placeholder process lock constants and functions
RESCAN_LOCK = "rescan"
DOWNLOAD_LOCK = "download"
# Simple in-memory process lock system
_active_locks = {}
def is_process_running(lock_name):
"""Check if a process is currently running (locked)."""
return lock_name in _active_locks
def register_socketio_handlers(socketio):
"""Register WebSocket event handlers."""
@socketio.on('connect')
def handle_connect():
"""Handle client connection."""
emit('status', {
'message': 'Connected to server',
'processes': {
'rescan_running': is_process_running(RESCAN_LOCK),
'download_running': is_process_running(DOWNLOAD_LOCK)
}
})
@socketio.on('disconnect')
def handle_disconnect():
"""Handle client disconnection."""
print('Client disconnected')
@socketio.on('get_status')
def handle_get_status():
"""Handle status request."""
# Import series_app from the main module if available
try:
from main import SeriesApp
# This would need to be properly initialized
series_count = 0 # Placeholder
except:
series_count = 0
emit('status_update', {
'processes': {
'rescan_running': is_process_running(RESCAN_LOCK),
'download_running': is_process_running(DOWNLOAD_LOCK)
},
'series_count': series_count
})