Fixed unclean DownTrack close when removed before bound. (#736)
* Fixed unclean DownTrack close when removed before bound. When a DownTrack is closed before it had a chance to be bound to a transceiver, we'd skip close and leave it hanging. This is unlikely in normal operations. However, it can be seen with permissions and subscription APIs. * remove remaining peerID references
This commit is contained in:
@@ -154,7 +154,6 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
||||
newWR := sfu.NewWebRTCReceiver(
|
||||
receiver,
|
||||
track,
|
||||
t.PublisherID(),
|
||||
t.params.TrackInfo,
|
||||
LoggerWithCodecMime(t.params.Logger, mime),
|
||||
twcc,
|
||||
|
||||
@@ -144,6 +144,7 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
||||
codecs,
|
||||
wr,
|
||||
t.params.BufferFactory,
|
||||
sub.Identity(),
|
||||
subscriberID,
|
||||
t.params.ReceiverConfig.PacketBufferSize,
|
||||
LoggerWithTrack(sub.GetLogger(), trackID),
|
||||
@@ -309,6 +310,10 @@ func (t *MediaTrackSubscriptions) RevokeDisallowedSubscribers(allowedSubscriberI
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.params.Logger.Infow("revoking subscription",
|
||||
"subscriber", subTrack.SubscriberIdentity(),
|
||||
"subscriberID", subTrack.SubscriberID(),
|
||||
)
|
||||
go subTrack.DownTrack().Close()
|
||||
revokedSubscriberIdentities = append(revokedSubscriberIdentities, subTrack.SubscriberIdentity())
|
||||
}
|
||||
|
||||
@@ -38,7 +38,8 @@ func HandleParticipantSignal(room types.Room, participant types.LocalParticipant
|
||||
participant.SetTrackMuted(livekit.TrackID(msg.Mute.Sid), msg.Mute.Muted, false)
|
||||
case *livekit.SignalRequest_Subscription:
|
||||
var err error
|
||||
if participant.CanSubscribe() {
|
||||
// always allow unsubscribe
|
||||
if participant.CanSubscribe() || !msg.Subscription.Subscribe {
|
||||
updateErr := room.UpdateSubscriptions(
|
||||
participant,
|
||||
livekit.StringsAsTrackIDs(msg.Subscription.TrackSids),
|
||||
|
||||
+14
-16
@@ -198,21 +198,21 @@ func (u *UpTrackManager) UpdateSubscriptionPermission(
|
||||
u.lock.Lock()
|
||||
defer u.lock.Unlock()
|
||||
|
||||
// store as is for use when migrating
|
||||
u.subscriptionPermission = subscriptionPermission
|
||||
if subscriptionPermission == nil {
|
||||
// store as is for use when migrating
|
||||
u.subscriptionPermission = subscriptionPermission
|
||||
// possible to get a nil when migrating
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := u.parseSubscriptionPermissions(subscriptionPermission, resolverBySid); err != nil {
|
||||
// do not accept permissions if parse fails
|
||||
u.subscriptionPermission = nil
|
||||
// when failed, do not override previous permissions
|
||||
return err
|
||||
}
|
||||
|
||||
// store as is for use when migrating
|
||||
u.subscriptionPermission = subscriptionPermission
|
||||
u.processPendingSubscriptions(resolverByIdentity)
|
||||
|
||||
u.maybeRevokeSubscriptions(resolverByIdentity)
|
||||
|
||||
return nil
|
||||
@@ -322,19 +322,15 @@ func (u *UpTrackManager) parseSubscriptionPermissions(
|
||||
}
|
||||
|
||||
// per participant permissions
|
||||
u.subscriberPermissions = make(map[livekit.ParticipantIdentity]*livekit.TrackPermission)
|
||||
subscriberPermissions := make(map[livekit.ParticipantIdentity]*livekit.TrackPermission)
|
||||
for _, trackPerms := range subscriptionPermission.TrackPermissions {
|
||||
subscriberIdentity := livekit.ParticipantIdentity(trackPerms.ParticipantIdentity)
|
||||
if subscriberIdentity == "" {
|
||||
if trackPerms.ParticipantSid == "" {
|
||||
u.subscriberPermissions = nil
|
||||
return ErrSubscriptionPermissionNeedsId
|
||||
}
|
||||
|
||||
var sub types.LocalParticipant
|
||||
if resolver != nil {
|
||||
sub = resolver(livekit.ParticipantID(trackPerms.ParticipantSid))
|
||||
}
|
||||
sub := resolver(livekit.ParticipantID(trackPerms.ParticipantSid))
|
||||
if sub == nil {
|
||||
u.params.Logger.Warnw("could not find subscriber for permissions update", nil, "subscriberID", trackPerms.ParticipantSid)
|
||||
continue
|
||||
@@ -353,9 +349,11 @@ func (u *UpTrackManager) parseSubscriptionPermissions(
|
||||
}
|
||||
}
|
||||
|
||||
u.subscriberPermissions[subscriberIdentity] = trackPerms
|
||||
subscriberPermissions[subscriberIdentity] = trackPerms
|
||||
}
|
||||
|
||||
u.subscriberPermissions = subscriberPermissions
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -437,11 +435,13 @@ func (u *UpTrackManager) maybeRemovePendingSubscription(trackID livekit.TrackID,
|
||||
}
|
||||
}
|
||||
|
||||
// creates subscriptions for tracks if permissions have been granted
|
||||
func (u *UpTrackManager) processPendingSubscriptions(resolver func(participantIdentity livekit.ParticipantIdentity) types.LocalParticipant) {
|
||||
updatedPendingSubscriptions := make(map[livekit.TrackID][]livekit.ParticipantIdentity)
|
||||
for trackID, pending := range u.pendingSubscriptions {
|
||||
track := u.getPublishedTrack(trackID)
|
||||
if track == nil {
|
||||
// published track is gone
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -488,11 +488,9 @@ func (u *UpTrackManager) maybeRevokeSubscriptions(resolver func(participantIdent
|
||||
|
||||
revokedSubscribers := track.RevokeDisallowedSubscribers(allowed)
|
||||
for _, subIdentity := range revokedSubscribers {
|
||||
var sub types.LocalParticipant
|
||||
if resolver != nil {
|
||||
sub = resolver(subIdentity)
|
||||
}
|
||||
sub := resolver(subIdentity)
|
||||
if sub == nil {
|
||||
// participant may have disconnected
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -35,12 +35,12 @@ func PackDataTrackLabel(participantID livekit.ParticipantID, trackID livekit.Tra
|
||||
return string(participantID) + trackIdSeparator + string(trackID) + trackIdSeparator + label
|
||||
}
|
||||
|
||||
func UnpackDataTrackLabel(packed string) (peerID livekit.ParticipantID, trackID livekit.TrackID, label string) {
|
||||
func UnpackDataTrackLabel(packed string) (participantID livekit.ParticipantID, trackID livekit.TrackID, label string) {
|
||||
parts := strings.Split(packed, trackIdSeparator)
|
||||
if len(parts) != 3 {
|
||||
return "", livekit.TrackID(packed), ""
|
||||
}
|
||||
peerID = livekit.ParticipantID(parts[0])
|
||||
participantID = livekit.ParticipantID(parts[0])
|
||||
trackID = livekit.TrackID(parts[1])
|
||||
label = parts[2]
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user