Publisher controlled flex permissions (#284)
* WIP commit * Add some tests * allowedSubscribers uses participant sid * correct variable name * correct another variable name * Add ParticipantSid to SubscriptionPermissionUpdate message * protocol v0.11.2 * WIP commit * WIP commit * fix tests * Remove unused code * Close uptrack manager * Remove duplicate close * move comment to the correct line where the loop could be long * Fix disallowed list revocation, thank you Jie * Remove unneeded interface method * RemoveSubscriber in Participant * Clean up disallowed subscriptions and handle permissions on new track addition * add test for track addition after permission set * Remove unnecessary check
This commit is contained in:
+23
-11
@@ -342,13 +342,13 @@ func (r *Room) UpdateSubscriptions(
|
||||
subscribe bool,
|
||||
) error {
|
||||
// find all matching tracks
|
||||
tracks := make(map[string]types.PublishedTrack)
|
||||
trackPublishers := make(map[string]types.Participant)
|
||||
participants := r.GetParticipants()
|
||||
for _, trackSid := range trackIds {
|
||||
for _, p := range participants {
|
||||
track := p.GetPublishedTrack(trackSid)
|
||||
if track != nil {
|
||||
tracks[trackSid] = track
|
||||
trackPublishers[trackSid] = p
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -360,26 +360,38 @@ func (r *Room) UpdateSubscriptions(
|
||||
continue
|
||||
}
|
||||
for _, trackSid := range pt.TrackSids {
|
||||
track := p.GetPublishedTrack(trackSid)
|
||||
if track != nil {
|
||||
tracks[trackSid] = track
|
||||
}
|
||||
trackPublishers[trackSid] = p
|
||||
}
|
||||
}
|
||||
|
||||
// handle subscription changes
|
||||
for _, track := range tracks {
|
||||
for trackSid, publisher := range trackPublishers {
|
||||
if subscribe {
|
||||
if err := track.AddSubscriber(participant); err != nil {
|
||||
if _, err := publisher.AddSubscriber(participant, types.AddSubscriberParams{TrackSids: []string{trackSid}}); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
track.RemoveSubscriber(participant.ID())
|
||||
publisher.RemoveSubscriber(participant, trackSid)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Room) UpdateSubscriptionPermissions(participant types.Participant, permissions *livekit.UpdateSubscriptionPermissions) error {
|
||||
return participant.UpdateSubscriptionPermissions(permissions, r.GetParticipantBySid)
|
||||
}
|
||||
|
||||
func (r *Room) RemoveDisallowedSubscriptions(sub types.Participant, disallowedSubscriptions map[string]string) {
|
||||
for trackSid, publisherSid := range disallowedSubscriptions {
|
||||
pub := r.GetParticipantBySid(publisherSid)
|
||||
if pub == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
pub.RemoveSubscriber(sub, trackSid)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Room) IsClosed() bool {
|
||||
select {
|
||||
case <-r.closed:
|
||||
@@ -523,7 +535,7 @@ func (r *Room) onTrackPublished(participant types.Participant, track types.Publi
|
||||
"participants", []string{participant.Identity(), existingParticipant.Identity()},
|
||||
"pIDs", []string{participant.ID(), existingParticipant.ID()},
|
||||
"track", track.ID())
|
||||
if err := track.AddSubscriber(existingParticipant); err != nil {
|
||||
if _, err := participant.AddSubscriber(existingParticipant, types.AddSubscriberParams{TrackSids: []string{track.ID()}}); err != nil {
|
||||
r.Logger.Errorw("could not subscribe to remoteTrack", err,
|
||||
"participants", []string{participant.Identity(), existingParticipant.Identity()},
|
||||
"pIDs", []string{participant.ID(), existingParticipant.ID()},
|
||||
@@ -595,7 +607,7 @@ func (r *Room) subscribeToExistingTracks(p types.Participant) {
|
||||
// don't send to itself
|
||||
continue
|
||||
}
|
||||
if n, err := op.AddSubscriber(p); err != nil {
|
||||
if n, err := op.AddSubscriber(p, types.AddSubscriberParams{AllTracks: true}); err != nil {
|
||||
// TODO: log error? or disconnect?
|
||||
r.Logger.Errorw("could not subscribe to participant", err,
|
||||
"participants", []string{op.Identity(), p.Identity()},
|
||||
|
||||
Reference in New Issue
Block a user