From bdfc684cd7b4d7bd828c4e1f6bf7c808649ab8ba Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Mon, 25 Dec 2023 23:05:59 +0530 Subject: [PATCH] Prevent race of new track and new receiver. (#2345) * Prevent race of new track and new receiver. Two different concepts 1. Creation of a new media track 2. Creation of a new receiver inside the media track collided and caused track published to not be fired. Unify to mark creation of new receiver as the source of truth. With simulcast codecs, creation of a new receiver should be treated as a new published track. * Fire onTrackPublished only on new track --- pkg/rtc/participant.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 285963286..b6d63e334 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -1861,10 +1861,17 @@ func (p *ParticipantImpl) mediaTrackReceived(track *webrtc.TrackRemote, rtpRecei if mt.AddReceiver(rtpReceiver, track, p.twcc, mid) { p.removeMutedTrackNotFired(mt) - if newTrack { - p.pubLogger.Debugw("track published", "trackID", mt.ID(), "track", logger.Proto(mt.ToProto())) - go p.handleTrackPublished(mt) - } + } + + if newTrack { + go func() { + p.pubLogger.Debugw( + "track published", + "trackID", mt.ID(), + "track", logger.Proto(mt.ToProto()), + ) + p.handleTrackPublished(mt) + }() } return mt, newTrack