Skip to content

Commit

Permalink
Merge pull request #434 from bbernhard/multimaster_mode
Browse files Browse the repository at this point in the history
Multimaster mode
  • Loading branch information
bbernhard authored Oct 30, 2023
2 parents b36d28f + 6feb707 commit c493655
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 174 deletions.
22 changes: 17 additions & 5 deletions src/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (a *Api) SendV2(c *gin.Context) {
}

func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan struct{}) {
receiveChannel, err := a.signalClient.GetReceiveChannel(number)
receiveChannel, err := a.signalClient.GetReceiveChannel()
if err != nil {
log.Error("Couldn't get receive channel: ", err.Error())
return
Expand All @@ -405,12 +405,24 @@ func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan s

if err == nil {
if data != "" {
err = ws.WriteMessage(websocket.TextMessage, []byte(data))
type Response struct {
Account string `json:"account"`
}
var response Response
err = json.Unmarshal([]byte(data), &response)
if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
log.Error("Couldn't write message: " + err.Error())
log.Error("Couldn't parse message ", data, ":", err.Error())
continue
}

if response.Account == number {
err = ws.WriteMessage(websocket.TextMessage, []byte(data))
if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
log.Error("Couldn't write message: " + err.Error())
}
return
}
return
}
}
} else {
Expand Down
Loading

0 comments on commit c493655

Please sign in to comment.