Merge pull request #2552 from robintown/spotlight-left

Don't keep someone in the spotlight if they've left the call
This commit is contained in:
Robin
2024-08-09 13:40:13 -04:00
committed by GitHub

View File

@@ -424,21 +424,22 @@ export class CallViewModel extends ViewModel {
), ),
scan<(readonly [UserMedia, boolean])[], UserMedia, null>( scan<(readonly [UserMedia, boolean])[], UserMedia, null>(
(prev, mediaItems) => { (prev, mediaItems) => {
const stickyPrev = prev === null || prev.vm.local ? null : prev; // Only remote users that are still in the call should be sticky
const [stickyMedia, stickySpeaking] =
(!prev?.vm.local && mediaItems.find(([m]) => m === prev)) || [];
// Decide who to spotlight: // Decide who to spotlight:
// If the previous speaker (not the local user) is still speaking, // If the previous speaker is still speaking, stick with them rather
// stick with them rather than switching eagerly to someone else // than switching eagerly to someone else
return ( return stickySpeaking
mediaItems.find(([m, s]) => m === stickyPrev && s)?.[0] ?? ? stickyMedia!
// Otherwise, select any remote user who is speaking : // Otherwise, select any remote user who is speaking
mediaItems.find(([m, s]) => !m.vm.local && s)?.[0] ?? (mediaItems.find(([m, s]) => !m.vm.local && s)?.[0] ??
// Otherwise, stick with the person who was last speaking // Otherwise, stick with the person who was last speaking
stickyPrev ?? stickyMedia ??
// Otherwise, spotlight an arbitrary remote user // Otherwise, spotlight an arbitrary remote user
mediaItems.find(([m]) => !m.vm.local)?.[0] ?? mediaItems.find(([m]) => !m.vm.local)?.[0] ??
// Otherwise, spotlight the local user // Otherwise, spotlight the local user
mediaItems.find(([m]) => m.vm.local)![0] mediaItems.find(([m]) => m.vm.local)![0]);
);
}, },
null, null,
), ),