Sebastian Mark
ab2e8c161d
- add goroutine to remove stale clients from the connection pool
- update client struct to track `LastPong` time
- set write deadline for websocket connections
- move package variables and const to `vars.go`
- log additional information when broadcasting errors
🤖
27 lines
712 B
Go
27 lines
712 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
// Represents a command from the client (start/stop)
|
|
type ClientCommand struct {
|
|
Command string `json:"command"` // Command send to the server
|
|
Password string `json:"password"` // Pomodoro control password
|
|
Settings PomodoroConfig `json:"settings"` // Pomodoro config
|
|
}
|
|
|
|
// Represents a single client
|
|
type WebsocketClient struct {
|
|
Conn *websocket.Conn
|
|
LastPong time.Time
|
|
RealIP string
|
|
}
|
|
|
|
// Sends a message to the websocket.
|
|
func (c *WebsocketClient) SendMessage(messageType int, data []byte) error {
|
|
c.Conn.SetWriteDeadline(time.Now().Add(TIMEOUT * time.Second))
|
|
return c.Conn.WriteMessage(messageType, data)
|
|
}
|