improvement websocket according to gorilla example
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user