@@ -7,8 +7,8 @@ Please see LICENSE in the repository root for full details.
77
88import {
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";
6059export 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.
0 commit comments