Sebastian Mark
b943c9d6eb
- introduce `Client` model
- modify all websocket operations to use the new `Client` model
- update function signatures to accept `models.Client` instead of `*websocket.Conn`
- ensure consistent usage of `client` across all related functions
🤖
43 lines
1,003 B
Go
43 lines
1,003 B
Go
package websocket
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/charmbracelet/log"
|
|
"github.com/gorilla/websocket"
|
|
|
|
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
|
)
|
|
|
|
func sendClientCommand(client ChronoTomato.Client, msg GoTomato.ClientCommand) {
|
|
messageBytes, err := json.Marshal(msg)
|
|
if err != nil {
|
|
log.Error("Error marshalling!", "reason", err)
|
|
return
|
|
}
|
|
|
|
err = client.Conn.WriteMessage(websocket.TextMessage, messageBytes)
|
|
if err != nil {
|
|
log.Error("Write error!", "reason", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
func SendCmd(client ChronoTomato.Client, pwd string, cmd string) {
|
|
message := GoTomato.ClientCommand{
|
|
Command: cmd,
|
|
Password: pwd,
|
|
}
|
|
|
|
sendClientCommand(client, message)
|
|
}
|
|
|
|
func Send_updateSettings(client ChronoTomato.Client, pwd string, settings GoTomato.PomodoroConfig) {
|
|
message := GoTomato.ClientCommand{
|
|
Command: "updateSettings",
|
|
Password: pwd,
|
|
Settings: settings,
|
|
}
|
|
|
|
sendClientCommand(client, message)
|
|
}
|