forked from jshiffer/matterbridge
Sent loopback messages to other websockets as well (api) (#1216)
This commit is contained in:
parent
58b6c4d277
commit
c63f08c811
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user