You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-30 02:21:17 +03:00
Apply prettier formatting
This commit is contained in:
@ -43,10 +43,10 @@ import PlatformPeg from "../../src/PlatformPeg";
|
||||
|
||||
jest.spyOn(MediaDeviceHandler, "getDevices").mockResolvedValue({
|
||||
[MediaDeviceKindEnum.AudioInput]: [
|
||||
{ deviceId: "1", groupId: "1", kind: "audioinput", label: "Headphones", toJSON: () => { } },
|
||||
{ deviceId: "1", groupId: "1", kind: "audioinput", label: "Headphones", toJSON: () => {} },
|
||||
],
|
||||
[MediaDeviceKindEnum.VideoInput]: [
|
||||
{ deviceId: "2", groupId: "2", kind: "videoinput", label: "Built-in webcam", toJSON: () => { } },
|
||||
{ deviceId: "2", groupId: "2", kind: "videoinput", label: "Built-in webcam", toJSON: () => {} },
|
||||
],
|
||||
[MediaDeviceKindEnum.AudioOutput]: [],
|
||||
});
|
||||
@ -55,7 +55,7 @@ jest.spyOn(MediaDeviceHandler, "getVideoInput").mockReturnValue("2");
|
||||
|
||||
const enabledSettings = new Set(["feature_group_calls", "feature_video_rooms", "feature_element_call_video_rooms"]);
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation(
|
||||
settingName => enabledSettings.has(settingName) || undefined,
|
||||
(settingName) => enabledSettings.has(settingName) || undefined,
|
||||
);
|
||||
|
||||
const setUpClientRoomAndStores = (): {
|
||||
@ -75,17 +75,21 @@ const setUpClientRoomAndStores = (): {
|
||||
const alice = mkRoomMember(room.roomId, "@alice:example.org");
|
||||
const bob = mkRoomMember(room.roomId, "@bob:example.org");
|
||||
const carol = mkRoomMember(room.roomId, "@carol:example.org");
|
||||
jest.spyOn(room, "getMember").mockImplementation(userId => {
|
||||
jest.spyOn(room, "getMember").mockImplementation((userId) => {
|
||||
switch (userId) {
|
||||
case alice.userId: return alice;
|
||||
case bob.userId: return bob;
|
||||
case carol.userId: return carol;
|
||||
default: return null;
|
||||
case alice.userId:
|
||||
return alice;
|
||||
case bob.userId:
|
||||
return bob;
|
||||
case carol.userId:
|
||||
return carol;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
});
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("join");
|
||||
|
||||
client.getRoom.mockImplementation(roomId => roomId === room.roomId ? room : null);
|
||||
client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null));
|
||||
client.getRooms.mockReturnValue([room]);
|
||||
client.getUserId.mockReturnValue(alice.userId);
|
||||
client.getDeviceId.mockReturnValue("alices_device");
|
||||
@ -110,14 +114,13 @@ const setUpClientRoomAndStores = (): {
|
||||
return { client, room, alice, bob, carol };
|
||||
};
|
||||
|
||||
const cleanUpClientRoomAndStores = (
|
||||
client: MatrixClient,
|
||||
room: Room,
|
||||
) => {
|
||||
const cleanUpClientRoomAndStores = (client: MatrixClient, room: Room) => {
|
||||
client.reEmitter.stopReEmitting(room, [RoomStateEvent.Events]);
|
||||
};
|
||||
|
||||
const setUpWidget = (call: Call): {
|
||||
const setUpWidget = (
|
||||
call: Call,
|
||||
): {
|
||||
widget: Widget;
|
||||
messaging: Mocked<ClientWidgetApi>;
|
||||
audioMutedSpy: jest.SpyInstance<boolean, []>;
|
||||
@ -361,10 +364,12 @@ describe("JitsiCall", () => {
|
||||
// Now, stub out client.sendStateEvent so we can test our local echo
|
||||
client.sendStateEvent.mockReset();
|
||||
await call.connect();
|
||||
expect(call.participants).toEqual(new Map([
|
||||
[alice, new Set(["alices_device"])],
|
||||
[bob, new Set(["bobweb", "bobdesktop"])],
|
||||
]));
|
||||
expect(call.participants).toEqual(
|
||||
new Map([
|
||||
[alice, new Set(["alices_device"])],
|
||||
[bob, new Set(["bobweb", "bobdesktop"])],
|
||||
]),
|
||||
);
|
||||
|
||||
await call.disconnect();
|
||||
expect(call.participants).toEqual(new Map([[bob, new Set(["bobweb", "bobdesktop"])]]));
|
||||
@ -373,40 +378,56 @@ describe("JitsiCall", () => {
|
||||
it("updates room state when connecting and disconnecting", async () => {
|
||||
const now1 = Date.now();
|
||||
await call.connect();
|
||||
await waitFor(() => expect(
|
||||
room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, alice.userId).getContent(),
|
||||
).toEqual({
|
||||
devices: [client.getDeviceId()],
|
||||
expires_ts: now1 + call.STUCK_DEVICE_TIMEOUT_MS,
|
||||
}), { interval: 5 });
|
||||
await waitFor(
|
||||
() =>
|
||||
expect(
|
||||
room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, alice.userId).getContent(),
|
||||
).toEqual({
|
||||
devices: [client.getDeviceId()],
|
||||
expires_ts: now1 + call.STUCK_DEVICE_TIMEOUT_MS,
|
||||
}),
|
||||
{ interval: 5 },
|
||||
);
|
||||
|
||||
const now2 = Date.now();
|
||||
await call.disconnect();
|
||||
await waitFor(() => expect(
|
||||
room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, alice.userId).getContent(),
|
||||
).toEqual({
|
||||
devices: [],
|
||||
expires_ts: now2 + call.STUCK_DEVICE_TIMEOUT_MS,
|
||||
}), { interval: 5 });
|
||||
await waitFor(
|
||||
() =>
|
||||
expect(
|
||||
room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, alice.userId).getContent(),
|
||||
).toEqual({
|
||||
devices: [],
|
||||
expires_ts: now2 + call.STUCK_DEVICE_TIMEOUT_MS,
|
||||
}),
|
||||
{ interval: 5 },
|
||||
);
|
||||
});
|
||||
|
||||
it("repeatedly updates room state while connected", async () => {
|
||||
await call.connect();
|
||||
await waitFor(() => expect(client.sendStateEvent).toHaveBeenLastCalledWith(
|
||||
room.roomId,
|
||||
JitsiCall.MEMBER_EVENT_TYPE,
|
||||
{ devices: [client.getDeviceId()], expires_ts: expect.any(Number) },
|
||||
alice.userId,
|
||||
), { interval: 5 });
|
||||
await waitFor(
|
||||
() =>
|
||||
expect(client.sendStateEvent).toHaveBeenLastCalledWith(
|
||||
room.roomId,
|
||||
JitsiCall.MEMBER_EVENT_TYPE,
|
||||
{ devices: [client.getDeviceId()], expires_ts: expect.any(Number) },
|
||||
alice.userId,
|
||||
),
|
||||
{ interval: 5 },
|
||||
);
|
||||
|
||||
client.sendStateEvent.mockClear();
|
||||
jest.advanceTimersByTime(call.STUCK_DEVICE_TIMEOUT_MS);
|
||||
await waitFor(() => expect(client.sendStateEvent).toHaveBeenLastCalledWith(
|
||||
room.roomId,
|
||||
JitsiCall.MEMBER_EVENT_TYPE,
|
||||
{ devices: [client.getDeviceId()], expires_ts: expect.any(Number) },
|
||||
alice.userId,
|
||||
), { interval: 5 });
|
||||
await waitFor(
|
||||
() =>
|
||||
expect(client.sendStateEvent).toHaveBeenLastCalledWith(
|
||||
room.roomId,
|
||||
JitsiCall.MEMBER_EVENT_TYPE,
|
||||
{ devices: [client.getDeviceId()], expires_ts: expect.any(Number) },
|
||||
alice.userId,
|
||||
),
|
||||
{ interval: 5 },
|
||||
);
|
||||
});
|
||||
|
||||
it("emits events when connection state changes", async () => {
|
||||
@ -468,24 +489,20 @@ describe("JitsiCall", () => {
|
||||
|
||||
const mkContent = (devices: IMyDevice[]): JitsiCallMemberContent => ({
|
||||
expires_ts: 1000 * 60 * 10,
|
||||
devices: devices.map(d => d.device_id),
|
||||
});
|
||||
const expectDevices = (devices: IMyDevice[]) => expect(
|
||||
room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, alice.userId).getContent(),
|
||||
).toEqual({
|
||||
expires_ts: expect.any(Number),
|
||||
devices: devices.map(d => d.device_id),
|
||||
devices: devices.map((d) => d.device_id),
|
||||
});
|
||||
const expectDevices = (devices: IMyDevice[]) =>
|
||||
expect(
|
||||
room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, alice.userId).getContent(),
|
||||
).toEqual({
|
||||
expires_ts: expect.any(Number),
|
||||
devices: devices.map((d) => d.device_id),
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
client.getDeviceId.mockReturnValue(aliceWeb.device_id);
|
||||
client.getDevices.mockResolvedValue({
|
||||
devices: [
|
||||
aliceWeb,
|
||||
aliceDesktop,
|
||||
aliceDesktopOffline,
|
||||
aliceDesktopNeverOnline,
|
||||
],
|
||||
devices: [aliceWeb, aliceDesktop, aliceDesktopOffline, aliceDesktopNeverOnline],
|
||||
});
|
||||
});
|
||||
|
||||
@ -700,13 +717,15 @@ describe("ElementCall", () => {
|
||||
room.roomId,
|
||||
ElementCall.MEMBER_EVENT_TYPE.name,
|
||||
{
|
||||
"m.calls": [{
|
||||
"m.call_id": call.groupCall.groupCallId,
|
||||
"m.devices": [
|
||||
{ device_id: "bobweb", session_id: "1", feeds: [], expires_ts: 1000 * 60 * 10 },
|
||||
{ device_id: "bobdesktop", session_id: "1", feeds: [], expires_ts: 1000 * 60 * 10 },
|
||||
],
|
||||
}],
|
||||
"m.calls": [
|
||||
{
|
||||
"m.call_id": call.groupCall.groupCallId,
|
||||
"m.devices": [
|
||||
{ device_id: "bobweb", session_id: "1", feeds: [], expires_ts: 1000 * 60 * 10 },
|
||||
{ device_id: "bobdesktop", session_id: "1", feeds: [], expires_ts: 1000 * 60 * 10 },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
bob.userId,
|
||||
);
|
||||
@ -715,12 +734,14 @@ describe("ElementCall", () => {
|
||||
room.roomId,
|
||||
ElementCall.MEMBER_EVENT_TYPE.name,
|
||||
{
|
||||
"m.calls": [{
|
||||
"m.call_id": call.groupCall.groupCallId,
|
||||
"m.devices": [
|
||||
{ device_id: "carolandroid", session_id: "1", feeds: [], expires_ts: -1000 * 60 },
|
||||
],
|
||||
}],
|
||||
"m.calls": [
|
||||
{
|
||||
"m.call_id": call.groupCall.groupCallId,
|
||||
"m.devices": [
|
||||
{ device_id: "carolandroid", session_id: "1", feeds: [], expires_ts: -1000 * 60 },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
carol.userId,
|
||||
);
|
||||
@ -728,10 +749,12 @@ describe("ElementCall", () => {
|
||||
// Now, stub out client.sendStateEvent so we can test our local echo
|
||||
client.sendStateEvent.mockReset();
|
||||
await call.connect();
|
||||
expect(call.participants).toEqual(new Map([
|
||||
[alice, new Set(["alices_device"])],
|
||||
[bob, new Set(["bobweb", "bobdesktop"])],
|
||||
]));
|
||||
expect(call.participants).toEqual(
|
||||
new Map([
|
||||
[alice, new Set(["alices_device"])],
|
||||
[bob, new Set(["bobweb", "bobdesktop"])],
|
||||
]),
|
||||
);
|
||||
|
||||
await call.disconnect();
|
||||
expect(call.participants).toEqual(new Map([[bob, new Set(["bobweb", "bobdesktop"])]]));
|
||||
@ -815,9 +838,9 @@ describe("ElementCall", () => {
|
||||
describe("screensharing", () => {
|
||||
it("passes source id if we can get it", async () => {
|
||||
const sourceId = "source_id";
|
||||
jest.spyOn(Modal, "createDialog").mockReturnValue(
|
||||
{ finished: new Promise((r) => r([sourceId])) } as IHandle<any[]>,
|
||||
);
|
||||
jest.spyOn(Modal, "createDialog").mockReturnValue({
|
||||
finished: new Promise((r) => r([sourceId])),
|
||||
} as IHandle<any[]>);
|
||||
jest.spyOn(PlatformPeg.get(), "supportsDesktopCapturer").mockReturnValue(true);
|
||||
|
||||
await call.connect();
|
||||
@ -836,15 +859,16 @@ describe("ElementCall", () => {
|
||||
|
||||
await waitFor(() => {
|
||||
expect(messaging!.transport.send).toHaveBeenCalledWith(
|
||||
"io.element.screenshare_start", expect.objectContaining({ desktopCapturerSourceId: sourceId }),
|
||||
"io.element.screenshare_start",
|
||||
expect.objectContaining({ desktopCapturerSourceId: sourceId }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("sends ScreenshareStop if we couldn't get a source id", async () => {
|
||||
jest.spyOn(Modal, "createDialog").mockReturnValue(
|
||||
{ finished: new Promise((r) => r([null])) } as IHandle<any[]>,
|
||||
);
|
||||
jest.spyOn(Modal, "createDialog").mockReturnValue({
|
||||
finished: new Promise((r) => r([null])),
|
||||
} as IHandle<any[]>);
|
||||
jest.spyOn(PlatformPeg.get(), "supportsDesktopCapturer").mockReturnValue(true);
|
||||
|
||||
await call.connect();
|
||||
@ -863,7 +887,8 @@ describe("ElementCall", () => {
|
||||
|
||||
await waitFor(() => {
|
||||
expect(messaging!.transport.send).toHaveBeenCalledWith(
|
||||
"io.element.screenshare_stop", expect.objectContaining({ }),
|
||||
"io.element.screenshare_stop",
|
||||
expect.objectContaining({}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -902,12 +927,14 @@ describe("ElementCall", () => {
|
||||
room.roomId,
|
||||
ElementCall.MEMBER_EVENT_TYPE.name,
|
||||
{
|
||||
"m.calls": [{
|
||||
"m.call_id": call.groupCall.groupCallId,
|
||||
"m.devices": [
|
||||
{ device_id: "bobweb", session_id: "1", feeds: [], expires_ts: 1000 * 60 * 10 },
|
||||
],
|
||||
}],
|
||||
"m.calls": [
|
||||
{
|
||||
"m.call_id": call.groupCall.groupCallId,
|
||||
"m.devices": [
|
||||
{ device_id: "bobweb", session_id: "1", feeds: [], expires_ts: 1000 * 60 * 10 },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
bob.userId,
|
||||
);
|
||||
@ -920,10 +947,12 @@ describe("ElementCall", () => {
|
||||
room.roomId,
|
||||
ElementCall.MEMBER_EVENT_TYPE.name,
|
||||
{
|
||||
"m.calls": [{
|
||||
"m.call_id": call.groupCall.groupCallId,
|
||||
"m.devices": [],
|
||||
}],
|
||||
"m.calls": [
|
||||
{
|
||||
"m.call_id": call.groupCall.groupCallId,
|
||||
"m.devices": [],
|
||||
},
|
||||
],
|
||||
},
|
||||
bob.userId,
|
||||
);
|
||||
|
Reference in New Issue
Block a user