Merge fixes

This commit is contained in:
Hugh Nimmo-Smith
2024-11-06 14:02:14 +00:00
parent c829f2f599
commit 73107e4139

View File

@@ -32,7 +32,6 @@ import {
Observable, Observable,
Subject, Subject,
combineLatest, combineLatest,
distinctUntilChanged,
distinctUntilKeyChanged, distinctUntilKeyChanged,
filter, filter,
fromEvent, fromEvent,
@@ -40,7 +39,6 @@ import {
map, map,
merge, merge,
of, of,
shareReplay,
startWith, startWith,
switchMap, switchMap,
throttleTime, throttleTime,
@@ -114,11 +112,11 @@ function observeRemoteTrackReceivingOkay(
}; };
return combineLatest([ return combineLatest([
observeTrackReference(participant, source), observeTrackReference(of(participant), source),
interval(1000).pipe(startWith(0)), interval(1000).pipe(startWith(0)),
]).pipe( ]).pipe(
switchMap(async ([trackReference]) => { switchMap(async ([trackReference]) => {
const track = trackReference.publication?.track; const track = trackReference?.publication?.track;
if (!track || !(track instanceof RemoteTrack)) { if (!track || !(track instanceof RemoteTrack)) {
return undefined; return undefined;
} }
@@ -267,64 +265,69 @@ abstract class BaseMediaViewModel extends ViewModel {
encryptionSystem.kind !== E2eeType.NONE && encryptionSystem.kind !== E2eeType.NONE &&
(a?.publication?.isEncrypted === false || (a?.publication?.isEncrypted === false ||
v?.publication?.isEncrypted === false), v?.publication?.isEncrypted === false),
).pipe(this.scope.state()); ).pipe(this.scope.state());
if (participant.isLocal || encryptionSystem.kind === E2eeType.NONE) { this.encryptionStatus = this.participant.pipe(
this.encryptionStatus = of(EncryptionStatus.Okay).pipe( switchMap((participant): Observable<EncryptionStatus> => {
this.scope.state(), if (
); !participant ||
} else if (encryptionSystem.kind === E2eeType.PER_PARTICIPANT) { participant.isLocal ||
this.encryptionStatus = combineLatest([ encryptionSystem.kind === E2eeType.NONE
encryptionErrorObservable( ) {
livekitRoom, return of(EncryptionStatus.Okay);
participant, } else if (encryptionSystem.kind === E2eeType.PER_PARTICIPANT) {
encryptionSystem, return combineLatest([
"MissingKey", encryptionErrorObservable(
), livekitRoom,
encryptionErrorObservable( participant,
livekitRoom, encryptionSystem,
participant, "MissingKey",
encryptionSystem, ),
"InvalidKey", encryptionErrorObservable(
), livekitRoom,
observeRemoteTrackReceivingOkay(participant, audioSource), participant,
observeRemoteTrackReceivingOkay(participant, videoSource), encryptionSystem,
]).pipe( "InvalidKey",
map(([keyMissing, keyInvalid, audioOkay, videoOkay]) => { ),
if (keyMissing) return EncryptionStatus.KeyMissing; observeRemoteTrackReceivingOkay(participant, audioSource),
if (keyInvalid) return EncryptionStatus.KeyInvalid; observeRemoteTrackReceivingOkay(participant, videoSource),
if (audioOkay || videoOkay) return EncryptionStatus.Okay; ]).pipe(
return undefined; // no change map(([keyMissing, keyInvalid, audioOkay, videoOkay]) => {
}), if (keyMissing) return EncryptionStatus.KeyMissing;
filter((x) => !!x), if (keyInvalid) return EncryptionStatus.KeyInvalid;
startWith(EncryptionStatus.Connecting), if (audioOkay || videoOkay) return EncryptionStatus.Okay;
this.scope.state(), return undefined; // no change
); }),
} else { filter((x) => !!x),
this.encryptionStatus = combineLatest([ startWith(EncryptionStatus.Connecting),
encryptionErrorObservable( );
livekitRoom, } else {
participant, return combineLatest([
encryptionSystem, encryptionErrorObservable(
"InvalidKey", livekitRoom,
), participant,
observeRemoteTrackReceivingOkay(participant, audioSource), encryptionSystem,
observeRemoteTrackReceivingOkay(participant, videoSource), "InvalidKey",
]).pipe( ),
map( observeRemoteTrackReceivingOkay(participant, audioSource),
([keyInvalid, audioOkay, videoOkay]): observeRemoteTrackReceivingOkay(participant, videoSource),
| EncryptionStatus ]).pipe(
| undefined => { map(
if (keyInvalid) return EncryptionStatus.PasswordInvalid; ([keyInvalid, audioOkay, videoOkay]):
if (audioOkay || videoOkay) return EncryptionStatus.Okay; | EncryptionStatus
return undefined; // no change | undefined => {
}, if (keyInvalid) return EncryptionStatus.PasswordInvalid;
), if (audioOkay || videoOkay) return EncryptionStatus.Okay;
filter((x) => !!x), return undefined; // no change
startWith(EncryptionStatus.Connecting), },
this.scope.state(), ),
); filter((x) => !!x),
} startWith(EncryptionStatus.Connecting),
);
}
}),
this.scope.state(),
);
} }
} }