Skip to content

Commit

Permalink
Merge pull request #2552 from robintown/spotlight-left
Browse files Browse the repository at this point in the history
Don't keep someone in the spotlight if they've left the call
  • Loading branch information
robintown authored Aug 9, 2024
2 parents 29df87d + ed99af0 commit 64e7047
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/state/CallViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,21 +424,22 @@ export class CallViewModel extends ViewModel {
),
scan<(readonly [UserMedia, boolean])[], UserMedia, null>(
(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:
// If the previous speaker (not the local user) is still speaking,
// stick with them rather than switching eagerly to someone else
return (
mediaItems.find(([m, s]) => m === stickyPrev && s)?.[0] ??
// Otherwise, select any remote user who is speaking
mediaItems.find(([m, s]) => !m.vm.local && s)?.[0] ??
// Otherwise, stick with the person who was last speaking
stickyPrev ??
// Otherwise, spotlight an arbitrary remote user
mediaItems.find(([m]) => !m.vm.local)?.[0] ??
// Otherwise, spotlight the local user
mediaItems.find(([m]) => m.vm.local)![0]
);
// If the previous speaker is still speaking, stick with them rather
// than switching eagerly to someone else
return stickySpeaking
? stickyMedia!
: // Otherwise, select any remote user who is speaking
(mediaItems.find(([m, s]) => !m.vm.local && s)?.[0] ??
// Otherwise, stick with the person who was last speaking
stickyMedia ??
// Otherwise, spotlight an arbitrary remote user
mediaItems.find(([m]) => !m.vm.local)?.[0] ??
// Otherwise, spotlight the local user
mediaItems.find(([m]) => m.vm.local)![0]);
},
null,
),
Expand Down

0 comments on commit 64e7047

Please sign in to comment.