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.
This commit is contained in:
@@ -358,7 +358,7 @@ export class Publisher {
|
|||||||
const track$ = scope.behavior(
|
const track$ = scope.behavior(
|
||||||
observeTrackReference$(room.localParticipant, Track.Source.Camera).pipe(
|
observeTrackReference$(room.localParticipant, Track.Source.Camera).pipe(
|
||||||
map((trackRef) => {
|
map((trackRef) => {
|
||||||
const track = trackRef?.publication?.track;
|
const track = trackRef?.publication.track;
|
||||||
return track instanceof LocalVideoTrack ? track : null;
|
return track instanceof LocalVideoTrack ? track : null;
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ Please see LICENSE in the repository root for full details.
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
type AudioSource,
|
type AudioSource,
|
||||||
type TrackReferenceOrPlaceholder,
|
|
||||||
type VideoSource,
|
type VideoSource,
|
||||||
|
type TrackReference,
|
||||||
observeParticipantEvents,
|
observeParticipantEvents,
|
||||||
observeParticipantMedia,
|
observeParticipantMedia,
|
||||||
roomEventSelector,
|
roomEventSelector,
|
||||||
@@ -33,7 +33,6 @@ import {
|
|||||||
type Observable,
|
type Observable,
|
||||||
Subject,
|
Subject,
|
||||||
combineLatest,
|
combineLatest,
|
||||||
distinctUntilKeyChanged,
|
|
||||||
filter,
|
filter,
|
||||||
fromEvent,
|
fromEvent,
|
||||||
interval,
|
interval,
|
||||||
@@ -60,14 +59,11 @@ import { type ObservableScope } from "./ObservableScope";
|
|||||||
export function observeTrackReference$(
|
export function observeTrackReference$(
|
||||||
participant: Participant,
|
participant: Participant,
|
||||||
source: Track.Source,
|
source: Track.Source,
|
||||||
): Observable<TrackReferenceOrPlaceholder> {
|
): Observable<TrackReference | undefined> {
|
||||||
return observeParticipantMedia(participant).pipe(
|
return observeParticipantMedia(participant).pipe(
|
||||||
map(() => ({
|
map(() => participant.getTrackPublication(source)),
|
||||||
participant: participant,
|
distinctUntilChanged(),
|
||||||
publication: participant.getTrackPublication(source),
|
map((publication) => publication && { participant, publication, source }),
|
||||||
source,
|
|
||||||
})),
|
|
||||||
distinctUntilKeyChanged("publication"),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +222,7 @@ abstract class BaseMediaViewModel {
|
|||||||
/**
|
/**
|
||||||
* The LiveKit video track for this media.
|
* The LiveKit video track for this media.
|
||||||
*/
|
*/
|
||||||
public readonly video$: Behavior<TrackReferenceOrPlaceholder | null>;
|
public readonly video$: Behavior<TrackReference | undefined>;
|
||||||
/**
|
/**
|
||||||
* Whether there should be a warning that this media is unencrypted.
|
* Whether there should be a warning that this media is unencrypted.
|
||||||
*/
|
*/
|
||||||
@@ -241,10 +237,12 @@ abstract class BaseMediaViewModel {
|
|||||||
|
|
||||||
private observeTrackReference$(
|
private observeTrackReference$(
|
||||||
source: Track.Source,
|
source: Track.Source,
|
||||||
): Behavior<TrackReferenceOrPlaceholder | null> {
|
): Behavior<TrackReference | undefined> {
|
||||||
return this.scope.behavior(
|
return this.scope.behavior(
|
||||||
this.participant$.pipe(
|
this.participant$.pipe(
|
||||||
switchMap((p) => (!p ? of(null) : observeTrackReference$(p, source))),
|
switchMap((p) =>
|
||||||
|
!p ? of(undefined) : observeTrackReference$(p, source),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -281,8 +279,8 @@ abstract class BaseMediaViewModel {
|
|||||||
[audio$, this.video$],
|
[audio$, this.video$],
|
||||||
(a, v) =>
|
(a, v) =>
|
||||||
encryptionSystem.kind !== E2eeType.NONE &&
|
encryptionSystem.kind !== E2eeType.NONE &&
|
||||||
(a?.publication?.isEncrypted === false ||
|
(a?.publication.isEncrypted === false ||
|
||||||
v?.publication?.isEncrypted === false),
|
v?.publication.isEncrypted === false),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -471,7 +469,7 @@ export class LocalUserMediaViewModel extends BaseUserMediaViewModel {
|
|||||||
private readonly videoTrack$: Observable<LocalVideoTrack | null> =
|
private readonly videoTrack$: Observable<LocalVideoTrack | null> =
|
||||||
this.video$.pipe(
|
this.video$.pipe(
|
||||||
switchMap((v) => {
|
switchMap((v) => {
|
||||||
const track = v?.publication?.track;
|
const track = v?.publication.track;
|
||||||
if (!(track instanceof LocalVideoTrack)) return of(null);
|
if (!(track instanceof LocalVideoTrack)) return of(null);
|
||||||
return merge(
|
return merge(
|
||||||
// Watch for track restarts because they indicate a camera switch.
|
// Watch for track restarts because they indicate a camera switch.
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ const UserMediaTile: FC<UserMediaTileProps> = ({
|
|||||||
const tile = (
|
const tile = (
|
||||||
<MediaView
|
<MediaView
|
||||||
ref={ref}
|
ref={ref}
|
||||||
video={video ?? undefined}
|
video={video}
|
||||||
userId={vm.userId}
|
userId={vm.userId}
|
||||||
unencryptedWarning={unencryptedWarning}
|
unencryptedWarning={unencryptedWarning}
|
||||||
encryptionStatus={encryptionStatus}
|
encryptionStatus={encryptionStatus}
|
||||||
|
|||||||
Reference in New Issue
Block a user