feat: ping/pong in computer websocket

This commit is contained in:
trafficlunar 2025-09-22 11:59:35 +01:00
parent 5dbb3394bb
commit e7a3cd8606

View file

@ -39,6 +39,16 @@ func HandleComputerWebSocket(w http.ResponseWriter, r *http.Request) {
slog.Info("WebSocket connection established") slog.Info("WebSocket connection established")
// Respond to client pings
conn.SetPingHandler(func(appData string) error {
slog.Info("Recieved ping from client")
return conn.WriteControl(
websocket.PongMessage,
[]byte(appData), // echo back the same data
time.Now().Add(10*time.Second), // deadline
)
})
// Mark computer online and record the start time for uptime tracking // Mark computer online and record the start time for uptime tracking
service.ComputerData.Online = true service.ComputerData.Online = true
service.ComputerData.UptimeStart = int(time.Now().Unix()) service.ComputerData.UptimeStart = int(time.Now().Unix())