Room API to support selective subscriptions

This commit is contained in:
David Zhao
2021-06-23 14:12:51 -07:00
parent 0c75924c73
commit d8b96ac2c8
6 changed files with 55 additions and 14 deletions
+1
View File
@@ -9,4 +9,5 @@ var (
ErrAlreadyJoined = errors.New("a participant with the same identity is already in the room")
ErrUnexpectedOffer = errors.New("expected answer SDP, received offer")
ErrDataChannelUnavailable = errors.New("data channel is not available")
ErrCannotSubscribe = errors.New("participant does not have permission to subscribe")
)
+7 -3
View File
@@ -248,12 +248,16 @@ func (r *Room) RemoveParticipant(identity string) {
}
}
func (r *Room) UpdateSubscriptions(participant types.Participant, subscription *livekit.UpdateSubscription) error {
func (r *Room) UpdateSubscriptions(participant types.Participant, trackIds []string, subscribe bool) error {
if !participant.CanSubscribe() {
return ErrCannotSubscribe
}
// find all matching tracks
var tracks []types.PublishedTrack
participants := r.GetParticipants()
for _, p := range participants {
for _, sid := range subscription.TrackSids {
for _, sid := range trackIds {
for _, track := range p.GetPublishedTracks() {
if sid == track.ID() {
tracks = append(tracks, track)
@@ -264,7 +268,7 @@ func (r *Room) UpdateSubscriptions(participant types.Participant, subscription *
// handle subscription changes
for _, track := range tracks {
if subscription.Subscribe {
if subscribe {
if err := track.AddSubscriber(participant); err != nil {
return err
}