Fix some errors in CallViewModel

This commit is contained in:
Robin
2025-08-27 14:29:22 +02:00
committed by Timo K
parent 9011ae4e1f
commit 35319dd6b5

View File

@@ -12,19 +12,20 @@ import {
} from "@livekit/components-core"; } from "@livekit/components-core";
import { import {
ConnectionState, ConnectionState,
E2EEOptions, type 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,
type EventTimelineSetHandlerMap, type EventTimelineSetHandlerMap,
EventType, EventType,
RoomEvent, RoomEvent,
MatrixClient, type MatrixClient,
RoomStateEvent, RoomStateEvent,
SyncState, SyncState,
type Room as MatrixRoom, type Room as MatrixRoom,
@@ -41,12 +42,10 @@ import {
distinctUntilChanged, distinctUntilChanged,
endWith, endWith,
filter, filter,
forkJoin,
fromEvent, fromEvent,
ignoreElements, ignoreElements,
map, map,
merge, merge,
mergeMap,
of, of,
pairwise, pairwise,
race, race,
@@ -61,7 +60,6 @@ import {
takeUntil, takeUntil,
throttleTime, throttleTime,
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 {
@@ -75,10 +73,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,
@@ -120,7 +114,7 @@ import { observeSpeaker$ } from "./observeSpeaker";
import { shallowEquals } from "../utils/array"; import { shallowEquals } from "../utils/array";
import { calculateDisplayName, shouldDisambiguate } from "../utils/displayname"; import { calculateDisplayName, shouldDisambiguate } from "../utils/displayname";
import { type MediaDevices } from "./MediaDevices"; import { type MediaDevices } from "./MediaDevices";
import { type Behavior } from "./Behavior"; import { constant, type Behavior } from "./Behavior";
import { getSFUConfigWithOpenID } from "../livekit/openIDSFU"; import { getSFUConfigWithOpenID } from "../livekit/openIDSFU";
import { defaultLiveKitOptions } from "../livekit/options"; import { defaultLiveKitOptions } from "../livekit/options";
import { import {
@@ -130,6 +124,7 @@ import {
} from "../rtcSessionHelpers"; } from "../rtcSessionHelpers";
import { E2eeType } from "../e2ee/e2eeType"; import { E2eeType } from "../e2ee/e2eeType";
import { MatrixKeyProvider } from "../e2ee/matrixKeyProvider"; import { MatrixKeyProvider } from "../e2ee/matrixKeyProvider";
import { ECConnectionState } from "../livekit/useECConnectionState";
export interface CallViewModelOptions { export interface CallViewModelOptions {
encryptionSystem: EncryptionSystem; encryptionSystem: EncryptionSystem;
@@ -141,10 +136,6 @@ export interface CallViewModelOptions {
waitForCallPickup?: boolean; waitForCallPickup?: boolean;
} }
// How long we wait after a focus switch before showing the real participant
// list again
const POST_FOCUS_PARTICIPANT_UPDATE_DELAY_MS = 3000;
// Do not play any sounds if the participant count has exceeded this // Do not play any sounds if the participant count has exceeded this
// number. // number.
export const MAX_PARTICIPANT_COUNT_FOR_SOUND = 8; export const MAX_PARTICIPANT_COUNT_FOR_SOUND = 8;
@@ -497,9 +488,10 @@ class Connection {
this.stopped = true; this.stopped = true;
} }
public readonly participants$ = connectedParticipantsObserver( public readonly participants$ = this.scope.behavior(
this.livekitRoom, connectedParticipantsObserver(this.livekitRoom),
).pipe(this.scope.state()); [],
);
public constructor( public constructor(
private readonly livekitRoom: LivekitRoom, private readonly livekitRoom: LivekitRoom,
@@ -649,9 +641,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),
// ),
), ),
); );
@@ -1819,17 +1812,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,