5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-25 19:01:35 +00:00

Sent loopback messages to other websockets as well (api) (#1216)

This commit is contained in:
NikkyAI 2020-08-27 22:28:03 +02:00 committed by GitHub
parent 58b6c4d277
commit c63f08c811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,7 +44,7 @@ func New(cfg *bridge.Config) bridge.Bridger {
b.Log.Errorf("failed to decode message from byte[] '%s'", string(msg)) b.Log.Errorf("failed to decode message from byte[] '%s'", string(msg))
return return
} }
b.handleWebsocketMessage(message) b.handleWebsocketMessage(message, s)
}) })
b.mrouter.HandleConnect(func(session *melody.Session) { b.mrouter.HandleConnect(func(session *melody.Session) {
greet := b.getGreeting() 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.Channel = "api"
message.Protocol = "api" message.Protocol = "api"
message.Account = b.Account message.Account = b.Account
message.ID = "" message.ID = ""
message.Timestamp = time.Now() 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.Log.Debugf("Sending websocket message from %s on %s to gateway", message.Username, "api")
b.Remote <- message b.Remote <- message
} }