Enforce subscriptio permission to data track (#4588)
* Enforce subscriptio permission to data track * use revoke path as same as media track * nil check
This commit is contained in:
@@ -16,6 +16,7 @@ package rtc
|
||||
|
||||
import (
|
||||
"github.com/livekit/livekit-server/pkg/rtc/datatrack"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
@@ -156,6 +157,33 @@ func (p *ParticipantImpl) onReceivedDataTrackMessage(data []byte, arrivalTime in
|
||||
p.listener().OnDataTrackMessage(p, data, &packet)
|
||||
}
|
||||
|
||||
// wraps the promoted UpTrackManager.UpdateSubscriptionPermission to also revoke
|
||||
// data track subscriptions that are no longer permitted
|
||||
func (p *ParticipantImpl) UpdateSubscriptionPermission(
|
||||
subscriptionPermission *livekit.SubscriptionPermission,
|
||||
timedVersion utils.TimedVersion,
|
||||
resolverBySid func(participantID livekit.ParticipantID) types.LocalParticipant,
|
||||
) error {
|
||||
if err := p.UpTrackManager.UpdateSubscriptionPermission(subscriptionPermission, timedVersion, resolverBySid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.maybeRevokeDataTrackSubscriptions()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) maybeRevokeDataTrackSubscriptions() {
|
||||
for _, dt := range p.UpDataTrackManager.GetPublishedDataTracks() {
|
||||
allowed := p.UpTrackManager.GetAllowedSubscribers(dt.ID())
|
||||
if allowed == nil {
|
||||
// no restrictions
|
||||
continue
|
||||
}
|
||||
|
||||
dt.RevokeDisallowedSubscribers(allowed)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) GetNextSubscribedDataTrackHandle() uint16 {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user