This repository was archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.ts
75 lines (66 loc) · 2.68 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import type { Page } from "@playwright/test";
import { expect, test } from "@playwright/test";
export const joinRoomAndAddScreenShare = async (page: Page, roomId: string): Promise<string> =>
test.step("Join room and add track", async () => {
const peerRequest = await createPeer(page, roomId);
try {
const {
peer: { id: peerId },
token: peerToken,
} = (await peerRequest.json()).data;
await test.step("Join room", async () => {
await page.getByPlaceholder("token").fill(peerToken);
await page.getByRole("button", { name: "Connect", exact: true }).click();
await expect(page.getByText("Status: joined")).toBeVisible();
});
await test.step("Add screenshare", async () => {
await page.getByRole("button", { name: "Start screen share", exact: true }).click();
});
return peerId;
} catch (e) {
// todo fix
throw { status: peerRequest.status(), response: await peerRequest.json() };
}
});
export const assertThatRemoteTracksAreVisible = async (page: Page, otherClientIds: string[]) => {
await test.step("Assert that remote tracks are visible", () =>
Promise.all(
otherClientIds.map((peerId) => expect(page.locator(`css=video[data-peer-id="${peerId}"]`)).toBeVisible()),
));
};
export const assertThatOtherVideoIsPlaying = async (page: Page) => {
await test.step("Assert that media is working", async () => {
const getDecodedFrames: () => Promise<number> = () =>
page.evaluate(async () => {
const client = (window as typeof window & { client: { getStatistics: () => Promise<RTCStatsReport> } }).client;
const stats = await client.getStatistics();
for (const stat of stats?.values() ?? []) {
if (stat.type === "inbound-rtp") {
return stat.framesDecoded;
}
}
return 0;
});
const firstMeasure = await getDecodedFrames();
await expect(async () => expect((await getDecodedFrames()) > firstMeasure).toBe(true)).toPass();
});
};
export const createRoom = async (page: Page, maxPeers?: number) =>
await test.step("Create room", async () => {
const data = {
...(maxPeers ? { maxPeers } : {}),
};
const roomRequest = await page.request.post("http://localhost:5002/room", { data });
return (await roomRequest.json()).data.room.id as string;
});
export const createPeer = async (page: Page, roomId: string, enableSimulcast: boolean = true) =>
await test.step("Create room", async () => {
return await page.request.post("http://localhost:5002/room/" + roomId + "/peer", {
data: {
type: "webrtc",
options: {
enableSimulcast,
},
},
});
});