Compare commits
2 commits
d2e34e84f8
...
f098c1f6bf
Author | SHA1 | Date | |
---|---|---|---|
f098c1f6bf | |||
337e5b0ed3 |
5 changed files with 9 additions and 9 deletions
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
// BroadcastMessage sends a message to all connected WebSocket clients.
|
||||
func BroadcastMessage(clients map[*websocket.Conn]*models.Client, message models.BroadcastMessage) {
|
||||
func BroadcastMessage(clients map[*websocket.Conn]*models.Client, message models.ServerMessage) {
|
||||
// Marshal the message into JSON format
|
||||
jsonMessage, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
|
|
|
@ -23,8 +23,8 @@ var pomodoroResumeChannel = make(chan bool, 1)
|
|||
|
||||
var mu sync.Mutex // to synchronize access to shared state
|
||||
|
||||
// RunPomodoroTimer iterates the Pomodoro work/break sessions.
|
||||
func RunPomodoroTimer(clients map[*websocket.Conn]*models.Client) {
|
||||
// RunPomodoro iterates the Pomodoro work/break sessions.
|
||||
func RunPomodoro(clients map[*websocket.Conn]*models.Client) {
|
||||
mu.Lock()
|
||||
pomodoroOngoing = true
|
||||
pomodoroPaused = false
|
||||
|
@ -58,7 +58,7 @@ func ResetPomodoro(clients map[*websocket.Conn]*models.Client) {
|
|||
mu.Unlock()
|
||||
|
||||
// Broadcast the reset message to all clients
|
||||
broadcast.BroadcastMessage(clients, models.BroadcastMessage{
|
||||
broadcast.BroadcastMessage(clients, models.ServerMessage{
|
||||
Mode: "none",
|
||||
Session: 0,
|
||||
MaxSession: 0,
|
||||
|
|
|
@ -20,7 +20,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int
|
|||
default:
|
||||
// Broadcast the current state to all clients
|
||||
if !IsPomodoroPaused() {
|
||||
broadcast.BroadcastMessage(clients, models.BroadcastMessage{
|
||||
broadcast.BroadcastMessage(clients, models.ServerMessage{
|
||||
Mode: mode,
|
||||
Session: session,
|
||||
MaxSession: PomodoroConfig.Sessions,
|
||||
|
@ -33,7 +33,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int
|
|||
}
|
||||
|
||||
// Final broadcast when time reaches zero
|
||||
broadcast.BroadcastMessage(clients, models.BroadcastMessage{
|
||||
broadcast.BroadcastMessage(clients, models.ServerMessage{
|
||||
Mode: mode,
|
||||
Session: session,
|
||||
MaxSession: PomodoroConfig.Sessions,
|
||||
|
|
|
@ -30,7 +30,7 @@ func handleClientCommands(ws *websocket.Conn) {
|
|||
switch command.Command {
|
||||
case "start":
|
||||
if !pomodoro.IsPomodoroOngoing() {
|
||||
go pomodoro.RunPomodoroTimer(Clients) // Start the timer with the list of clients
|
||||
go pomodoro.RunPomodoro(Clients) // Start the timer with the list of clients
|
||||
}
|
||||
case "stop":
|
||||
if pomodoro.IsPomodoroOngoing() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package models
|
||||
|
||||
// BroadcastMessage represents the data sent to the client via WebSocket.
|
||||
type BroadcastMessage struct {
|
||||
// ServerMessage represents the data sent to the client via WebSocket.
|
||||
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
|
Loading…
Reference in a new issue