summaryrefslogtreecommitdiffstats
path: root/bridge/api/api.go
diff options
context:
space:
mode:
authorNikkyAI <root@nikky.moe>2020-08-27 22:28:03 +0200
committerGitHub <noreply@github.com>2020-08-27 22:28:03 +0200
commitc63f08c8113598149f312bffd3fbdf1970660639 (patch)
tree52a5080b4a6dd538bc9163db29c35f3d79535d80 /bridge/api/api.go
parent58b6c4d277d4577baadc376deee7d306c332f420 (diff)
downloadmatterbridge-msglm-c63f08c8113598149f312bffd3fbdf1970660639.tar.gz
matterbridge-msglm-c63f08c8113598149f312bffd3fbdf1970660639.tar.bz2
matterbridge-msglm-c63f08c8113598149f312bffd3fbdf1970660639.zip
Sent loopback messages to other websockets as well (api) (#1216)
Diffstat (limited to 'bridge/api/api.go')
-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
}