refactor: move broadcast package to websocket

- update import paths to reflect the new package name
- change function call to use the new websocket package
- adjust client iteration to use the renamed Clients variable

🤖
This commit is contained in:
Sebastian Mark 2024-10-21 09:24:20 +02:00
parent aab6896c7d
commit 6ffd9f1e38
2 changed files with 3 additions and 5 deletions

View file

@ -0,0 +1,30 @@
package websocket
import (
"encoding/json"
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
"github.com/gorilla/websocket"
"log"
"time"
)
// BroadcastMessage sends a message to all connected WebSocket clients.
func SendPermanentBroadCastMessage() {
for {
// Marshal the message into JSON format
jsonMessage, err := json.Marshal(shared.Message)
if err != nil {
log.Printf("Error marshalling message: %v", err)
return
}
// Iterate over all connected clients and broadcast the message
for _, client := range Clients {
err := client.SendMessage(websocket.TextMessage, jsonMessage)
if err != nil {
log.Printf("Error broadcasting to client: %v", err)
// The client is responsible for closing itself on error
}
}
time.Sleep(time.Second)
}
}