Skip to content

Commit

Permalink
Merge pull request #2752 from robintown/one-on-one-crash
Browse files Browse the repository at this point in the history
Make one-on-one layout less prone to crashing
  • Loading branch information
robintown authored Nov 11, 2024
2 parents b22d2db + 50d380c commit a6efdf0
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions src/state/CallViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,16 +672,6 @@ export class CallViewModel extends ViewModel {
this.gridModeUserSelection.next(value);
}

private readonly oneOnOne: Observable<boolean> = combineLatest(
[this.grid, this.screenShares],
(grid, screenShares) =>
grid.length == 2 &&
// 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) &&
screenShares.length === 0,
);

private readonly gridLayout: Observable<LayoutMedia> = combineLatest(
[this.grid, this.spotlight],
(grid, spotlight) => ({
Expand Down Expand Up @@ -714,13 +704,22 @@ export class CallViewModel extends ViewModel {
pip: pip ?? undefined,
}));

private readonly oneOnOneLayout: Observable<LayoutMedia> =
private readonly oneOnOneLayout: Observable<LayoutMedia | null> =
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((mediaItems) => {
if (mediaItems.length !== 2) return null;
const local = mediaItems.find((vm) => vm.vm.local)!
.vm as LocalUserMediaViewModel;
const remote = mediaItems.find((vm) => !vm.vm.local)?.vm as
| RemoteUserMediaViewModel
| undefined;
// There might not be a remote tile if there are screen shares, or if
// only the local user is in the call and they're using the duplicate
// tiles option
if (remote === undefined) return null;

return { type: "one-on-one", local, remote };
}),
);

private readonly pipLayout: Observable<LayoutMedia> = this.spotlight.pipe(
Expand All @@ -738,9 +737,9 @@ export class CallViewModel extends ViewModel {
switchMap((gridMode) => {
switch (gridMode) {
case "grid":
return this.oneOnOne.pipe(
return this.oneOnOneLayout.pipe(
switchMap((oneOnOne) =>
oneOnOne ? this.oneOnOneLayout : this.gridLayout,
oneOnOne === null ? this.gridLayout : of(oneOnOne),
),
);
case "spotlight":
Expand All @@ -755,20 +754,20 @@ export class CallViewModel extends ViewModel {
}),
);
case "narrow":
return this.oneOnOne.pipe(
return this.oneOnOneLayout.pipe(
switchMap((oneOnOne) =>
oneOnOne
? // The expanded spotlight layout makes for a better one-on-one
// experience in narrow windows
this.spotlightExpandedLayout
: combineLatest(
oneOnOne === null
? combineLatest(
[this.grid, this.spotlight],
(grid, spotlight) =>
grid.length > smallMobileCallThreshold ||
spotlight.some((vm) => vm instanceof ScreenShareViewModel)
? this.spotlightPortraitLayout
: this.gridLayout,
).pipe(switchAll()),
).pipe(switchAll())
: // The expanded spotlight layout makes for a better one-on-one
// experience in narrow windows
this.spotlightExpandedLayout,
),
);
case "flat":
Expand Down

0 comments on commit a6efdf0

Please sign in to comment.