ChronoTomato/internal/websocket/send.go

42 lines
942 B
Go
Raw Normal View History

2024-10-22 11:13:41 +00:00
package websocket
import (
"encoding/json"
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
2024-10-22 11:13:41 +00:00
"github.com/charmbracelet/log"
"github.com/gorilla/websocket"
)
func sendClientCommand(conn *websocket.Conn, msg GoTomato.ClientCommand) {
2024-10-22 11:13:41 +00:00
messageBytes, err := json.Marshal(msg)
if err != nil {
log.Error("Error marshalling!", "reason", err)
return
}
err = conn.WriteMessage(websocket.TextMessage, messageBytes)
if err != nil {
log.Error("Write error!", "reason", err)
return
}
}
func SendCmd(conn *websocket.Conn, pwd string, cmd string) {
message := GoTomato.ClientCommand{
2024-10-22 11:13:41 +00:00
Command: cmd,
Password: pwd,
}
sendClientCommand(conn, message)
}
func Send_updateSettings(conn *websocket.Conn, pwd string, settings GoTomato.GoTomatoPomodoroConfig) {
message := GoTomato.ClientCommand{
2024-10-22 11:13:41 +00:00
Command: "updateSettings",
Password: pwd,
PomodoroSettings: settings,
2024-10-22 11:13:41 +00:00
}
sendClientCommand(conn, message)
}