fix(gameplay): restore scoreboard phase error contract
Some checks failed
CI / test-and-quality (push) Failing after 2m30s
CI / test-and-quality (pull_request) Failing after 2m32s

This commit is contained in:
2026-03-15 08:52:35 +00:00
parent 97b366d1e9
commit 8fa39adc2b
4 changed files with 193 additions and 24 deletions

20
realtime/broadcast.py Normal file
View File

@@ -0,0 +1,20 @@
from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
async def broadcast_phase_event(session_code: str, event_type: str, payload: dict) -> None:
"""Send a phase event to all WebSocket clients connected to a game session."""
channel_layer = get_channel_layer()
group_name = f"game_{session_code.upper()}"
await channel_layer.group_send(
group_name,
{
"type": "phase_event",
"payload": {"type": event_type, **payload},
},
)
def sync_broadcast_phase_event(session_code: str, event_type: str, payload: dict) -> None:
"""Sync wrapper for calling broadcast_phase_event from synchronous Django views."""
async_to_sync(broadcast_phase_event)(session_code, event_type, payload)