|
|
@@ -6,6 +6,7 @@ import (
|
|
|
ws "github.com/gorilla/websocket"
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
|
+ "google.golang.org/protobuf/reflect/protoreflect"
|
|
|
"net/http"
|
|
|
)
|
|
|
|
|
|
@@ -24,6 +25,12 @@ var marshalOptions = protojson.MarshalOptions{
|
|
|
EmitUnpopulated: true,
|
|
|
}
|
|
|
|
|
|
+func OnConfigChanged() {
|
|
|
+ evt := &pb.EventConfigChanged{}
|
|
|
+
|
|
|
+ broadcast(evt)
|
|
|
+}
|
|
|
+
|
|
|
var ExecutionListener WebsocketExecutionListener
|
|
|
|
|
|
type WebsocketExecutionListener struct{}
|
|
|
@@ -72,12 +79,19 @@ func (WebsocketExecutionListener) OnExecutionFinished(logEntry *executor.Interna
|
|
|
ExecutionFinished: logEntry.ExecutionFinished,
|
|
|
}
|
|
|
|
|
|
- broadcast("ExecutionFinished", le)
|
|
|
+ broadcast(le)
|
|
|
}
|
|
|
|
|
|
-func broadcast(messageType string, pbmsg *pb.LogEntry) {
|
|
|
+func broadcast(pbmsg protoreflect.ProtoMessage) {
|
|
|
payload, err := marshalOptions.Marshal(pbmsg)
|
|
|
|
|
|
+ if err != nil {
|
|
|
+ log.Errorf("websocket marshal error: %v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ messageType := pbmsg.ProtoReflect().Descriptor().FullName()
|
|
|
+
|
|
|
// <EVIL>
|
|
|
// So, the websocket wants to encode messages using the same protomarshaller
|
|
|
// as the REST API - this gives consistency instead of using encoding/json
|
|
|
@@ -97,13 +111,8 @@ func broadcast(messageType string, pbmsg *pb.LogEntry) {
|
|
|
hackyMessage = append(hackyMessage, []byte("}")...)
|
|
|
// </EVIL>
|
|
|
|
|
|
- if err != nil {
|
|
|
- log.Errorf("websocket marshal error: %v", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
for _, client := range clients {
|
|
|
- client.conn.WriteMessage(1, hackyMessage)
|
|
|
+ client.conn.WriteMessage(ws.TextMessage, hackyMessage)
|
|
|
}
|
|
|
}
|
|
|
|