ChronoTomato/internal/websocket/send.go
Sebastian Mark bbc9977f1c feat: refactor shared.Message to a channel
- remove `shared` package and shared.Message
- rename `notifications` package to `frontend`
- introduce a channel send the received ServerMessages to the frontend handler(s)
- move keyhandler to goroutine
- simplify password handling in Start function
- update import names when importing from GoTomoto
2024-10-27 22:33:30 +01:00

42 lines
943 B
Go

package websocket
import (
"encoding/json"
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
"github.com/charmbracelet/log"
"github.com/gorilla/websocket"
)
func sendClientCommand(conn *websocket.Conn, msg GoTomato.ClientCommand) {
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{
Command: cmd,
Password: pwd,
}
sendClientCommand(conn, message)
}
func Send_updateSettings(conn *websocket.Conn, pwd string, settings GoTomato.GoTomatoPomodoroConfig) {
message := GoTomato.ClientCommand{
Command: "updateSettings",
Password: pwd,
PomodoroSettings: settings,
}
sendClientCommand(conn, message)
}