Expose livekitConnectionState directly

This commit is contained in:
Half-Shot
2025-09-16 12:51:51 +01:00
parent f072fd2f9c
commit 82392bf582
2 changed files with 10 additions and 14 deletions

View File

@@ -25,7 +25,11 @@ import useMeasure from "react-use-measure";
import { type MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
import classNames from "classnames";
import { BehaviorSubject, map } from "rxjs";
import { useObservable, useSubscription } from "observable-hooks";
import {
useObservable,
useObservableEagerState,
useSubscription,
} from "observable-hooks";
import { logger } from "matrix-js-sdk/lib/logger";
import { RoomAndToDeviceEvents } from "matrix-js-sdk/lib/matrixrtc/RoomAndToDeviceKeyTransport";
import {
@@ -249,7 +253,7 @@ export const InCallView: FC<InCallViewProps> = ({
useReactionsSender();
useWakeLock();
const isDisconnected = useBehavior(vm.livekitDisconnected$);
const isDisconnected = useObservableEagerState(vm.livekitConnectionState$);
// annoyingly we don't get the disconnection reason this way,
// only by listening for the emitted event

View File

@@ -465,14 +465,6 @@ export class CallViewModel extends ViewModel {
),
);
public readonly livekitDisconnected$ = this.scope.behavior(
and$(
this.livekitConnectionState$.pipe(
map((state) => state === ConnectionState.Disconnected),
),
),
);
private readonly connected$ = this.scope.behavior(
and$(
this.matrixConnected$,
@@ -969,11 +961,11 @@ export class CallViewModel extends ViewModel {
"unknown" | "ringing" | "timeout" | "decline" | "success"
>(
combineLatest([
this.livekitDisconnected$,
this.livekitConnectionState$,
this.someoneElseJoined$,
]).pipe(
switchMap(([disconnected, someoneElseJoined]) => {
if (disconnected) {
switchMap(([livekitConnectionState, someoneElseJoined]) => {
if (livekitConnectionState === ConnectionState.Disconnected) {
// Do not ring until we're connected.
return of("unknown" as const);
} else if (someoneElseJoined) {
@@ -1698,7 +1690,7 @@ export class CallViewModel extends ViewModel {
private readonly livekitRoom: LivekitRoom,
private readonly mediaDevices: MediaDevices,
private readonly options: CallViewModelOptions,
private readonly livekitConnectionState$: Observable<ECConnectionState>,
public readonly livekitConnectionState$: Observable<ECConnectionState>,
private readonly handsRaisedSubject$: Observable<
Record<string, RaisedHandInfo>
>,