feat: ping/pong in computer websocket
This commit is contained in:
parent
5dbb3394bb
commit
e7a3cd8606
1 changed files with 10 additions and 0 deletions
|
|
@ -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())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue