Allow subscription requests made from server APIs (#249)
This commit is contained in:
@@ -160,10 +160,6 @@ func (t *MediaTrack) PublishLossPercentage() uint32 {
|
|||||||
|
|
||||||
// AddSubscriber subscribes sub to current mediaTrack
|
// AddSubscriber subscribes sub to current mediaTrack
|
||||||
func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
||||||
if !sub.CanSubscribe() {
|
|
||||||
return ErrPermissionDenied
|
|
||||||
}
|
|
||||||
|
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
|
|
||||||
|
|||||||
+1
-5
@@ -8,8 +8,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
livekit "github.com/livekit/protocol/livekit"
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
@@ -316,10 +316,6 @@ 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, subscribe bool) error {
|
||||||
if !participant.CanSubscribe() {
|
|
||||||
return ErrCannotSubscribe
|
|
||||||
}
|
|
||||||
|
|
||||||
// find all matching tracks
|
// find all matching tracks
|
||||||
var tracks []types.PublishedTrack
|
var tracks []types.PublishedTrack
|
||||||
participants := r.GetParticipants()
|
participants := r.GetParticipants()
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
livekit "github.com/livekit/protocol/livekit"
|
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
"github.com/livekit/livekit-server/pkg/routing"
|
"github.com/livekit/livekit-server/pkg/routing"
|
||||||
@@ -421,7 +421,16 @@ func (r *RoomManager) handleSignalRequest(room *rtc.Room, participant types.Part
|
|||||||
case *livekit.SignalRequest_Mute:
|
case *livekit.SignalRequest_Mute:
|
||||||
participant.SetTrackMuted(msg.Mute.Sid, msg.Mute.Muted, false)
|
participant.SetTrackMuted(msg.Mute.Sid, msg.Mute.Muted, false)
|
||||||
case *livekit.SignalRequest_Subscription:
|
case *livekit.SignalRequest_Subscription:
|
||||||
if err := room.UpdateSubscriptions(participant, msg.Subscription.TrackSids, msg.Subscription.Subscribe); err != nil {
|
var err error
|
||||||
|
if participant.CanSubscribe() {
|
||||||
|
updateErr := room.UpdateSubscriptions(participant, msg.Subscription.TrackSids, msg.Subscription.Subscribe)
|
||||||
|
if updateErr != nil {
|
||||||
|
err = updateErr
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = rtc.ErrCannotSubscribe
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
logger.Warnw("could not update subscription", err,
|
logger.Warnw("could not update subscription", err,
|
||||||
"room", room.Room.Name,
|
"room", room.Room.Name,
|
||||||
"participant", participant.Identity(),
|
"participant", participant.Identity(),
|
||||||
|
|||||||
Reference in New Issue
Block a user