add and improve remove driver function and rename datapoint

This commit is contained in:
Adrian Zuercher
2025-07-31 12:20:49 +02:00
parent b21101958d
commit 21e4231e24
8 changed files with 107 additions and 49 deletions

View File

@@ -38,7 +38,6 @@ func (cH *ClientHandler) ConnectNewClient(id string, c *gin.Context) (client *mo
client, err = models.ConnectNewClient(id, c)
client.OnClose = func(code int, reason string) {
fmt.Println(23, "closing", id)
delete(cH.Clients, id)
}

View File

@@ -17,10 +17,10 @@ var Broadcast Clients = make(Clients)
const (
// Time allowed to write a message to the peer.
writeWait = 30 * time.Second
writeWait = 10 * time.Second
// Time allowed to read the next pong message from the peer.
pongWait = 40 * time.Second
pongWait = 30 * time.Second
// Send pings to peer with this period. Must be less than pongWait.
pingPeriod = (pongWait * 9) / 10
@@ -69,12 +69,15 @@ func ConnectNewClient(id string, c *gin.Context) (*Client, error) {
Broadcast[client.Id] = client
conn.SetReadDeadline(time.Now().Add(pongWait))
conn.SetPingHandler(func(appData string) error {
if client.OnPing != nil {
client.OnPing()
}
conn.SetReadDeadline(time.Now().Add(pongWait))
conn.SetWriteDeadline(time.Now().Add(writeWait))
conn.SetReadDeadline(time.Now().Add(writeWait))
if err := client.conn.WriteControl(websocket.PongMessage, []byte(appData), time.Now().Add(pongWait)); err != nil {
client.OnError(err)
}
@@ -166,6 +169,7 @@ func (c *Client) PingInterval(interval time.Duration) {
c.OnError(err)
return
}
for range ticker.C {
if c.OnPing != nil {
c.OnPing()