Skip to content

Commit ac47bf4

Browse files
committed
Make the video behavior less confusing
There's no reason to allow it to take on placeholder values. It should be defined when the media has a published video track and undefined when not.
1 parent fcff734 commit ac47bf4

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

src/state/CallViewModel/localMember/Publisher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export class Publisher {
362362
const track$ = scope.behavior(
363363
observeTrackReference$(room.localParticipant, Track.Source.Camera).pipe(
364364
map((trackRef) => {
365-
const track = trackRef?.publication?.track;
365+
const track = trackRef?.publication.track;
366366
return track instanceof LocalVideoTrack ? track : null;
367367
}),
368368
),

src/state/MediaViewModel.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Please see LICENSE in the repository root for full details.
77

88
import {
99
type AudioSource,
10-
type TrackReferenceOrPlaceholder,
1110
type VideoSource,
11+
type TrackReference,
1212
observeParticipantEvents,
1313
observeParticipantMedia,
1414
roomEventSelector,
@@ -33,7 +33,6 @@ import {
3333
type Observable,
3434
Subject,
3535
combineLatest,
36-
distinctUntilKeyChanged,
3736
filter,
3837
fromEvent,
3938
interval,
@@ -60,14 +59,11 @@ import { type ObservableScope } from "./ObservableScope";
6059
export function observeTrackReference$(
6160
participant: Participant,
6261
source: Track.Source,
63-
): Observable<TrackReferenceOrPlaceholder> {
62+
): Observable<TrackReference | undefined> {
6463
return observeParticipantMedia(participant).pipe(
65-
map(() => ({
66-
participant: participant,
67-
publication: participant.getTrackPublication(source),
68-
source,
69-
})),
70-
distinctUntilKeyChanged("publication"),
64+
map(() => participant.getTrackPublication(source)),
65+
distinctUntilChanged(),
66+
map((publication) => publication && { participant, publication, source }),
7167
);
7268
}
7369

@@ -226,7 +222,7 @@ abstract class BaseMediaViewModel {
226222
/**
227223
* The LiveKit video track for this media.
228224
*/
229-
public readonly video$: Behavior<TrackReferenceOrPlaceholder | null>;
225+
public readonly video$: Behavior<TrackReference | undefined>;
230226
/**
231227
* Whether there should be a warning that this media is unencrypted.
232228
*/
@@ -241,10 +237,12 @@ abstract class BaseMediaViewModel {
241237

242238
private observeTrackReference$(
243239
source: Track.Source,
244-
): Behavior<TrackReferenceOrPlaceholder | null> {
240+
): Behavior<TrackReference | undefined> {
245241
return this.scope.behavior(
246242
this.participant$.pipe(
247-
switchMap((p) => (!p ? of(null) : observeTrackReference$(p, source))),
243+
switchMap((p) =>
244+
!p ? of(undefined) : observeTrackReference$(p, source),
245+
),
248246
),
249247
);
250248
}
@@ -281,8 +279,8 @@ abstract class BaseMediaViewModel {
281279
[audio$, this.video$],
282280
(a, v) =>
283281
encryptionSystem.kind !== E2eeType.NONE &&
284-
(a?.publication?.isEncrypted === false ||
285-
v?.publication?.isEncrypted === false),
282+
(a?.publication.isEncrypted === false ||
283+
v?.publication.isEncrypted === false),
286284
),
287285
);
288286

@@ -471,7 +469,7 @@ export class LocalUserMediaViewModel extends BaseUserMediaViewModel {
471469
private readonly videoTrack$: Observable<LocalVideoTrack | null> =
472470
this.video$.pipe(
473471
switchMap((v) => {
474-
const track = v?.publication?.track;
472+
const track = v?.publication.track;
475473
if (!(track instanceof LocalVideoTrack)) return of(null);
476474
return merge(
477475
// Watch for track restarts because they indicate a camera switch.

src/tile/GridTile.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const UserMediaTile: FC<UserMediaTileProps> = ({
150150
const tile = (
151151
<MediaView
152152
ref={ref}
153-
video={video ?? undefined}
153+
video={video}
154154
userId={vm.userId}
155155
unencryptedWarning={unencryptedWarning}
156156
encryptionStatus={encryptionStatus}

0 commit comments

Comments
 (0)