From c0a8a386a5ac1b688881f18fa035302f4f86356b Mon Sep 17 00:00:00 2001 From: Leonard Kim Date: Mon, 12 Aug 2019 12:25:06 -0700 Subject: [PATCH] fix(pinning): debounce autopin subscriber The store's remote tracks get cleared and re-added when switching in and out of p2p, which can cause pinning thrashing. Avoid that with a debounce. --- react/features/video-layout/subscriber.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/react/features/video-layout/subscriber.js b/react/features/video-layout/subscriber.js index 31acd333e..9eff5138f 100644 --- a/react/features/video-layout/subscriber.js +++ b/react/features/video-layout/subscriber.js @@ -1,5 +1,7 @@ // @flow +import debounce from 'lodash/debounce'; + import { VIDEO_QUALITY_LEVELS, setMaxReceiverVideoQuality @@ -44,11 +46,12 @@ StateListenerRegistry.register( /** * For auto-pin mode, listen for changes to the known media tracks and look - * for updates to screen shares. + * for updates to screen shares. The listener is debounced to avoid state + * thrashing that might occur, especially when switching in or out of p2p. */ StateListenerRegistry.register( /* selector */ state => state['features/base/tracks'], - /* listener */ (tracks, store) => { + /* listener */ debounce((tracks, store) => { if (!AUTO_PIN_LATEST_SCREEN_SHARE) { return; } @@ -88,8 +91,7 @@ StateListenerRegistry.register( _updateAutoPinnedParticipant(store); } - } -); + }, 100)); /** * Private helper to automatically pin the latest screen share stream or unpin