From 5009f1fe1b4a08f5df361b6d465cd9653e0c67df Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 7 Nov 2024 16:53:25 +0000 Subject: [PATCH] Assertions for one-on-one view --- src/state/CallViewModel.ts | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/state/CallViewModel.ts b/src/state/CallViewModel.ts index 080adbf4..0db03af1 100644 --- a/src/state/CallViewModel.ts +++ b/src/state/CallViewModel.ts @@ -802,6 +802,7 @@ export class CallViewModel extends ViewModel { // There might not be a remote tile if only the local user is in the call // and they're using the duplicate tiles option grid.some((vm) => !vm.local) && + grid.some((vm) => vm.local) && screenShares.length === 0, ); @@ -816,12 +817,14 @@ export class CallViewModel extends ViewModel { }), ); - private readonly spotlightLandscapeLayout: Observable = - combineLatest([this.grid, this.spotlight], (grid, spotlight) => ({ + private spotlightLandscapeLayout: Observable = combineLatest( + [this.grid, this.spotlight], + (grid, spotlight) => ({ type: "spotlight-landscape", spotlight, grid, - })); + }), + ); private readonly spotlightPortraitLayout: Observable = combineLatest([this.grid, this.spotlight], (grid, spotlight) => ({ @@ -839,11 +842,24 @@ export class CallViewModel extends ViewModel { private readonly oneOnOneLayout: Observable = this.mediaItems.pipe( - map((grid) => ({ - type: "one-on-one", - local: grid.find((vm) => vm.vm.local)!.vm as LocalUserMediaViewModel, - remote: grid.find((vm) => !vm.vm.local)!.vm as RemoteUserMediaViewModel, - })), + map((grid) => { + const local = grid.find((vm) => vm.vm.local)?.vm as + | LocalUserMediaViewModel + | undefined; + const remote = grid.find((vm) => !vm.vm.local)?.vm as + | RemoteUserMediaViewModel + | undefined; + if (!local || !remote) { + throw new Error( + "Invalid state: there should be local and remote media for one-on-one layout", + ); + } + return { + type: "one-on-one", + local, + remote, + }; + }), ); private readonly pipLayout: Observable = this.spotlight.pipe(