feat: implement permanent broadcast message functionality

- add SendPermanentBroadCastMessage to continuously send updates
- refactor BroadcastMessage to use a shared Message struct
- update pomodoro logic to modify broadcast.Message directly
- adjust client command handling to use broadcast.Clients map
- enhance ServerMessage struct with "Ongoing" and "Paused" fields

🤖
This commit is contained in:
Sebastian Mark 2024-10-21 08:16:26 +02:00
parent eba4065c6f
commit 9615d4d449
8 changed files with 75 additions and 65 deletions

View file

@ -20,7 +20,6 @@ This section describes the WebSocket commands that clients can send to the Pomod
Both client commands (sent to the server) and server messages (sent to the client) use the JSON format. The structure of these messages are described in the sections below.
### Client Commands
Clients communicate with the server by sending JSON-encoded commands. Each command must include a `command` field specifying the action to perform. Here are the available commands:
@ -51,19 +50,23 @@ Example:
### Server Messages
The server sends JSON-encoded messages to all connected clients to update them on the current state of the Pomodoro session.
The server periodically (every second) sends JSON-encoded messages to all connected clients to update them on the current state of the Pomodoro session.
These messages contain the following fields:
- mode: Indicates the current phase of the Pomodoro session ("Work", "ShortBreak", "LongBreak", or "none" if no session is running).
- session: The current session number (e.g., 1 for the first work session).
- total_sessions: The total number of sessions for the current Pomodoro cycle (e.g., 4 if the cycle consists of 4 work/break sessions).
- time_left: The remaining time for the current mode, in seconds (e.g., 900 for 15 minutes).
- ongoing: Wether a pomodoro is currently ongoing
- paused: Wether the timer is paused
| Message Type | Sent by Server | Example |
| --------------------- | ------------------------------------------------ | --------------------------------------------------- |
| Welcome Message | Upon initial client connection | `{"mode": "none", "session": 0, "total_sessions": 0, "time_left": 0}` |
| Session Update | Periodically during a session | `{"mode": "Work", "session": 1, "total_sessions": 4, "time_left": 900}` |
| Session End/Reset | After session completes or is reset | `{"mode": "none", "session": 0, "total_sessions": 0, "time_left": 0}` |
| Message Type | Example |
| --------------------- | --------------------------------------------------- |
| Welcome Message | `{"mode": "none", "session":0, "total_sessions":0, "time_left":0, "ongoing": false, "paused": false}` |
| Session Running | `{"mode": "Work", "session": 1, "total_sessions": 4, "time_left": 900, "ongoing": true, "paused": false}` |
| Session Running | `{"mode": "ShortBreak", "session": 2, "total_sessions": 4, "time_left": 50, "ongoing": true, "paused": false}` |
| Session Paused | `{"mode": "Work", "session": 2, "total_sessions": 4, "time_left": 456, "ongoing": true, "paused": true}` |
| Session End/Reset | `{"mode": "none", "session": 0, "total_sessions": 0, "time_left": 0, "ongoing": false, "paused": false}` |
## Testing