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.
This commit is contained in:
Pablo Fuente Pérez
2026-09-04 23:49:33 +05:30
committed by GitHub
parent e77173df95
commit 407fe3fe26
+38
View File
@@ -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