This API provides endpoints for managing a real-time draw system where users can join a room, participate in a draw, and restart the process. The system uses WebSocket broadcasting for real-time updates.
- Endpoint:
POST /api/enter
- Description: Allows a user to enter the draw room
- Request Body:
{ "nickname": "string" }
- Responses:
- 200 OK: User successfully joined
{ "message": "User joined the room!" }
- 400 Bad Request: If nickname is already taken or room is full
or
{ "message": "This nickname is already in the room." }
{ "message": "The room is full." }
- 200 OK: User successfully joined
- Endpoint:
POST /api/start
- Description: Initiates the draw process when the room is full
- Responses:
- 200 OK: Draw completed successfully
{ "message": "We have a winner! [winner_name]" }
- 400 Bad Request: If room is not full
{ "message": "Room is not full yet." }
- 200 OK: Draw completed successfully
- Endpoint:
POST /api/restart
- Description: Clears the room and allows for a new draw session
- Responses:
- 200 OK: Room cleared successfully
{ "message": "Room cleaned." }
- 400 Bad Request: If room is already empty
{ "message": "Room is empty." }
- 200 OK: Room cleared successfully
The system broadcasts the following events on the 'draw' channel:
-
UserJoined Event
- Triggered when a new user joins the room
- Payload includes the new user's nickname and updated participants list
-
DrawStarted Event
- Triggered when the draw is initiated
- Payload includes the winner's name
- The system has a maximum participant limit (configurable via
MAX_PARTICIPANTS_COUNT
environment variable) - There is a special admin user with the nickname "admin123"
- The system uses Laravel's cache system to maintain the state of participants