mirror of
https://github.com/livekit/livekit.git
synced 2026-10-22 10:42:29 +00:00
* Close subscriptions promptly Two things: ----------- 1. Because the desired is not changed, the notifiers are not notified that the subscription is not observing any more. So, that holds a refernce to the subscription manager. Address the above by setting `setDesired` to false on all subscriptions when subscription manager closes. That will remove observer from the notifiers. 2. When subscription manager is closed, the down track close is invoked which flows back (with onClose callback of downtrack) to subscription manager "handleSubscribedTrackClose". That callback handler sets the subscribed track to nil for that subscription. A couple of scenarios here a. Without the above change, desired could have been true and it would have looked that the track needs to try subscription again because `needsSubscribe == true` (desired == true && subscribedTrack == nil) b. Even with the change above, there is a new condition of `desired == false && subscribedTrack == nil` and there was no handler for that condition in the reconciler. Address this by adding a `needsCleanup` function and delete subscription from the map. Note that the reconciler may not be running to execute this action as subscription manager would have closed the `closeCh`, but doing the code in the interest of proper clean up. * clean up