mirror of
https://github.com/livekit/livekit.git
synced 2026-04-04 10:25:39 +00:00
Introduce a pending close map and fire onNoSubscribers only when there are not subscribed and no pending close. There are a couple of paths for down track close - RemoveSubscriber - RemoveAllSubscriber We remove the subscriber from `subscribedTracks` in these. This is because `AddSubscriber` checks for existing subscription. If there is a remove followed by an add, the add should not think there is an existing susbcription if there is a delay in down track close callback. But, down track close is also called directly from places like participant close. So, have to clean up both subscribedTrack and pendingClose when the down track close fires. Call onNoSubscribers only when both are empty. This will allow relay up track to stop properly when all susbcribers have left.