Fix some errors in CallViewModel

This commit is contained in:
Robin
2025-08-27 14:29:22 +02:00
parent 1ee35066d8
commit b3de46befc

View File

@@ -11,17 +11,17 @@ import {
observeParticipantMedia, observeParticipantMedia,
} from "@livekit/components-core"; } from "@livekit/components-core";
import { import {
ConnectionState, type E2EEOptions,
E2EEOptions,
ExternalE2EEKeyProvider, ExternalE2EEKeyProvider,
Room as LivekitRoom, Room as LivekitRoom,
type LocalParticipant, type LocalParticipant,
ParticipantEvent, ParticipantEvent,
type RemoteParticipant, type RemoteParticipant,
} from "livekit-client"; } from "livekit-client";
import E2EEWorker from "livekit-client/e2ee-worker?worker";
import { import {
ClientEvent, ClientEvent,
MatrixClient, type MatrixClient,
RoomStateEvent, RoomStateEvent,
SyncState, SyncState,
type Room as MatrixRoom, type Room as MatrixRoom,
@@ -33,14 +33,11 @@ import {
type Observable, type Observable,
Subject, Subject,
combineLatest, combineLatest,
concat,
distinctUntilChanged, distinctUntilChanged,
filter, filter,
forkJoin,
fromEvent, fromEvent,
map, map,
merge, merge,
mergeMap,
of, of,
pairwise, pairwise,
race, race,
@@ -52,7 +49,6 @@ import {
switchScan, switchScan,
take, take,
timer, timer,
withLatestFrom,
} from "rxjs"; } from "rxjs";
import { logger } from "matrix-js-sdk/lib/logger"; import { logger } from "matrix-js-sdk/lib/logger";
import { import {
@@ -65,10 +61,6 @@ import {
} from "matrix-js-sdk/lib/matrixrtc"; } from "matrix-js-sdk/lib/matrixrtc";
import { ViewModel } from "./ViewModel"; import { ViewModel } from "./ViewModel";
import {
ECAddonConnectionState,
type ECConnectionState,
} from "../livekit/useECConnectionState";
import { import {
LocalUserMediaViewModel, LocalUserMediaViewModel,
type MediaViewModel, type MediaViewModel,
@@ -125,9 +117,6 @@ export interface CallViewModelOptions {
encryptionSystem: EncryptionSystem; encryptionSystem: EncryptionSystem;
autoLeaveWhenOthersLeft?: boolean; autoLeaveWhenOthersLeft?: boolean;
} }
// How long we wait after a focus switch before showing the real participant
// list again
const POST_FOCUS_PARTICIPANT_UPDATE_DELAY_MS = 3000;
// This is the number of participants that we think constitutes a "small" call // This is the number of participants that we think constitutes a "small" call
// on mobile. No spotlight tile should be shown below this threshold. // on mobile. No spotlight tile should be shown below this threshold.
@@ -476,9 +465,9 @@ class Connection {
this.stopped = true; this.stopped = true;
} }
public readonly participants$ = connectedParticipantsObserver( public readonly participants$ = this.scope.behavior(connectedParticipantsObserver(
this.livekitRoom, this.livekitRoom,
).pipe(this.scope.state()); ), []);
public constructor( public constructor(
private readonly livekitRoom: LivekitRoom, private readonly livekitRoom: LivekitRoom,
@@ -628,9 +617,10 @@ export class CallViewModel extends ViewModel {
private readonly connected$ = this.scope.behavior( private readonly connected$ = this.scope.behavior(
and$( and$(
this.matrixConnected$, this.matrixConnected$,
this.livekitConnectionState$.pipe( // TODO-MULTI-SFU
map((state) => state === ConnectionState.Connected), // this.livekitConnectionState$.pipe(
), // map((state) => state === ConnectionState.Connected),
// ),
), ),
); );
@@ -1705,17 +1695,17 @@ export class CallViewModel extends ViewModel {
) { ) {
super(); super();
void this.localConnection.then((c) => c.startPublishing()); void this.localConnection.then((c) => void c.startPublishing());
this.connectionInstructions$ this.connectionInstructions$
.pipe(this.scope.bind()) .pipe(this.scope.bind())
.subscribe(({ start, stop }) => { .subscribe(({ start, stop }) => {
for (const connection of start) connection.startSubscribing(); for (const connection of start) void connection.startSubscribing();
for (const connection of stop) connection.stop(); for (const connection of stop) connection.stop();
}); });
combineLatest([this.localFocus, this.joined$]) combineLatest([this.localFocus, this.joined$])
.pipe(this.scope.bind()) .pipe(this.scope.bind())
.subscribe(([localFocus]) => { .subscribe(([localFocus]) => {
enterRTCSession( void enterRTCSession(
this.matrixRTCSession, this.matrixRTCSession,
localFocus, localFocus,
this.encryptionSystem.kind !== E2eeType.PER_PARTICIPANT, this.encryptionSystem.kind !== E2eeType.PER_PARTICIPANT,