From 3a2efbcc7ec7885d53f580575b89d1b70d2e9d8d Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Tue, 6 Sep 2022 03:03:50 +0200 Subject: [PATCH] Send chathistory messages in the client goroutine. We used to send the chat history from the reader goroutine, which would cause them to race with the join message. --- rtpconn/webclient.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index 18268d7..7a23f95 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -1177,7 +1177,7 @@ func handleAction(c *webClient, a interface{}) error { } } perms := append([]string(nil), c.permissions...) - return c.write(clientMessage{ + err := c.write(clientMessage{ Type: "joined", Kind: a.kind, Group: a.group, @@ -1187,6 +1187,23 @@ func handleAction(c *webClient, a interface{}) error { Data: data, RTCConfiguration: ice.ICEConfiguration(), }) + if err != nil { + return err + } + h := c.group.GetChatHistory() + for _, m := range h { + err := c.write(clientMessage{ + Type: "chathistory", + Id: m.Id, + Username: m.User, + Time: m.Time, + Value: m.Value, + Kind: m.Kind, + }) + if err != nil { + return err + } + } case permissionsChangedAction: g := c.Group() if g == nil { @@ -1426,20 +1443,6 @@ func handleClientMessage(c *webClient, m clientMessage) error { }) } c.group = g - h := c.group.GetChatHistory() - for _, m := range h { - err := c.write(clientMessage{ - Type: "chathistory", - Id: m.Id, - Username: m.User, - Time: m.Time, - Value: m.Value, - Kind: m.Kind, - }) - if err != nil { - return err - } - } case "request": requested, err := parseRequested(m.Request) if err != nil {