From c63f08c8113598149f312bffd3fbdf1970660639 Mon Sep 17 00:00:00 2001 From: NikkyAI Date: Thu, 27 Aug 2020 22:28:03 +0200 Subject: [PATCH] Sent loopback messages to other websockets as well (api) (#1216) --- bridge/api/api.go | 11 +++++++++-- 1 file 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 }