You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
* stats: merge stats classes in this branch * stats: merge call object * stats: merge export metric events * stats: fix code style changes * stats: add missing stats value formatter * stats: add missing methode to call mock * stats: add stats for callee * stats: stop sending stats if call finish * stats: rename StatsCollector to StatsReportGatherer
69 lines
2.8 KiB
TypeScript
69 lines
2.8 KiB
TypeScript
/*
|
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
import { StatsReportGatherer } from "../../../../src/webrtc/stats/statsReportGatherer";
|
|
import { StatsReportEmitter } from "../../../../src/webrtc/stats/statsReportEmitter";
|
|
|
|
const CALL_ID = "CALL_ID";
|
|
const USER_ID = "USER_ID";
|
|
|
|
describe("StatsReportGatherer", () => {
|
|
let collector: StatsReportGatherer;
|
|
let rtcSpy: RTCPeerConnection;
|
|
let emitter: StatsReportEmitter;
|
|
beforeEach(() => {
|
|
rtcSpy = { getStats: () => new Promise<RTCStatsReport>(() => null) } as RTCPeerConnection;
|
|
rtcSpy.addEventListener = jest.fn();
|
|
emitter = new StatsReportEmitter();
|
|
collector = new StatsReportGatherer(CALL_ID, USER_ID, rtcSpy, emitter);
|
|
});
|
|
|
|
describe("on process stats", () => {
|
|
it("if active calculate stats reports", async () => {
|
|
const getStats = jest.spyOn(rtcSpy, "getStats");
|
|
getStats.mockResolvedValue({} as RTCStatsReport);
|
|
await collector.processStats("GROUP_CALL_ID", "LOCAL_USER_ID");
|
|
expect(getStats).toHaveBeenCalled();
|
|
});
|
|
|
|
it("if not active do not calculate stats reports", async () => {
|
|
collector.setActive(false);
|
|
const getStats = jest.spyOn(rtcSpy, "getStats");
|
|
await collector.processStats("GROUP_CALL_ID", "LOCAL_USER_ID");
|
|
expect(getStats).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("if get reports fails, the collector becomes inactive", async () => {
|
|
expect(collector.getActive()).toBeTruthy();
|
|
const getStats = jest.spyOn(rtcSpy, "getStats");
|
|
getStats.mockRejectedValue(new Error("unknown"));
|
|
await collector.processStats("GROUP_CALL_ID", "LOCAL_USER_ID");
|
|
expect(getStats).toHaveBeenCalled();
|
|
expect(collector.getActive()).toBeFalsy();
|
|
});
|
|
|
|
it("if active an RTCStatsReport not a promise the collector becomes inactive", async () => {
|
|
const getStats = jest.spyOn(rtcSpy, "getStats");
|
|
// @ts-ignore
|
|
getStats.mockReturnValue({});
|
|
const actual = await collector.processStats("GROUP_CALL_ID", "LOCAL_USER_ID");
|
|
expect(actual).toBeFalsy();
|
|
expect(getStats).toHaveBeenCalled();
|
|
expect(collector.getActive()).toBeFalsy();
|
|
});
|
|
});
|
|
});
|