mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-11 08:35:37 +00:00
feature: Refresh dashboards when entity files change. (#319)
* feature: Refresh dashboards when entities change * feature: Refresh dashboards when entities change * bugfix: Concurrency, lock around websocket write
This commit is contained in:
@@ -8,12 +8,17 @@ import (
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"net/http"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var upgrader = ws.Upgrader{
|
||||
CheckOrigin: checkOriginPermissive,
|
||||
}
|
||||
|
||||
var (
|
||||
sendmutex = sync.Mutex{}
|
||||
)
|
||||
|
||||
type WebsocketClient struct {
|
||||
conn *ws.Conn
|
||||
}
|
||||
@@ -44,6 +49,10 @@ func (WebsocketExecutionListener) OnExecutionStarted(title string) {
|
||||
*/
|
||||
}
|
||||
|
||||
func OnEntityChanged() {
|
||||
broadcast(&pb.EventEntityChanged{})
|
||||
}
|
||||
|
||||
/*
|
||||
The default checkOrigin function checks that the origin (browser) matches the
|
||||
request origin. However in OliveTin we expect many users to deliberately proxy
|
||||
@@ -113,9 +122,11 @@ func broadcast(pbmsg protoreflect.ProtoMessage) {
|
||||
hackyMessage = append(hackyMessage, []byte("}")...)
|
||||
// </EVIL>
|
||||
|
||||
sendmutex.Lock()
|
||||
for _, client := range clients {
|
||||
client.conn.WriteMessage(ws.TextMessage, hackyMessage)
|
||||
}
|
||||
sendmutex.Unlock()
|
||||
}
|
||||
|
||||
func (c *WebsocketClient) messageLoop() {
|
||||
|
||||
Reference in New Issue
Block a user