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.
This commit is contained in:
Leonard Kim 2019-08-12 12:25:06 -07:00 committed by virtuacoplenny
parent 7af081ea99
commit c0a8a386a5
1 changed files with 6 additions and 4 deletions

View File

@ -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