From 8de6ddceb0ec1e0095fd5705fbf4c25f8cad1ee0 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 15 Aug 2025 20:20:00 +0200 Subject: [PATCH] Test that media tracks are paused while reconnecting to MatrixRTC --- src/state/CallViewModel.test.ts | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/state/CallViewModel.test.ts b/src/state/CallViewModel.test.ts index 9fce6e5d..eec471b6 100644 --- a/src/state/CallViewModel.test.ts +++ b/src/state/CallViewModel.test.ts @@ -21,6 +21,7 @@ import { type MatrixClient } from "matrix-js-sdk"; import { ConnectionState, type LocalParticipant, + type LocalTrackPublication, type Participant, ParticipantEvent, type RemoteParticipant, @@ -1237,3 +1238,55 @@ test("audio output changes when toggling earpiece mode", () => { ); }); }); + +test("media tracks are paused while reconnecting to MatrixRTC", () => { + withTestScheduler(({ behavior, schedule, expectObservable }) => { + const trackRunning$ = new BehaviorSubject(true); + const originalPublications = localParticipant.trackPublications; + localParticipant.trackPublications = new Map([ + [ + "video", + { + track: new (class { + public get isUpstreamPaused(): boolean { + return !trackRunning$.value; + } + public async pauseUpstream(): Promise { + trackRunning$.next(false); + return Promise.resolve(); + } + public async resumeUpstream(): Promise { + trackRunning$.next(true); + return Promise.resolve(); + } + })(), + } as unknown as LocalTrackPublication, + ], + ]); + onTestFinished(() => { + localParticipant.trackPublications = originalPublications; + }); + + const rtcMemberMarbles = " aba"; + const expectedReconnectingMarbles = "nyn"; + const expectedTrackRunningMarbles = "yny"; + + withCallViewModel( + constant([]), + behavior(rtcMemberMarbles, { a: [localRtcMember], b: [] }), + of(ConnectionState.Connected), + new Map(), + mockMediaDevices({}), + (vm) => { + expectObservable(vm.reconnecting$).toBe( + expectedReconnectingMarbles, + yesNo, + ); + expectObservable(trackRunning$).toBe( + expectedTrackRunningMarbles, + yesNo, + ); + }, + ); + }); +});