Respond to suggestions from code review
This commit is contained in:
@@ -126,9 +126,9 @@ export type GridMode = "grid" | "spotlight";
|
|||||||
export type WindowMode = "normal" | "full screen" | "pip";
|
export type WindowMode = "normal" | "full screen" | "pip";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorting bins defining the order in which media tiles appear in the grid.
|
* Sorting bins defining the order in which media tiles appear in the layout.
|
||||||
*/
|
*/
|
||||||
enum GridBin {
|
enum SortingBin {
|
||||||
SelfStart,
|
SelfStart,
|
||||||
Presenters,
|
Presenters,
|
||||||
Speakers,
|
Speakers,
|
||||||
@@ -235,7 +235,8 @@ export class CallViewModel extends ViewModel {
|
|||||||
|
|
||||||
// Lists of participants to "hold" on display, even if LiveKit claims that
|
// Lists of participants to "hold" on display, even if LiveKit claims that
|
||||||
// they've left
|
// they've left
|
||||||
private readonly remoteParticipantHolds = zip(
|
private readonly remoteParticipantHolds: Observable<RemoteParticipant[][]> =
|
||||||
|
zip(
|
||||||
this.connectionState,
|
this.connectionState,
|
||||||
this.rawRemoteParticipants.pipe(sample(this.connectionState)),
|
this.rawRemoteParticipants.pipe(sample(this.connectionState)),
|
||||||
(s, ps) => {
|
(s, ps) => {
|
||||||
@@ -282,7 +283,8 @@ export class CallViewModel extends ViewModel {
|
|||||||
startWith([]),
|
startWith([]),
|
||||||
);
|
);
|
||||||
|
|
||||||
private readonly remoteParticipants = combineLatest(
|
private readonly remoteParticipants: Observable<RemoteParticipant[]> =
|
||||||
|
combineLatest(
|
||||||
[this.rawRemoteParticipants, this.remoteParticipantHolds],
|
[this.rawRemoteParticipants, this.remoteParticipantHolds],
|
||||||
(raw, holds) => {
|
(raw, holds) => {
|
||||||
const result = [...raw];
|
const result = [...raw];
|
||||||
@@ -302,7 +304,7 @@ export class CallViewModel extends ViewModel {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
private readonly mediaItems = state(
|
private readonly mediaItems: StateObservable<MediaItem[]> = state(
|
||||||
combineLatest([
|
combineLatest([
|
||||||
this.remoteParticipants,
|
this.remoteParticipants,
|
||||||
observeParticipantMedia(this.livekitRoom.localParticipant),
|
observeParticipantMedia(this.livekitRoom.localParticipant),
|
||||||
@@ -362,15 +364,17 @@ export class CallViewModel extends ViewModel {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
private readonly userMedia = this.mediaItems.pipe(
|
private readonly userMedia: Observable<UserMedia[]> = this.mediaItems.pipe(
|
||||||
map((ms) => ms.filter((m): m is UserMedia => m instanceof UserMedia)),
|
map((ms) => ms.filter((m): m is UserMedia => m instanceof UserMedia)),
|
||||||
);
|
);
|
||||||
|
|
||||||
private readonly screenShares = this.mediaItems.pipe(
|
private readonly screenShares: Observable<ScreenShare[]> =
|
||||||
|
this.mediaItems.pipe(
|
||||||
map((ms) => ms.filter((m): m is ScreenShare => m instanceof ScreenShare)),
|
map((ms) => ms.filter((m): m is ScreenShare => m instanceof ScreenShare)),
|
||||||
);
|
);
|
||||||
|
|
||||||
private readonly spotlightSpeaker = this.userMedia.pipe(
|
private readonly spotlightSpeaker: Observable<UserMedia | null> =
|
||||||
|
this.userMedia.pipe(
|
||||||
switchMap((ms) =>
|
switchMap((ms) =>
|
||||||
ms.length === 0
|
ms.length === 0
|
||||||
? of([])
|
? of([])
|
||||||
@@ -397,28 +401,22 @@ export class CallViewModel extends ViewModel {
|
|||||||
throttleTime(800, undefined, { leading: true, trailing: true }),
|
throttleTime(800, undefined, { leading: true, trailing: true }),
|
||||||
);
|
);
|
||||||
|
|
||||||
private readonly grid = this.userMedia.pipe(
|
private readonly grid: Observable<UserMediaViewModel[]> = this.userMedia.pipe(
|
||||||
switchMap((ms) => {
|
switchMap((ms) => {
|
||||||
const bins = ms.map((m) =>
|
const bins = ms.map((m) =>
|
||||||
combineLatest(
|
combineLatest(
|
||||||
[m.speaker, m.presenter, m.vm.audioEnabled, m.vm.videoEnabled],
|
[m.speaker, m.presenter, m.vm.audioEnabled, m.vm.videoEnabled],
|
||||||
(speaker, presenter, audio, video) =>
|
(speaker, presenter, audio, video) => {
|
||||||
[
|
let bin: SortingBin;
|
||||||
m,
|
if (m.vm.local) bin = SortingBin.SelfStart;
|
||||||
m.vm.local
|
else if (presenter) bin = SortingBin.Presenters;
|
||||||
? GridBin.SelfStart
|
else if (speaker) bin = SortingBin.Speakers;
|
||||||
: presenter
|
else if (video)
|
||||||
? GridBin.Presenters
|
bin = audio ? SortingBin.VideoAndAudio : SortingBin.Video;
|
||||||
: speaker
|
else bin = audio ? SortingBin.Audio : SortingBin.NoMedia;
|
||||||
? GridBin.Speakers
|
|
||||||
: video
|
return [m, bin] as const;
|
||||||
? audio
|
},
|
||||||
? GridBin.VideoAndAudio
|
|
||||||
: GridBin.Video
|
|
||||||
: audio
|
|
||||||
? GridBin.Audio
|
|
||||||
: GridBin.NoMedia,
|
|
||||||
] as const,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
// Sort the media by bin order and generate a tile for each one
|
// Sort the media by bin order and generate a tile for each one
|
||||||
@@ -430,7 +428,7 @@ export class CallViewModel extends ViewModel {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
private readonly spotlight = combineLatest(
|
private readonly spotlight: Observable<MediaViewModel[]> = combineLatest(
|
||||||
[this.screenShares, this.spotlightSpeaker],
|
[this.screenShares, this.spotlightSpeaker],
|
||||||
(screenShares, spotlightSpeaker): MediaViewModel[] =>
|
(screenShares, spotlightSpeaker): MediaViewModel[] =>
|
||||||
screenShares.length > 0
|
screenShares.length > 0
|
||||||
@@ -440,6 +438,10 @@ export class CallViewModel extends ViewModel {
|
|||||||
: [spotlightSpeaker.vm],
|
: [spotlightSpeaker.vm],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: Make this react to changes in window dimensions and screen
|
||||||
|
// orientation
|
||||||
|
private readonly windowMode = of<WindowMode>("normal");
|
||||||
|
|
||||||
private readonly _gridMode = new BehaviorSubject<GridMode>("grid");
|
private readonly _gridMode = new BehaviorSubject<GridMode>("grid");
|
||||||
/**
|
/**
|
||||||
* The layout mode of the media tile grid.
|
* The layout mode of the media tile grid.
|
||||||
@@ -450,10 +452,6 @@ export class CallViewModel extends ViewModel {
|
|||||||
this._gridMode.next(value);
|
this._gridMode.next(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make this react to changes in window dimensions and screen
|
|
||||||
// orientation
|
|
||||||
private readonly windowMode = of<WindowMode>("normal");
|
|
||||||
|
|
||||||
public readonly layout: StateObservable<Layout> = state(
|
public readonly layout: StateObservable<Layout> = state(
|
||||||
combineLatest([this._gridMode, this.windowMode], (gridMode, windowMode) => {
|
combineLatest([this._gridMode, this.windowMode], (gridMode, windowMode) => {
|
||||||
switch (windowMode) {
|
switch (windowMode) {
|
||||||
@@ -492,7 +490,8 @@ export class CallViewModel extends ViewModel {
|
|||||||
*/
|
*/
|
||||||
// TODO: Get rid of this field, replacing it with the 'layout' field above
|
// TODO: Get rid of this field, replacing it with the 'layout' field above
|
||||||
// which keeps more details of the layout order internal to the view model
|
// which keeps more details of the layout order internal to the view model
|
||||||
public readonly tiles = state(
|
public readonly tiles: StateObservable<TileDescriptor<MediaViewModel>[]> =
|
||||||
|
state(
|
||||||
combineLatest([
|
combineLatest([
|
||||||
this.remoteParticipants,
|
this.remoteParticipants,
|
||||||
observeParticipantMedia(this.livekitRoom.localParticipant),
|
observeParticipantMedia(this.livekitRoom.localParticipant),
|
||||||
|
|||||||
Reference in New Issue
Block a user