summaryrefslogtreecommitdiffstats
path: root/bridge/api
diff options
context:
space:
mode:
Diffstat (limited to 'bridge/api')
-rw-r--r--bridge/api/api.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/bridge/api/api.go b/bridge/api/api.go
index 9c937565..515007f0 100644
--- a/bridge/api/api.go
+++ b/bridge/api/api.go
@@ -44,7 +44,7 @@ func New(cfg *bridge.Config) bridge.Bridger {
b.Log.Errorf("failed to decode message from byte[] '%s'", string(msg))
return
}
- b.handleWebsocketMessage(message)
+ b.handleWebsocketMessage(message, s)
})
b.mrouter.HandleConnect(func(session *melody.Session) {
greet := b.getGreeting()
@@ -178,13 +178,20 @@ func (b *API) handleStream(c echo.Context) error {
}
}
-func (b *API) handleWebsocketMessage(message config.Message) {
+func (b *API) handleWebsocketMessage(message config.Message, s *melody.Session) {
message.Channel = "api"
message.Protocol = "api"
message.Account = b.Account
message.ID = ""
message.Timestamp = time.Now()
+ data, err := json.Marshal(message)
+ if err != nil {
+ b.Log.Errorf("failed to encode message for loopback '%v'", message)
+ return
+ }
+ _ = b.mrouter.BroadcastOthers(data, s)
+
b.Log.Debugf("Sending websocket message from %s on %s to gateway", message.Username, "api")
b.Remote <- message
}