Use fewer ML-style variable names

This commit is contained in:
Robin
2024-07-17 15:37:55 -04:00
parent a59875dab5
commit 2bc56dbff2

View File

@@ -386,7 +386,7 @@ export class CallViewModel extends ViewModel {
}, },
new Map<string, MediaItem>(), new Map<string, MediaItem>(),
), ),
map((ms) => [...ms.values()]), map((mediaItems) => [...mediaItems.values()]),
finalizeValue((ts) => { finalizeValue((ts) => {
for (const t of ts) t.destroy(); for (const t of ts) t.destroy();
}), }),
@@ -394,35 +394,41 @@ export class CallViewModel extends ViewModel {
); );
private readonly userMedia: Observable<UserMedia[]> = this.mediaItems.pipe( private readonly userMedia: Observable<UserMedia[]> = this.mediaItems.pipe(
map((ms) => ms.filter((m): m is UserMedia => m instanceof UserMedia)), map((mediaItems) =>
mediaItems.filter((m): m is UserMedia => m instanceof UserMedia),
),
); );
private readonly screenShares: Observable<ScreenShare[]> = private readonly screenShares: Observable<ScreenShare[]> =
this.mediaItems.pipe( this.mediaItems.pipe(
map((ms) => ms.filter((m): m is ScreenShare => m instanceof ScreenShare)), map((mediaItems) =>
mediaItems.filter((m): m is ScreenShare => m instanceof ScreenShare),
),
); );
private readonly spotlightSpeaker: Observable<UserMedia | null> = private readonly spotlightSpeaker: Observable<UserMedia | null> =
this.userMedia.pipe( this.userMedia.pipe(
switchMap((ms) => switchMap((mediaItems) =>
ms.length === 0 mediaItems.length === 0
? of([]) ? of([])
: combineLatest( : combineLatest(
ms.map((m) => m.vm.speaking.pipe(map((s) => [m, s] as const))), mediaItems.map((m) =>
m.vm.speaking.pipe(map((s) => [m, s] as const)),
),
), ),
), ),
scan<(readonly [UserMedia, boolean])[], UserMedia | null, null>( scan<(readonly [UserMedia, boolean])[], UserMedia | null, null>(
(prev, ms) => (prev, mediaItems) =>
// Decide who to spotlight: // Decide who to spotlight:
// If the previous speaker is still speaking, stick with them rather // If the previous speaker is still speaking, stick with them rather
// than switching eagerly to someone else // than switching eagerly to someone else
ms.find(([m, s]) => m === prev && s)?.[0] ?? mediaItems.find(([m, s]) => m === prev && s)?.[0] ??
// Otherwise, select anyone who is speaking // Otherwise, select anyone who is speaking
ms.find(([, s]) => s)?.[0] ?? mediaItems.find(([, s]) => s)?.[0] ??
// Otherwise, stick with the person who was last speaking // Otherwise, stick with the person who was last speaking
prev ?? prev ??
// Otherwise, spotlight the local user // Otherwise, spotlight the local user
ms.find(([m]) => m.vm.local)?.[0] ?? mediaItems.find(([m]) => m.vm.local)?.[0] ??
null, null,
null, null,
), ),
@@ -431,8 +437,8 @@ export class CallViewModel extends ViewModel {
); );
private readonly grid: Observable<UserMediaViewModel[]> = this.userMedia.pipe( private readonly grid: Observable<UserMediaViewModel[]> = this.userMedia.pipe(
switchMap((ms) => { switchMap((mediaItems) => {
const bins = ms.map((m) => const bins = mediaItems.map((m) =>
combineLatest( combineLatest(
[ [
m.speaker, m.speaker,