Fix panics due to concurrent websocket writes

This commit is contained in:
Lubos Dolezel
2023-02-24 11:49:26 +01:00
parent 8bee96aeff
commit f27cbfb299
21 changed files with 131 additions and 141 deletions

View File

@@ -3,14 +3,13 @@ package services
import (
"context"
"github.com/gorilla/websocket"
ws "saml.dev/gome-assistant/internal/websocket"
)
/* Structs */
type Lock struct {
conn *websocket.Conn
conn *ws.WebsocketWriter
ctx context.Context
}
@@ -26,7 +25,7 @@ func (l Lock) Lock(entityId string, serviceData ...map[string]any) {
req.ServiceData = serviceData[0]
}
ws.WriteMessage(req, l.conn, l.ctx)
l.conn.WriteMessage(req, l.ctx)
}
// Unlock a lock entity. Takes an entityId and an optional
@@ -39,5 +38,5 @@ func (l Lock) Unlock(entityId string, serviceData ...map[string]any) {
req.ServiceData = serviceData[0]
}
ws.WriteMessage(req, l.conn, l.ctx)
l.conn.WriteMessage(req, l.ctx)
}