Include participant_sid in UpdateSubscription. (#279)

* Include `participant_sid` in `UpdateSubscription`.

Prevents all publisher tracks to find a match.

* generate

* Update protocol version
This commit is contained in:
Raja Subramanian
2021-12-23 09:18:32 +05:30
committed by GitHub
parent 42a9b6657d
commit eae6eff6a3
7 changed files with 73 additions and 24 deletions
+39 -8
View File
@@ -92,6 +92,19 @@ func (r *Room) GetParticipant(identity string) types.Participant {
return r.participants[identity]
}
func (r *Room) GetParticipantBySid(participantID string) types.Participant {
r.lock.RLock()
defer r.lock.RUnlock()
for _, p := range r.participants {
if p.ID() == participantID {
return p
}
}
return nil
}
func (r *Room) GetParticipants() []types.Participant {
r.lock.RLock()
defer r.lock.RUnlock()
@@ -322,16 +335,34 @@ func (r *Room) RemoveParticipant(identity string) {
}
}
func (r *Room) UpdateSubscriptions(participant types.Participant, trackIds []string, subscribe bool) error {
func (r *Room) UpdateSubscriptions(
participant types.Participant,
trackIds []string,
participantTracks []*livekit.ParticipantTracks,
subscribe bool,
) error {
// find all matching tracks
var tracks []types.PublishedTrack
tracks := make(map[string]types.PublishedTrack)
participants := r.GetParticipants()
for _, p := range participants {
for _, sid := range trackIds {
for _, track := range p.GetPublishedTracks() {
if sid == track.ID() {
tracks = append(tracks, track)
}
for _, trackSid := range trackIds {
for _, p := range participants {
track := p.GetPublishedTrack(trackSid)
if track != nil {
tracks[trackSid] = track
break
}
}
}
for _, pt := range participantTracks {
p := r.GetParticipantBySid(pt.ParticipantSid)
if p == nil {
continue
}
for _, trackSid := range pt.TrackSids {
track := p.GetPublishedTrack(trackSid)
if track != nil {
tracks[trackSid] = track
}
}
}