break: update ServerMessage model

- rename MaxSession to TotalSession (and JSON struct tags)

🤖
This commit is contained in:
Sebastian Mark 2024-10-20 23:20:23 +02:00
parent 52634ed226
commit 5c08a9b184
5 changed files with 23 additions and 23 deletions

View file

@ -39,14 +39,14 @@ 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).
- max_session: The total number of sessions for the current Pomodoro cycle (e.g., 4 if the cycle consists of 4 work/break sessions).
- 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).
| Message Type | Sent by Server | Example |
| --------------------- | ------------------------------------------------ | --------------------------------------------------- |
| Welcome Message | Upon initial client connection | `{"mode": "none", "session": 0, "max_session": 0, "time_left": 0}` |
| Session Update | Periodically during a session | `{"mode": "Work", "session": 1, "max_session": 4, "time_left": 900}` |
| Session End/Reset | After session completes or is reset | `{"mode": "none", "session": 0, "max_session": 0, "time_left": 0}` |
| 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}` |
## Testing

View file

@ -41,11 +41,11 @@
var data = JSON.parse(event.data);
var mode = data.mode;
var session = data.session;
var maxSession = data.max_session;
var totalSession = data.total_sessions;
var timeLeft = data.time_left;
document.getElementById("timer").innerText =
mode + " Session " + session + "/" + maxSession + ": " + formatTime(timeLeft);
mode + " Session " + session + "/" + totalSession + ": " + formatTime(timeLeft);
};
ws.onclose = function () {

View file

@ -54,7 +54,7 @@ func ResetPomodoro(clients map[*websocket.Conn]*models.Client) {
broadcast.BroadcastMessage(clients, models.ServerMessage{
Mode: "none",
Session: 0,
MaxSession: 0,
TotalSession: 0,
TimeLeft: 0,
})

View file

@ -8,7 +8,7 @@ import (
)
// startTimer runs the countdown and broadcasts every second.
func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int, mode string, session int, sessions int) bool {
func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int, mode string, session int, totalSessions int) bool {
for remainingSeconds > 0 {
select {
case <-pomodoroResetChannel:
@ -23,7 +23,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int
broadcast.BroadcastMessage(clients, models.ServerMessage{
Mode: mode,
Session: session,
MaxSession: sessions,
TotalSession: totalSessions,
TimeLeft: remainingSeconds,
})
time.Sleep(time.Second)
@ -36,7 +36,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int
broadcast.BroadcastMessage(clients, models.ServerMessage{
Mode: mode,
Session: session,
MaxSession: sessions,
TotalSession: totalSessions,
TimeLeft: 0,
})

View file

@ -4,6 +4,6 @@ package models
type ServerMessage struct {
Mode string `json:"mode"` // "Work", "ShortBreak", or "LongBreak"
Session int `json:"session"` // Current session number
MaxSession int `json:"max_session"` // Total number of sessions
TotalSession int `json:"total_sessions"` // Total number of sessions
TimeLeft int `json:"time_left"` // Remaining time in seconds
}