From 7f8e63233085053722af7c6f451fdf1b86132656 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sun, 11 May 2025 03:08:30 +0530 Subject: [PATCH] Send self participant update immediately. (#3656) * Send self participant update immediately. Match with cloud. Send immediately for non-hidden participants also * comment --- pkg/rtc/room.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/rtc/room.go b/pkg/rtc/room.go index 602145a9..712d3869 100644 --- a/pkg/rtc/room.go +++ b/pkg/rtc/room.go @@ -1337,19 +1337,32 @@ func (r *Room) subscribeToExistingTracks(p types.LocalParticipant) { func (r *Room) broadcastParticipantState(p types.LocalParticipant, opts broadcastOptions) { pi := p.ToProto() - if p.Hidden() { - if !opts.skipSource { - // send update only to hidden participant + // send it to the same participant immediately + selfSent := false + if !opts.skipSource { + defer func() { + if selfSent { + return + } + err := p.SendParticipantUpdate([]*livekit.ParticipantInfo{pi}) if err != nil { p.GetLogger().Errorw("could not send update to participant", err) } - } + }() + } + + if p.Hidden() { + // hidden participant updates are sent only to the hidden participant itself, + // these could be things like metadata update return } updates := r.pushAndDequeueUpdates(pi, p.CloseReason(), opts.immediate) - r.sendParticipantUpdates(updates) + if len(updates) != 0 { + selfSent = true + r.sendParticipantUpdates(updates) + } } func (r *Room) sendParticipantUpdates(updates []*participantUpdate) {