feat: SubscriptionManager to consolidate subscription handling (#1317)
Added a new manager to handle all subscription needs. Implemented using reconciler pattern. The goals are: improve subscription resilience by separating desired state and current state reduce complexity of synchronous processing better detect failures with the ability to trigger full reconnect
This commit is contained in:
@@ -26,37 +26,17 @@ func HandleParticipantSignal(room types.Room, participant types.LocalParticipant
|
||||
case *livekit.SignalRequest_Mute:
|
||||
participant.SetTrackMuted(livekit.TrackID(msg.Mute.Sid), msg.Mute.Muted, false)
|
||||
case *livekit.SignalRequest_Subscription:
|
||||
var err error
|
||||
// always allow unsubscribe
|
||||
if participant.CanSubscribe() || !msg.Subscription.Subscribe {
|
||||
updateErr := room.UpdateSubscriptions(
|
||||
participant,
|
||||
livekit.StringsAsTrackIDs(msg.Subscription.TrackSids),
|
||||
msg.Subscription.ParticipantTracks,
|
||||
msg.Subscription.Subscribe,
|
||||
)
|
||||
if updateErr != nil {
|
||||
err = updateErr
|
||||
}
|
||||
} else {
|
||||
err = ErrCannotSubscribe
|
||||
}
|
||||
if err != nil {
|
||||
pLogger.Warnw("could not update subscription", err,
|
||||
"trackID", msg.Subscription.TrackSids,
|
||||
"subscribe", msg.Subscription.Subscribe)
|
||||
} else {
|
||||
pLogger.Infow("updated subscription",
|
||||
"trackID", msg.Subscription.TrackSids,
|
||||
"subscribe", msg.Subscription.Subscribe)
|
||||
}
|
||||
// allow participant to indicate their interest in the subscription
|
||||
// permission check happens later in SubscriptionManager
|
||||
room.UpdateSubscriptions(
|
||||
participant,
|
||||
livekit.StringsAsTrackIDs(msg.Subscription.TrackSids),
|
||||
msg.Subscription.ParticipantTracks,
|
||||
msg.Subscription.Subscribe,
|
||||
)
|
||||
case *livekit.SignalRequest_TrackSetting:
|
||||
for _, sid := range livekit.StringsAsTrackIDs(msg.TrackSetting.TrackSids) {
|
||||
err := participant.UpdateSubscribedTrackSettings(sid, msg.TrackSetting)
|
||||
if err != nil {
|
||||
pLogger.Errorw("failed to update subscribed track settings", err, "trackID", sid)
|
||||
continue
|
||||
}
|
||||
participant.UpdateSubscribedTrackSettings(sid, msg.TrackSetting)
|
||||
}
|
||||
case *livekit.SignalRequest_Leave:
|
||||
pLogger.Infow("client leaving room")
|
||||
|
||||
Reference in New Issue
Block a user