update to sdk api change: audioLevel stats$()

This commit is contained in:
Timo K.
2026-10-14 10:23:29 +02:00
committed by Timo
parent 79c1f82448
commit b0659279ee
4 changed files with 12 additions and 12 deletions
+2 -9
View File
@@ -6,11 +6,7 @@ Please see LICENSE in the repository root for full details.
*/ */
import { expect, onTestFinished, test, vi } from "vitest"; import { expect, onTestFinished, test, vi } from "vitest";
import { import { constant } from "@element-hq/matrixrtc-sdk";
type Behavior,
constant,
type MediaStreamStats,
} from "@element-hq/matrixrtc-sdk";
import { waitFor } from "@testing-library/dom"; import { waitFor } from "@testing-library/dom";
import { BehaviorSubject } from "rxjs"; import { BehaviorSubject } from "rxjs";
@@ -241,12 +237,9 @@ test("user media polls stream stats only while the setting is on", () => {
onTestFinished(() => showConnectionStats.setValue(false)); onTestFinished(() => showConnectionStats.setValue(false));
withTestScheduler(({ cold, expectObservable, schedule }) => { withTestScheduler(({ cold, expectObservable, schedule }) => {
const stats = { type: "inbound-rtp" } as RTCInboundRtpStreamStats; const stats = { type: "inbound-rtp" } as RTCInboundRtpStreamStats;
// A behavior that only runs its source while subscribed, as the SDK's does
const vm = mockRemoteMedia(rtcMembership, {}, [ const vm = mockRemoteMedia(rtcMembership, {}, [
mockAudioTrack({ mockAudioTrack({
stats$: cold("-s", { stats$: () => cold("-s", { s: stats }),
s: stats,
}) as unknown as Behavior<MediaStreamStats>,
}), }),
]); ]);
schedule("-a-b", { schedule("-a-b", {
+4 -1
View File
@@ -35,6 +35,9 @@ import { type UserMediaViewModel } from "./UserMediaViewModel";
import { type ScreenShareViewModel } from "./ScreenShareViewModel"; import { type ScreenShareViewModel } from "./ScreenShareViewModel";
import { type UnstableLivekitTransport } from "matrix-js-sdk/lib/matrixrtc"; import { type UnstableLivekitTransport } from "matrix-js-sdk/lib/matrixrtc";
/** How often a view model reads a track's RTP statistics while it needs them. */
export const statsIntervalMs = 1000;
// TODO: Encryption status is kinda broken and thus unused right now. Remove? // TODO: Encryption status is kinda broken and thus unused right now. Remove?
export enum EncryptionStatus { export enum EncryptionStatus {
Connecting, Connecting,
@@ -157,7 +160,7 @@ function receivingOkay$(
): Observable<boolean | undefined> { ): Observable<boolean | undefined> {
let last: { framesDecoded?: number; framesReceived?: number } = {}; let last: { framesDecoded?: number; framesReceived?: number } = {};
return track$.pipe( return track$.pipe(
switchMap((track) => track?.stats$ ?? of(undefined)), switchMap((track) => track?.stats$(statsIntervalMs) ?? of(undefined)),
map((stats): boolean | undefined => { map((stats): boolean | undefined => {
if (stats === undefined || stats.type !== "inbound-rtp") return undefined; if (stats === undefined || stats.type !== "inbound-rtp") return undefined;
const { framesDecoded, framesReceived } = const { framesDecoded, framesReceived } =
+4 -1
View File
@@ -27,6 +27,7 @@ import {
createMemberMedia, createMemberMedia,
type MemberMediaInputs, type MemberMediaInputs,
type BaseMemberMediaViewModel, type BaseMemberMediaViewModel,
statsIntervalMs,
} from "./MemberMediaViewModel"; } from "./MemberMediaViewModel";
import { type RemoteUserMediaViewModel } from "./RemoteUserMediaViewModel"; import { type RemoteUserMediaViewModel } from "./RemoteUserMediaViewModel";
import { showConnectionStats } from "../../settings/settings"; import { showConnectionStats } from "../../settings/settings";
@@ -104,7 +105,9 @@ export function createBaseUserMedia(
showConnectionStats.value$, showConnectionStats.value$,
]).pipe( ]).pipe(
switchMap(([track, show]) => switchMap(([track, show]) =>
track !== undefined && show ? track.stats$ : of(undefined), track !== undefined && show
? track.stats$(statsIntervalMs)
: of(undefined),
), ),
), ),
); );
+2 -1
View File
@@ -311,8 +311,9 @@ export function mockMediaTrack(
id: "track", id: "track",
muted$: constant(false), muted$: constant(false),
encrypted: true, encrypted: true,
stats$: constant(undefined), stats$: () => constant(undefined),
isActive$: constant(false), isActive$: constant(false),
audioLevel$: constant(0),
attach: vi.fn(), attach: vi.fn(),
detach: vi.fn(), detach: vi.fn(),
setAudioContext: vi.fn(), setAudioContext: vi.fn(),