improvement websocket according to gorilla example

This commit is contained in:
Adrian Zürcher
2025-06-22 07:46:24 +02:00
parent 659cbe4072
commit 91ea59ed6e
6 changed files with 131 additions and 66 deletions

View File

@@ -6,7 +6,6 @@ import (
"fmt"
"regexp"
"strings"
"sync"
"time"
"github.com/google/uuid"
@@ -34,7 +33,6 @@ type Datapoint struct {
ReadWrite json_dataModels.Rights `json:"readWrite"`
Drivers json_dataModels.Drivers `json:"drivers,omitempty"`
Subscriptions Subscriptions `json:"-"`
sync.RWMutex `json:"-"`
}
func (d *Datapoint) Set(path string, set json_dataModels.Set) (bool, error) {
@@ -381,9 +379,6 @@ func (d *Datapoint) RemoveSubscribtion(client *wsModels.Client) {
}
func (d *Datapoint) Publish(eventType string) error {
d.RLock()
defer d.RUnlock()
for client := range d.Subscriptions {
r := json_data.NewResponse()
r.AddPublish(json_dataModels.Publish{
@@ -392,14 +387,13 @@ func (d *Datapoint) Publish(eventType string) error {
Path: d.Path,
Value: d.Value,
})
b, err := json.Marshal(r)
if err != nil {
return err
}
if err := client.SendResponse(b, 5); err != nil {
return err
}
client.SendResponse(b)
}
return nil
}