mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
update to sdk api change: audioLevel stats$()
This commit is contained in:
@@ -6,11 +6,7 @@ Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { expect, onTestFinished, test, vi } from "vitest";
|
||||
import {
|
||||
type Behavior,
|
||||
constant,
|
||||
type MediaStreamStats,
|
||||
} from "@element-hq/matrixrtc-sdk";
|
||||
import { constant } from "@element-hq/matrixrtc-sdk";
|
||||
import { waitFor } from "@testing-library/dom";
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
|
||||
@@ -241,12 +237,9 @@ test("user media polls stream stats only while the setting is on", () => {
|
||||
onTestFinished(() => showConnectionStats.setValue(false));
|
||||
withTestScheduler(({ cold, expectObservable, schedule }) => {
|
||||
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, {}, [
|
||||
mockAudioTrack({
|
||||
stats$: cold("-s", {
|
||||
s: stats,
|
||||
}) as unknown as Behavior<MediaStreamStats>,
|
||||
stats$: () => cold("-s", { s: stats }),
|
||||
}),
|
||||
]);
|
||||
schedule("-a-b", {
|
||||
|
||||
@@ -35,6 +35,9 @@ import { type UserMediaViewModel } from "./UserMediaViewModel";
|
||||
import { type ScreenShareViewModel } from "./ScreenShareViewModel";
|
||||
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?
|
||||
export enum EncryptionStatus {
|
||||
Connecting,
|
||||
@@ -157,7 +160,7 @@ function receivingOkay$(
|
||||
): Observable<boolean | undefined> {
|
||||
let last: { framesDecoded?: number; framesReceived?: number } = {};
|
||||
return track$.pipe(
|
||||
switchMap((track) => track?.stats$ ?? of(undefined)),
|
||||
switchMap((track) => track?.stats$(statsIntervalMs) ?? of(undefined)),
|
||||
map((stats): boolean | undefined => {
|
||||
if (stats === undefined || stats.type !== "inbound-rtp") return undefined;
|
||||
const { framesDecoded, framesReceived } =
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
createMemberMedia,
|
||||
type MemberMediaInputs,
|
||||
type BaseMemberMediaViewModel,
|
||||
statsIntervalMs,
|
||||
} from "./MemberMediaViewModel";
|
||||
import { type RemoteUserMediaViewModel } from "./RemoteUserMediaViewModel";
|
||||
import { showConnectionStats } from "../../settings/settings";
|
||||
@@ -104,7 +105,9 @@ export function createBaseUserMedia(
|
||||
showConnectionStats.value$,
|
||||
]).pipe(
|
||||
switchMap(([track, show]) =>
|
||||
track !== undefined && show ? track.stats$ : of(undefined),
|
||||
track !== undefined && show
|
||||
? track.stats$(statsIntervalMs)
|
||||
: of(undefined),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
+2
-1
@@ -311,8 +311,9 @@ export function mockMediaTrack(
|
||||
id: "track",
|
||||
muted$: constant(false),
|
||||
encrypted: true,
|
||||
stats$: constant(undefined),
|
||||
stats$: () => constant(undefined),
|
||||
isActive$: constant(false),
|
||||
audioLevel$: constant(0),
|
||||
attach: vi.fn(),
|
||||
detach: vi.fn(),
|
||||
setAudioContext: vi.fn(),
|
||||
|
||||
Reference in New Issue
Block a user