From 407fe3fe26f7aad72f1307f01020d9a7671de6d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Fuente=20P=C3=A9rez?= Date: Fri, 4 Sep 2026 20:19:33 +0200 Subject: [PATCH] rtc: send connection quality to participants that subscribe after their first update (#4838) * rtc: send connection quality to participants that subscribe after their first update Added tracking for participants' connection quality updates to ensure all subscribed participants receive necessary updates, even if they were added after the last quality announcement * rtc: record sent connection quality only after a successful send A failed SendConnectionQualityUpdate must not mark the participant as informed, otherwise the update is never retried while qualities stay stable. Also simplify the untold-subscription check. --- pkg/rtc/room.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pkg/rtc/room.go b/pkg/rtc/room.go index 76224e73..0585fe48 100644 --- a/pkg/rtc/room.go +++ b/pkg/rtc/room.go @@ -1681,6 +1681,8 @@ func (r *Room) connectionQualityWorker() { defer ticker.Stop() prevConnectionInfos := make(map[livekit.ParticipantID]*livekit.ConnectionQualityInfo) + // per participant, the participants whose quality it was told about in its last update + toldQualityOf := make(map[livekit.ParticipantID]map[livekit.ParticipantID]struct{}) // send updates to only users that are subscribed to each other for !r.IsClosed() { <-ticker.C @@ -1718,6 +1720,32 @@ func (r *Room) connectionQualityWorker() { } } + // also send if a participant is subscribed to someone whose quality it has never been told about: + // its subscriptions may have been established after the tick that announced it as a new entrant, + // and without a later quality change it would never receive their quality + for pID := range toldQualityOf { + if _, nowOk := nowConnectionInfos[pID]; !nowOk { + // participant is not ACTIVE any more + delete(toldQualityOf, pID) + } + } + if !sendUpdate { + sendUpdate = slices.ContainsFunc(participants, func(op types.LocalParticipant) bool { + if !op.ProtocolVersion().SupportsConnectionQuality() || op.State() != livekit.ParticipantInfo_ACTIVE { + return false + } + for _, sid := range op.GetSubscribedParticipants() { + if _, nowOk := nowConnectionInfos[sid]; !nowOk { + continue + } + if _, told := toldQualityOf[op.ID()][sid]; !told { + return true + } + } + return false + }) + } + if !sendUpdate { prevConnectionInfos = nowConnectionInfos continue @@ -1746,10 +1774,20 @@ func (r *Room) connectionQualityWorker() { // no change continue } + if err := op.SendConnectionQualityUpdate(update); err != nil { r.logger.Warnw("could not send connection quality update", err, "participant", op.Identity()) + continue } + + // remember which participants' quality this participant has been sent, + // only after a successful send so that a failed one is retried on next tick + told := make(map[livekit.ParticipantID]struct{}, len(update.Updates)) + for _, info := range update.Updates { + told[livekit.ParticipantID(info.ParticipantSid)] = struct{}{} + } + toldQualityOf[op.ID()] = told } prevConnectionInfos = nowConnectionInfos