From 33f398ddcf09f2b183abd43671a56a17098aca1b Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 2 Dec 2024 14:10:31 +0000 Subject: [PATCH] Refactor spotlightAndPip into spotlight and pip --- src/state/CallViewModel.ts | 40 ++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/state/CallViewModel.ts b/src/state/CallViewModel.ts index eb81304a..89fa3950 100644 --- a/src/state/CallViewModel.ts +++ b/src/state/CallViewModel.ts @@ -630,21 +630,24 @@ export class CallViewModel extends ViewModel { }), ); - private readonly spotlightAndPip: Observable<{ - spotlight: Observable; - pip: Observable; - }> = this.screenShares.pipe( - map((screenShares) => - screenShares.length > 0 - ? { - spotlight: of(screenShares.map((m) => m.vm)), - pip: this.spotlightSpeaker, - } - : { - spotlight: this.spotlightSpeaker.pipe( + private readonly spotlight: Observable = + this.screenShares.pipe( + switchMap((screenShares) => + screenShares.length > 0 + ? of(screenShares.map((m) => m.vm)) + : this.spotlightSpeaker.pipe( map((speaker) => (speaker ? [speaker] : [])), ), - pip: this.spotlightSpeaker.pipe( + ), + this.scope.state(), + ); + + private readonly pip: Observable = + this.screenShares.pipe( + switchMap((screenShares) => + screenShares.length > 0 + ? this.spotlightSpeaker + : this.spotlightSpeaker.pipe( switchMap((speaker) => speaker ? speaker.local @@ -671,13 +674,7 @@ export class CallViewModel extends ViewModel { : of(null), ), ), - }, - ), - ); - - private readonly spotlight: Observable = - this.spotlightAndPip.pipe( - switchMap(({ spotlight }) => spotlight), + ), this.scope.state(), ); @@ -689,9 +686,6 @@ export class CallViewModel extends ViewModel { distinctUntilChanged(), ); - private readonly pip: Observable = - this.spotlightAndPip.pipe(switchMap(({ pip }) => pip)); - private readonly pipEnabled: Observable = setPipEnabled.pipe( startWith(false), );