- Replaced scattered message strings with `DraftMessage` `StrEnum` and numeric `DraftPhase` `IntEnum` for clear, centralized definitions. - Added Python→JS constants sync via `scripts/generate_js_constants.py` to ensure backend/frontend parity. - Refactored WebSocket consumers to use `broadcast.*` and `direct.message` handlers with `_dispatch_broadcast` for consistent event delivery. - Enhanced `DraftStateManager` to store `draft_index` and explicitly manage `connected_participants`. - Added colored logging config in settings for improved debugging. - Frontend: split UI into `ParticipantList` and `DraftMoviePool`, extracted message handlers (`handleDraftStatusMessages`, `handleUserIdentifyMessages`), and updated components to use new message/phase enums.
68 lines
2.7 KiB
Python
68 lines
2.7 KiB
Python
from enum import IntEnum, StrEnum
|
|
|
|
class DraftMessage(StrEnum):
|
|
# Participant
|
|
PARTICIPANT_JOIN_REQUEST = "participant.join.request" # client -> server
|
|
PARTICIPANT_JOIN_CONFIRM = "participant.join.confirm" # server -> client
|
|
PARTICIPANT_JOIN_REJECT = "participant.join.reject" # server -> client
|
|
PARTICIPANT_LEAVE_INFORM = "participant.leave.inform" # server -> client (broadcast)
|
|
|
|
# User presence
|
|
USER_JOIN_INFORM = "user.join.inform" # server -> client
|
|
USER_LEAVE_INFORM = "user.leave.inform"
|
|
USER_IDENTIFICATION_INFORM = "user.identification.inform" # server -> client (tells socket "you are X", e.g. after connect) # server -> client
|
|
|
|
# Phase control
|
|
PHASE_CHANGE_INFORM = "phase.change.inform" # server -> client (target phase payload)
|
|
PHASE_CHANGE_REQUEST = "phase.change.request" # server -> client (target phase payload)
|
|
PHASE_CHANGE_CONFIRM = "phase.change.confirm" # server -> client (target phase payload)
|
|
|
|
# Status / sync
|
|
STATUS_SYNC_REQUEST = "status.sync.request" # client -> server
|
|
STATUS_SYNC_INFORM = "status.sync.inform" # server -> client (full/partial state)
|
|
|
|
DRAFT_INDEX_ADVANCE_REQUEST = "draft.index.advance.request"
|
|
DRAFT_INDEX_ADVANCE_CONFIRM = "draft.index.advance.confirm"
|
|
|
|
# Order determination
|
|
ORDER_DETERMINE_REQUEST = "order.determine.request" # client -> server (admin)
|
|
ORDER_DETERMINE_CONFIRM = "order.determine.confirm" # server -> client
|
|
|
|
# Bidding (examples, adjust to your flow)
|
|
BID_START_INFORM = "bid.start.inform" # server -> client (movie, ends_at)
|
|
BID_PLACE_REQUEST = "bid.place.request" # client -> server (amount)
|
|
BID_UPDATE_INFORM = "bid.update.inform" # server -> client (high bid)
|
|
BID_END_INFORM = "bid.end.inform" # server -> client (winner)
|
|
|
|
# Nomination (examples)
|
|
NOMINATION_SUBMIT_REQUEST = "nomination.submit.request" # client -> server (movie_id)
|
|
NOMINATION_CONFIRM = "nomination.submit.confirm" # server -> client
|
|
|
|
|
|
class DraftPhase(IntEnum):
|
|
WAITING = 10
|
|
DETERMINE_ORDER = 20
|
|
NOMINATING = 30
|
|
BIDDING = 40
|
|
AWARDING = 50
|
|
FINALIZING = 60
|
|
|
|
def __str__(self):
|
|
return self.name.lower()
|
|
|
|
class DraftGroupChannelNames:
|
|
def __init__(self, id):
|
|
self.prefix = f"draft.{id}"
|
|
|
|
@property
|
|
def session(self):
|
|
return f"{self.prefix}.session"
|
|
|
|
@property
|
|
def admin(self):
|
|
return f"{self.prefix}.admin"
|
|
|
|
@property
|
|
def participant(self):
|
|
return f"{self.prefix}.participant"
|
|
|