1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00
Files
matrix-js-sdk/spec/unit/webrtc/stats/callFeedStatsReporter.spec.ts
Enrico Schwendig 3cfad3cdeb Expand webrtc stats with connection and call feed track information (#3421)
* Refactor names in webrtc stats

* Refactor summary stats reporter to gatherer

* Add call and opponent member id to call stats reports

* Update opponent member when we know them

* Add missing return type

* remove async in test

* add call feed webrtc report

* add logger for error case in stats gathering

* gather connection track report

* expand call feed stats with call feed

* formation code and fix lint issues

* clean up new track stats

 * set label for call feed stats and
 * remove stream in track stats
 * transceiver stats based on mid
 * call feed stats based on stream id
 * fix lint and test issues

* Fix merge issues

* Add test for expanding call feed stats in group call

* Fix export issue from prv PR

* explain test data and fixed some linter issues

* convert tests to snapshot tests
2023-06-07 14:05:51 +00:00

118 lines
4.1 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 { CallFeedStatsReporter } from "../../../../src/webrtc/stats/callFeedStatsReporter";
import { CallFeedReport } from "../../../../src/webrtc/stats/statsReport";
import { CallFeed } from "../../../../src/webrtc/callFeed";
const CALL_ID = "CALL_ID";
const USER_ID = "USER_ID";
describe("CallFeedStatsReporter", () => {
let rtcSpy: RTCPeerConnection;
beforeEach(() => {
rtcSpy = {} as RTCPeerConnection;
rtcSpy.getTransceivers = jest.fn().mockReturnValue(buildTransceiverMocks());
});
describe("should", () => {
it("builds CallFeedReport", async () => {
expect(CallFeedStatsReporter.buildCallFeedReport(CALL_ID, USER_ID, rtcSpy)).toMatchSnapshot();
});
it("extends CallFeedReport with call feeds", async () => {
const feed = buildCallFeedMock("1");
const callFeedList: CallFeed[] = [feed];
const report = {
callId: "callId",
opponentMemberId: "opponentMemberId",
transceiver: [],
callFeeds: [],
} as CallFeedReport;
expect(CallFeedStatsReporter.expandCallFeedReport(report, callFeedList).callFeeds).toMatchSnapshot();
});
});
const buildTransceiverMocks = (): RTCRtpTransceiver[] => {
const trans1 = {
mid: "0",
direction: "sendrecv",
currentDirection: "sendonly",
sender: buildSenderMock("sender_audio_0", "audio"),
receiver: buildReceiverMock("receiver_audio_0", "audio"),
} as RTCRtpTransceiver;
const trans2 = {
mid: "1",
direction: "recvonly",
currentDirection: "sendrecv",
sender: buildSenderMock("sender_video_1", "video"),
receiver: buildReceiverMock("receiver_video_1", "video"),
} as RTCRtpTransceiver;
const trans3 = {
mid: "2",
direction: "recvonly",
currentDirection: "recvonly",
sender: { track: null } as RTCRtpSender,
receiver: buildReceiverMock("receiver_video_2", "video"),
} as RTCRtpTransceiver;
return [trans1, trans2, trans3];
};
const buildSenderMock = (id: string, kind: "audio" | "video"): RTCRtpSender => {
const track = buildTrackMock(id, kind);
return {
track,
} as RTCRtpSender;
};
const buildReceiverMock = (id: string, kind: "audio" | "video"): RTCRtpReceiver => {
const track = buildTrackMock(id, kind);
return {
track,
} as RTCRtpReceiver;
};
const buildTrackMock = (id: string, kind: "audio" | "video"): MediaStreamTrack => {
return {
id,
kind,
enabled: true,
label: "--",
muted: false,
readyState: "live",
getSettings: () => ({ deviceId: `settingDeviceId-${id}` }),
getConstraints: () => ({ deviceId: `constrainDeviceId-${id}` }),
} as MediaStreamTrack;
};
const buildCallFeedMock = (id: string, isLocal = true): CallFeed => {
const stream = {
id: `stream-${id}`,
getAudioTracks(): MediaStreamTrack[] {
return [buildTrackMock(`video-${id}`, "video")];
},
getVideoTracks(): MediaStreamTrack[] {
return [buildTrackMock(`audio-${id}`, "audio")];
},
} as MediaStream;
return {
stream,
isLocal: () => isLocal,
isVideoMuted: () => false,
isAudioMuted: () => true,
} as CallFeed;
};
});