diff --git a/pkg/rtc/supervisor/publication_monitor.go b/pkg/rtc/supervisor/publication_monitor.go index 557323a2..13a7248d 100644 --- a/pkg/rtc/supervisor/publication_monitor.go +++ b/pkg/rtc/supervisor/publication_monitor.go @@ -139,23 +139,20 @@ func (p *PublicationMonitor) IsIdle() bool { } func (p *PublicationMonitor) update() { - var pub *publish - if p.desiredPublishes.Len() > 0 { - pub = p.desiredPublishes.PopFront().(*publish) - } + for { + var pub *publish + if p.desiredPublishes.Len() > 0 { + pub = p.desiredPublishes.PopFront().(*publish) + } - if pub == nil { - return - } + if pub == nil { + return + } - switch { - case pub.isStart && p.publishedTrack != nil: - return - case !pub.isStart && p.publishedTrack == nil: - return - default: - // put it back as the condition is not satisfied - p.desiredPublishes.PushFront(pub) - return + if (pub.isStart && p.publishedTrack == nil) || (!pub.isStart && p.publishedTrack != nil) { + // put it back as the condition is not satisfied + p.desiredPublishes.PushFront(pub) + return + } } } diff --git a/pkg/rtc/supervisor/subscription_monitor.go b/pkg/rtc/supervisor/subscription_monitor.go index 0187abe5..6a4912b1 100644 --- a/pkg/rtc/supervisor/subscription_monitor.go +++ b/pkg/rtc/supervisor/subscription_monitor.go @@ -117,23 +117,20 @@ func (s *SubscriptionMonitor) IsIdle() bool { } func (s *SubscriptionMonitor) update() { - var tx *transition - if s.desiredTransitions.Len() > 0 { - tx = s.desiredTransitions.PopFront().(*transition) - } + for { + var tx *transition + if s.desiredTransitions.Len() > 0 { + tx = s.desiredTransitions.PopFront().(*transition) + } - if tx == nil { - return - } + if tx == nil { + return + } - switch { - case tx.isSubscribed && s.subscribedTrack != nil: - return - case !tx.isSubscribed && s.subscribedTrack == nil: - return - default: - // put it back as the condition is not satisfied - s.desiredTransitions.PushFront(tx) - return + if (tx.isSubscribed && s.subscribedTrack == nil) || (!tx.isSubscribed && s.subscribedTrack != nil) { + // put it back as the condition is not satisfied + s.desiredTransitions.PushFront(tx) + return + } } }