From 82392bf5828825dfdf9c696c0514aeb61929db2b Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 16 Sep 2025 12:51:51 +0100 Subject: [PATCH] Expose livekitConnectionState directly --- src/room/InCallView.tsx | 8 ++++++-- src/state/CallViewModel.ts | 16 ++++------------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/room/InCallView.tsx b/src/room/InCallView.tsx index 0b1a2be2..32af10d1 100644 --- a/src/room/InCallView.tsx +++ b/src/room/InCallView.tsx @@ -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 = ({ 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 diff --git a/src/state/CallViewModel.ts b/src/state/CallViewModel.ts index 2764d45d..8289369f 100644 --- a/src/state/CallViewModel.ts +++ b/src/state/CallViewModel.ts @@ -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, + public readonly livekitConnectionState$: Observable, private readonly handsRaisedSubject$: Observable< Record >,