package websocket import ( "encoding/json" "github.com/charmbracelet/log" "github.com/gorilla/websocket" GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models" ) // Sends to ClientCommand to the clients websocket func (c Client) sendClientCommand(msg GoTomato.ClientCommand) { messageBytes, err := json.Marshal(msg) if err != nil { log.Error("Error marshalling!", "reason", err) return } err = c.Conn.WriteMessage(websocket.TextMessage, messageBytes) if err != nil { log.Error("Write error!", "reason", err) return } } // Sends the passed command to the server func (c Client) SendCmd(cmd string) { message := GoTomato.ClientCommand{ Command: cmd, Password: c.Password, } c.sendClientCommand(message) } // Sends the new PomodoroConfig to the server func (c Client) SendSettingsUpdate(settings GoTomato.PomodoroConfig) { message := GoTomato.ClientCommand{ Command: "updateSettings", Password: c.Password, Settings: settings, } c.sendClientCommand(message) }