Use if statement instead of ternary for readability in spotlight and pip logic

This commit is contained in:
Hugh Nimmo-Smith
2024-12-02 14:35:33 +00:00
parent 33f398ddcf
commit 7fdcbb3292

View File

@@ -632,49 +632,59 @@ export class CallViewModel extends ViewModel {
private readonly spotlight: Observable<MediaViewModel[]> = private readonly spotlight: Observable<MediaViewModel[]> =
this.screenShares.pipe( this.screenShares.pipe(
switchMap((screenShares) => switchMap((screenShares) => {
screenShares.length > 0 if (screenShares.length > 0) {
? of(screenShares.map((m) => m.vm)) return of(screenShares.map((m) => m.vm));
: this.spotlightSpeaker.pipe( }
map((speaker) => (speaker ? [speaker] : [])),
), return this.spotlightSpeaker.pipe(
), map((speaker) => (speaker ? [speaker] : [])),
);
}),
this.scope.state(), this.scope.state(),
); );
private readonly pip: Observable<UserMediaViewModel | null> = private readonly pip: Observable<UserMediaViewModel | null> =
this.screenShares.pipe( this.screenShares.pipe(
switchMap((screenShares) => switchMap((screenShares) => {
screenShares.length > 0 if (screenShares.length > 0) {
? this.spotlightSpeaker return this.spotlightSpeaker;
: this.spotlightSpeaker.pipe( }
switchMap((speaker) =>
speaker return this.spotlightSpeaker.pipe(
? speaker.local switchMap((speaker) => {
? of(null) if (!speaker || speaker.local) {
: this.mediaItems.pipe( return of(null);
switchMap((mediaItems) => { }
const localUserMedia = mediaItems.find(
(m) => m.vm instanceof LocalUserMediaViewModel, return this.mediaItems.pipe(
) as UserMedia | undefined; switchMap((mediaItems) => {
return ( const localUserMedia = mediaItems.find(
( (m) => m.vm instanceof LocalUserMediaViewModel,
localUserMedia?.vm as LocalUserMediaViewModel ) as UserMedia | undefined;
).alwaysShow.pipe(
map( const localUserMediaViewModel = localUserMedia?.vm as
(alwaysShow) => | LocalUserMediaViewModel
(alwaysShow | undefined;
? localUserMedia?.vm
: undefined) ?? null, if (!localUserMediaViewModel) {
), return of(null);
) ?? of(null) }
);
}), return localUserMediaViewModel.alwaysShow.pipe(
) map((alwaysShow) => {
: of(null), if (alwaysShow) {
), return localUserMediaViewModel;
), }
),
return null;
}),
);
}),
);
}),
);
}),
this.scope.state(), this.scope.state(),
); );