2022-08-30 21:13:39 +02:00
|
|
|
/*
|
|
|
|
Copyright 2022 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 EventEmitter from "events";
|
|
|
|
import { mocked } from "jest-mock";
|
|
|
|
import { waitFor } from "@testing-library/react";
|
2024-03-20 15:27:29 +01:00
|
|
|
import {
|
|
|
|
RoomType,
|
|
|
|
Room,
|
|
|
|
RoomEvent,
|
|
|
|
MatrixEvent,
|
|
|
|
RoomStateEvent,
|
|
|
|
PendingEventOrdering,
|
|
|
|
IContent,
|
|
|
|
} from "matrix-js-sdk/src/matrix";
|
2024-03-18 15:40:52 +01:00
|
|
|
import { KnownMembership } from "matrix-js-sdk/src/types";
|
2022-08-30 21:13:39 +02:00
|
|
|
import { Widget } from "matrix-widget-api";
|
2023-10-30 16:14:27 +01:00
|
|
|
// eslint-disable-next-line no-restricted-imports
|
|
|
|
import { MatrixRTCSessionManagerEvents } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSessionManager";
|
|
|
|
// eslint-disable-next-line no-restricted-imports
|
|
|
|
import { CallMembership } from "matrix-js-sdk/src/matrixrtc/CallMembership";
|
|
|
|
// eslint-disable-next-line no-restricted-imports
|
|
|
|
import { MatrixRTCSession, MatrixRTCSessionEvent } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
2022-08-30 21:13:39 +02:00
|
|
|
|
|
|
|
import type { Mocked } from "jest-mock";
|
2023-08-09 09:18:41 +02:00
|
|
|
import type { MatrixClient, IMyDevice, RoomMember } from "matrix-js-sdk/src/matrix";
|
2022-08-30 21:13:39 +02:00
|
|
|
import type { ClientWidgetApi } from "matrix-widget-api";
|
2023-08-03 14:56:30 +02:00
|
|
|
import {
|
|
|
|
JitsiCallMemberContent,
|
|
|
|
Layout,
|
|
|
|
Call,
|
|
|
|
CallEvent,
|
|
|
|
ConnectionState,
|
|
|
|
JitsiCall,
|
|
|
|
ElementCall,
|
|
|
|
} from "../../src/models/Call";
|
2022-08-30 21:13:39 +02:00
|
|
|
import { stubClient, mkEvent, mkRoomMember, setupAsyncStoreWithClient, mockPlatformPeg } from "../test-utils";
|
|
|
|
import MediaDeviceHandler, { MediaDeviceKindEnum } from "../../src/MediaDeviceHandler";
|
|
|
|
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
|
|
|
|
import WidgetStore from "../../src/stores/WidgetStore";
|
|
|
|
import { WidgetMessagingStore } from "../../src/stores/widgets/WidgetMessagingStore";
|
|
|
|
import ActiveWidgetStore, { ActiveWidgetStoreEvent } from "../../src/stores/ActiveWidgetStore";
|
|
|
|
import { ElementWidgetActions } from "../../src/stores/widgets/ElementWidgetActions";
|
2022-09-16 17:12:27 +02:00
|
|
|
import SettingsStore from "../../src/settings/SettingsStore";
|
2022-12-22 13:09:57 +01:00
|
|
|
import { PosthogAnalytics } from "../../src/PosthogAnalytics";
|
2022-09-16 17:12:27 +02:00
|
|
|
|
|
|
|
jest.spyOn(MediaDeviceHandler, "getDevices").mockResolvedValue({
|
|
|
|
[MediaDeviceKindEnum.AudioInput]: [
|
2022-12-12 12:24:14 +01:00
|
|
|
{ deviceId: "1", groupId: "1", kind: "audioinput", label: "Headphones", toJSON: () => {} },
|
2022-09-16 17:12:27 +02:00
|
|
|
],
|
|
|
|
[MediaDeviceKindEnum.VideoInput]: [
|
2022-12-12 12:24:14 +01:00
|
|
|
{ deviceId: "2", groupId: "2", kind: "videoinput", label: "Built-in webcam", toJSON: () => {} },
|
2022-09-16 17:12:27 +02:00
|
|
|
],
|
|
|
|
[MediaDeviceKindEnum.AudioOutput]: [],
|
|
|
|
});
|
|
|
|
jest.spyOn(MediaDeviceHandler, "getAudioInput").mockReturnValue("1");
|
|
|
|
jest.spyOn(MediaDeviceHandler, "getVideoInput").mockReturnValue("2");
|
|
|
|
|
2022-09-27 13:54:51 +02:00
|
|
|
const enabledSettings = new Set(["feature_group_calls", "feature_video_rooms", "feature_element_call_video_rooms"]);
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation(
|
2022-12-12 12:24:14 +01:00
|
|
|
(settingName) => enabledSettings.has(settingName) || undefined,
|
2022-09-16 17:12:27 +02:00
|
|
|
);
|
|
|
|
|
2022-09-27 13:54:51 +02:00
|
|
|
const setUpClientRoomAndStores = (): {
|
2022-09-16 17:12:27 +02:00
|
|
|
client: Mocked<MatrixClient>;
|
|
|
|
room: Room;
|
|
|
|
alice: RoomMember;
|
|
|
|
bob: RoomMember;
|
|
|
|
carol: RoomMember;
|
|
|
|
} => {
|
|
|
|
stubClient();
|
2023-06-05 19:12:23 +02:00
|
|
|
const client = mocked<MatrixClient>(MatrixClientPeg.safeGet());
|
2022-09-16 17:12:27 +02:00
|
|
|
|
|
|
|
const room = new Room("!1:example.org", client, "@alice:example.org", {
|
|
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
|
|
});
|
|
|
|
|
|
|
|
const alice = mkRoomMember(room.roomId, "@alice:example.org");
|
|
|
|
const bob = mkRoomMember(room.roomId, "@bob:example.org");
|
|
|
|
const carol = mkRoomMember(room.roomId, "@carol:example.org");
|
2022-12-12 12:24:14 +01:00
|
|
|
jest.spyOn(room, "getMember").mockImplementation((userId) => {
|
2022-09-16 17:12:27 +02:00
|
|
|
switch (userId) {
|
2022-12-12 12:24:14 +01:00
|
|
|
case alice.userId:
|
|
|
|
return alice;
|
|
|
|
case bob.userId:
|
|
|
|
return bob;
|
|
|
|
case carol.userId:
|
|
|
|
return carol;
|
|
|
|
default:
|
|
|
|
return null;
|
2022-09-16 17:12:27 +02:00
|
|
|
}
|
|
|
|
});
|
2023-10-30 16:14:27 +01:00
|
|
|
|
2024-03-12 15:52:54 +01:00
|
|
|
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
2022-09-16 17:12:27 +02:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null));
|
2023-10-30 16:14:27 +01:00
|
|
|
client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null));
|
|
|
|
client.matrixRTC.getRoomSession.mockImplementation((roomId) => {
|
|
|
|
const session = new EventEmitter() as MatrixRTCSession;
|
|
|
|
session.memberships = [];
|
|
|
|
return session;
|
|
|
|
});
|
2022-09-16 17:12:27 +02:00
|
|
|
client.getRooms.mockReturnValue([room]);
|
|
|
|
client.getUserId.mockReturnValue(alice.userId);
|
2022-10-14 15:17:49 +02:00
|
|
|
client.getDeviceId.mockReturnValue("alices_device");
|
2022-09-16 17:12:27 +02:00
|
|
|
client.reEmitter.reEmit(room, [RoomStateEvent.Events]);
|
|
|
|
client.sendStateEvent.mockImplementation(async (roomId, eventType, content, stateKey = "") => {
|
|
|
|
if (roomId !== room.roomId) throw new Error("Unknown room");
|
|
|
|
const event = mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: eventType,
|
|
|
|
room: roomId,
|
|
|
|
user: alice.userId,
|
|
|
|
skey: stateKey,
|
2024-03-20 15:27:29 +01:00
|
|
|
content: content as IContent,
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
room.addLiveEvents([event]);
|
2023-02-16 10:38:44 +01:00
|
|
|
return { event_id: event.getId()! };
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
setupAsyncStoreWithClient(WidgetStore.instance, client);
|
|
|
|
setupAsyncStoreWithClient(WidgetMessagingStore.instance, client);
|
|
|
|
|
|
|
|
return { client, room, alice, bob, carol };
|
|
|
|
};
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
const cleanUpClientRoomAndStores = (client: MatrixClient, room: Room) => {
|
2022-09-16 17:12:27 +02:00
|
|
|
client.reEmitter.stopReEmitting(room, [RoomStateEvent.Events]);
|
|
|
|
};
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
const setUpWidget = (
|
|
|
|
call: Call,
|
|
|
|
): {
|
2022-09-16 17:12:27 +02:00
|
|
|
widget: Widget;
|
|
|
|
messaging: Mocked<ClientWidgetApi>;
|
|
|
|
audioMutedSpy: jest.SpyInstance<boolean, []>;
|
|
|
|
videoMutedSpy: jest.SpyInstance<boolean, []>;
|
|
|
|
} => {
|
2024-01-29 17:06:12 +01:00
|
|
|
call.widget.data = { ...call.widget, skipLobby: true };
|
2022-09-16 17:12:27 +02:00
|
|
|
const widget = new Widget(call.widget);
|
|
|
|
|
|
|
|
const eventEmitter = new EventEmitter();
|
|
|
|
const messaging = {
|
|
|
|
on: eventEmitter.on.bind(eventEmitter),
|
|
|
|
off: eventEmitter.off.bind(eventEmitter),
|
|
|
|
once: eventEmitter.once.bind(eventEmitter),
|
|
|
|
emit: eventEmitter.emit.bind(eventEmitter),
|
|
|
|
stop: jest.fn(),
|
|
|
|
transport: {
|
|
|
|
send: jest.fn(),
|
|
|
|
reply: jest.fn(),
|
|
|
|
},
|
|
|
|
} as unknown as Mocked<ClientWidgetApi>;
|
|
|
|
WidgetMessagingStore.instance.storeMessaging(widget, call.roomId, messaging);
|
|
|
|
|
|
|
|
const audioMutedSpy = jest.spyOn(MediaDeviceHandler, "startWithAudioMuted", "get");
|
|
|
|
const videoMutedSpy = jest.spyOn(MediaDeviceHandler, "startWithVideoMuted", "get");
|
|
|
|
|
|
|
|
return { widget, messaging, audioMutedSpy, videoMutedSpy };
|
|
|
|
};
|
|
|
|
|
|
|
|
const cleanUpCallAndWidget = (
|
|
|
|
call: Call,
|
|
|
|
widget: Widget,
|
|
|
|
audioMutedSpy: jest.SpyInstance<boolean, []>,
|
|
|
|
videoMutedSpy: jest.SpyInstance<boolean, []>,
|
|
|
|
) => {
|
|
|
|
call.destroy();
|
|
|
|
jest.clearAllMocks();
|
|
|
|
WidgetMessagingStore.instance.stopMessaging(widget, call.roomId);
|
|
|
|
audioMutedSpy.mockRestore();
|
|
|
|
videoMutedSpy.mockRestore();
|
|
|
|
};
|
2022-08-30 21:13:39 +02:00
|
|
|
|
|
|
|
describe("JitsiCall", () => {
|
|
|
|
mockPlatformPeg({ supportsJitsiScreensharing: () => true });
|
|
|
|
|
|
|
|
let client: Mocked<MatrixClient>;
|
|
|
|
let room: Room;
|
|
|
|
let alice: RoomMember;
|
|
|
|
let bob: RoomMember;
|
|
|
|
let carol: RoomMember;
|
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
beforeEach(() => {
|
2022-09-27 13:54:51 +02:00
|
|
|
({ client, room, alice, bob, carol } = setUpClientRoomAndStores());
|
|
|
|
jest.spyOn(room, "getType").mockReturnValue(RoomType.ElementVideo);
|
2022-08-30 21:13:39 +02:00
|
|
|
});
|
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
afterEach(() => cleanUpClientRoomAndStores(client, room));
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
describe("get", () => {
|
|
|
|
it("finds no calls", () => {
|
|
|
|
expect(Call.get(room)).toBeNull();
|
2022-08-30 21:13:39 +02:00
|
|
|
});
|
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
it("finds calls", async () => {
|
|
|
|
await JitsiCall.create(room);
|
|
|
|
expect(Call.get(room)).toBeInstanceOf(JitsiCall);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("ignores terminated calls", async () => {
|
|
|
|
await JitsiCall.create(room);
|
|
|
|
|
|
|
|
// Terminate the call
|
|
|
|
const [event] = room.currentState.getStateEvents("im.vector.modular.widgets");
|
|
|
|
await client.sendStateEvent(room.roomId, "im.vector.modular.widgets", {}, event.getStateKey()!);
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(Call.get(room)).toBeNull();
|
2022-08-30 21:13:39 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-27 13:54:51 +02:00
|
|
|
describe("instance in a video room", () => {
|
2022-09-16 17:12:27 +02:00
|
|
|
let call: JitsiCall;
|
|
|
|
let widget: Widget;
|
|
|
|
let messaging: Mocked<ClientWidgetApi>;
|
|
|
|
let audioMutedSpy: jest.SpyInstance<boolean, []>;
|
|
|
|
let videoMutedSpy: jest.SpyInstance<boolean, []>;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
jest.setSystemTime(0);
|
|
|
|
|
|
|
|
await JitsiCall.create(room);
|
|
|
|
const maybeCall = JitsiCall.get(room);
|
|
|
|
if (maybeCall === null) throw new Error("Failed to create call");
|
|
|
|
call = maybeCall;
|
|
|
|
|
|
|
|
({ widget, messaging, audioMutedSpy, videoMutedSpy } = setUpWidget(call));
|
|
|
|
|
2022-11-04 11:48:08 +01:00
|
|
|
mocked(messaging.transport).send.mockImplementation(async (action: string): Promise<any> => {
|
2022-09-16 17:12:27 +02:00
|
|
|
if (action === ElementWidgetActions.JoinCall) {
|
|
|
|
messaging.emit(
|
|
|
|
`action:${ElementWidgetActions.JoinCall}`,
|
|
|
|
new CustomEvent("widgetapirequest", { detail: {} }),
|
|
|
|
);
|
|
|
|
} else if (action === ElementWidgetActions.HangupCall) {
|
|
|
|
messaging.emit(
|
|
|
|
`action:${ElementWidgetActions.HangupCall}`,
|
|
|
|
new CustomEvent("widgetapirequest", { detail: {} }),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
});
|
|
|
|
});
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
afterEach(() => cleanUpCallAndWidget(call, widget, audioMutedSpy, videoMutedSpy));
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
it("connects muted", async () => {
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
audioMutedSpy.mockReturnValue(true);
|
|
|
|
videoMutedSpy.mockReturnValue(true);
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
expect(messaging.transport.send).toHaveBeenCalledWith(ElementWidgetActions.JoinCall, {
|
|
|
|
audioInput: null,
|
|
|
|
videoInput: null,
|
|
|
|
});
|
|
|
|
});
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
it("connects unmuted", async () => {
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
audioMutedSpy.mockReturnValue(false);
|
|
|
|
videoMutedSpy.mockReturnValue(false);
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
expect(messaging.transport.send).toHaveBeenCalledWith(ElementWidgetActions.JoinCall, {
|
|
|
|
audioInput: "Headphones",
|
|
|
|
videoInput: "Built-in webcam",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("waits for messaging when connecting", async () => {
|
|
|
|
// Temporarily remove the messaging to simulate connecting while the
|
|
|
|
// widget is still initializing
|
|
|
|
WidgetMessagingStore.instance.stopMessaging(widget, room.roomId);
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
const connect = call.start();
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.WidgetLoading);
|
2022-09-16 17:12:27 +02:00
|
|
|
|
|
|
|
WidgetMessagingStore.instance.storeMessaging(widget, room.roomId, messaging);
|
|
|
|
await connect;
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
});
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
it("doesn't stop messaging when connecting", async () => {
|
|
|
|
// Temporarily remove the messaging to simulate connecting while the
|
|
|
|
// widget is still initializing
|
|
|
|
jest.useFakeTimers();
|
|
|
|
const oldSendMock = messaging.transport.send;
|
|
|
|
mocked(messaging.transport).send.mockImplementation(async (action: string): Promise<any> => {
|
|
|
|
if (action === ElementWidgetActions.JoinCall) {
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
|
|
messaging.emit(
|
|
|
|
`action:${ElementWidgetActions.JoinCall}`,
|
|
|
|
new CustomEvent("widgetapirequest", { detail: {} }),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
|
|
|
|
const connect = call.start();
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.WidgetLoading);
|
|
|
|
async function runTimers() {
|
|
|
|
jest.advanceTimersByTime(500);
|
|
|
|
jest.advanceTimersByTime(1000);
|
|
|
|
}
|
|
|
|
async function runStopMessaging() {
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
|
|
WidgetMessagingStore.instance.stopMessaging(widget, room.roomId);
|
|
|
|
}
|
|
|
|
runStopMessaging();
|
|
|
|
runTimers();
|
|
|
|
let connectError;
|
|
|
|
try {
|
|
|
|
await connect;
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
connectError = e;
|
|
|
|
}
|
|
|
|
expect(connectError).toBeDefined();
|
|
|
|
// const connect2 = await connect;
|
|
|
|
// expect(connect2).toThrow();
|
|
|
|
messaging.transport.send = oldSendMock;
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
it("fails to connect if the widget returns an error", async () => {
|
|
|
|
mocked(messaging.transport).send.mockRejectedValue(new Error("never!!1! >:("));
|
2024-01-29 17:06:12 +01:00
|
|
|
await expect(call.start()).rejects.toBeDefined();
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("fails to disconnect if the widget returns an error", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
mocked(messaging.transport).send.mockRejectedValue(new Error("never!!1! >:("));
|
|
|
|
await expect(call.disconnect()).rejects.toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles remote disconnection", async () => {
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
const callback = jest.fn();
|
|
|
|
|
|
|
|
call.on(CallEvent.ConnectionState, callback);
|
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
messaging.emit(
|
|
|
|
`action:${ElementWidgetActions.HangupCall}`,
|
|
|
|
new CustomEvent("widgetapirequest", { detail: {} }),
|
|
|
|
);
|
2024-01-29 17:06:12 +01:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(callback).toHaveBeenNthCalledWith(1, ConnectionState.Disconnected, ConnectionState.Connected),
|
|
|
|
expect(callback).toHaveBeenNthCalledWith(
|
|
|
|
2,
|
|
|
|
ConnectionState.WidgetLoading,
|
|
|
|
ConnectionState.Disconnected,
|
2022-09-16 17:12:27 +02:00
|
|
|
);
|
2024-01-29 17:06:12 +01:00
|
|
|
expect(callback).toHaveBeenNthCalledWith(3, ConnectionState.Connecting, ConnectionState.WidgetLoading);
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
2024-01-29 17:06:12 +01:00
|
|
|
// in video rooms we expect the call to immediately reconnect
|
|
|
|
call.off(CallEvent.ConnectionState, callback);
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("disconnects", async () => {
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
await call.disconnect();
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
});
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
it("disconnects when we leave the room", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
2024-03-12 15:52:54 +01:00
|
|
|
room.emit(RoomEvent.MyMembership, room, KnownMembership.Leave);
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
});
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
it("reconnects after disconnect in video rooms", async () => {
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
await call.start();
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
await call.disconnect();
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
});
|
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
it("remains connected if we stay in the room", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
2024-03-12 15:52:54 +01:00
|
|
|
room.emit(RoomEvent.MyMembership, room, KnownMembership.Join);
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("tracks participants in room state", async () => {
|
2022-11-28 22:37:32 +01:00
|
|
|
expect(call.participants).toEqual(new Map());
|
2022-09-16 17:12:27 +02:00
|
|
|
|
|
|
|
// A participant with multiple devices (should only show up once)
|
|
|
|
await client.sendStateEvent(
|
|
|
|
room.roomId,
|
|
|
|
JitsiCall.MEMBER_EVENT_TYPE,
|
|
|
|
{ devices: ["bobweb", "bobdesktop"], expires_ts: 1000 * 60 * 10 },
|
|
|
|
bob.userId,
|
|
|
|
);
|
|
|
|
// A participant with an expired device (should not show up)
|
|
|
|
await client.sendStateEvent(
|
|
|
|
room.roomId,
|
|
|
|
JitsiCall.MEMBER_EVENT_TYPE,
|
|
|
|
{ devices: ["carolandroid"], expires_ts: -1000 * 60 },
|
|
|
|
carol.userId,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Now, stub out client.sendStateEvent so we can test our local echo
|
|
|
|
client.sendStateEvent.mockReset();
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(call.participants).toEqual(
|
|
|
|
new Map([
|
|
|
|
[alice, new Set(["alices_device"])],
|
|
|
|
[bob, new Set(["bobweb", "bobdesktop"])],
|
|
|
|
]),
|
|
|
|
);
|
2022-09-16 17:12:27 +02:00
|
|
|
|
|
|
|
await call.disconnect();
|
2022-11-28 22:37:32 +01:00
|
|
|
expect(call.participants).toEqual(new Map([[bob, new Set(["bobweb", "bobdesktop"])]]));
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("updates room state when connecting and disconnecting", async () => {
|
|
|
|
const now1 = Date.now();
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-12-12 12:24:14 +01:00
|
|
|
await waitFor(
|
|
|
|
() =>
|
|
|
|
expect(
|
2023-02-15 14:36:22 +01:00
|
|
|
room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, alice.userId)?.getContent(),
|
2022-12-12 12:24:14 +01:00
|
|
|
).toEqual({
|
|
|
|
devices: [client.getDeviceId()],
|
|
|
|
expires_ts: now1 + call.STUCK_DEVICE_TIMEOUT_MS,
|
|
|
|
}),
|
|
|
|
{ interval: 5 },
|
|
|
|
);
|
2022-09-16 17:12:27 +02:00
|
|
|
|
|
|
|
const now2 = Date.now();
|
|
|
|
await call.disconnect();
|
2022-12-12 12:24:14 +01:00
|
|
|
await waitFor(
|
|
|
|
() =>
|
|
|
|
expect(
|
2023-02-15 14:36:22 +01:00
|
|
|
room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, alice.userId)?.getContent(),
|
2022-12-12 12:24:14 +01:00
|
|
|
).toEqual({
|
|
|
|
devices: [],
|
|
|
|
expires_ts: now2 + call.STUCK_DEVICE_TIMEOUT_MS,
|
|
|
|
}),
|
|
|
|
{ interval: 5 },
|
|
|
|
);
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("repeatedly updates room state while connected", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-12-12 12:24:14 +01:00
|
|
|
await waitFor(
|
|
|
|
() =>
|
|
|
|
expect(client.sendStateEvent).toHaveBeenLastCalledWith(
|
|
|
|
room.roomId,
|
|
|
|
JitsiCall.MEMBER_EVENT_TYPE,
|
|
|
|
{ devices: [client.getDeviceId()], expires_ts: expect.any(Number) },
|
|
|
|
alice.userId,
|
|
|
|
),
|
|
|
|
{ interval: 5 },
|
|
|
|
);
|
2022-09-16 17:12:27 +02:00
|
|
|
|
|
|
|
client.sendStateEvent.mockClear();
|
|
|
|
jest.advanceTimersByTime(call.STUCK_DEVICE_TIMEOUT_MS);
|
2022-12-12 12:24:14 +01:00
|
|
|
await waitFor(
|
|
|
|
() =>
|
|
|
|
expect(client.sendStateEvent).toHaveBeenLastCalledWith(
|
|
|
|
room.roomId,
|
|
|
|
JitsiCall.MEMBER_EVENT_TYPE,
|
|
|
|
{ devices: [client.getDeviceId()], expires_ts: expect.any(Number) },
|
|
|
|
alice.userId,
|
|
|
|
),
|
|
|
|
{ interval: 5 },
|
|
|
|
);
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("emits events when connection state changes", async () => {
|
2022-10-07 04:27:28 +02:00
|
|
|
const onConnectionState = jest.fn();
|
2022-09-16 17:12:27 +02:00
|
|
|
call.on(CallEvent.ConnectionState, onConnectionState);
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
await call.disconnect();
|
2022-10-07 04:27:28 +02:00
|
|
|
expect(onConnectionState.mock.calls).toEqual([
|
2024-01-29 17:06:12 +01:00
|
|
|
[ConnectionState.WidgetLoading, ConnectionState.Disconnected],
|
|
|
|
[ConnectionState.Connecting, ConnectionState.WidgetLoading],
|
|
|
|
[ConnectionState.Lobby, ConnectionState.Connecting],
|
|
|
|
[ConnectionState.Connected, ConnectionState.Lobby],
|
2022-10-07 04:27:28 +02:00
|
|
|
[ConnectionState.Disconnecting, ConnectionState.Connected],
|
|
|
|
[ConnectionState.Disconnected, ConnectionState.Disconnecting],
|
2022-09-16 17:12:27 +02:00
|
|
|
]);
|
2022-10-07 04:27:28 +02:00
|
|
|
|
|
|
|
call.off(CallEvent.ConnectionState, onConnectionState);
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("emits events when participants change", async () => {
|
2022-10-07 04:27:28 +02:00
|
|
|
const onParticipants = jest.fn();
|
2022-09-16 17:12:27 +02:00
|
|
|
call.on(CallEvent.Participants, onParticipants);
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
await call.disconnect();
|
2022-10-07 04:27:28 +02:00
|
|
|
expect(onParticipants.mock.calls).toEqual([
|
2022-11-28 22:37:32 +01:00
|
|
|
[new Map([[alice, new Set(["alices_device"])]]), new Map()],
|
|
|
|
[new Map([[alice, new Set(["alices_device"])]]), new Map([[alice, new Set(["alices_device"])]])],
|
|
|
|
[new Map(), new Map([[alice, new Set(["alices_device"])]])],
|
|
|
|
[new Map(), new Map()],
|
2022-10-07 04:27:28 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
call.off(CallEvent.Participants, onParticipants);
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("switches to spotlight layout when the widget becomes a PiP", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
ActiveWidgetStore.instance.emit(ActiveWidgetStoreEvent.Undock);
|
|
|
|
expect(messaging.transport.send).toHaveBeenCalledWith(ElementWidgetActions.SpotlightLayout, {});
|
|
|
|
ActiveWidgetStore.instance.emit(ActiveWidgetStoreEvent.Dock);
|
|
|
|
expect(messaging.transport.send).toHaveBeenCalledWith(ElementWidgetActions.TileLayout, {});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("clean", () => {
|
|
|
|
const aliceWeb: IMyDevice = {
|
|
|
|
device_id: "aliceweb",
|
|
|
|
last_seen_ts: 0,
|
|
|
|
};
|
|
|
|
const aliceDesktop: IMyDevice = {
|
|
|
|
device_id: "alicedesktop",
|
|
|
|
last_seen_ts: 0,
|
|
|
|
};
|
|
|
|
const aliceDesktopOffline: IMyDevice = {
|
|
|
|
device_id: "alicedesktopoffline",
|
|
|
|
last_seen_ts: 1000 * 60 * 60 * -2, // 2 hours ago
|
|
|
|
};
|
|
|
|
const aliceDesktopNeverOnline: IMyDevice = {
|
|
|
|
device_id: "alicedesktopneveronline",
|
|
|
|
};
|
|
|
|
|
|
|
|
const mkContent = (devices: IMyDevice[]): JitsiCallMemberContent => ({
|
|
|
|
expires_ts: 1000 * 60 * 10,
|
2022-12-12 12:24:14 +01:00
|
|
|
devices: devices.map((d) => d.device_id),
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
2022-12-12 12:24:14 +01:00
|
|
|
const expectDevices = (devices: IMyDevice[]) =>
|
|
|
|
expect(
|
2023-02-15 14:36:22 +01:00
|
|
|
room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, alice.userId)?.getContent(),
|
2022-12-12 12:24:14 +01:00
|
|
|
).toEqual({
|
|
|
|
expires_ts: expect.any(Number),
|
|
|
|
devices: devices.map((d) => d.device_id),
|
|
|
|
});
|
2022-09-16 17:12:27 +02:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
client.getDeviceId.mockReturnValue(aliceWeb.device_id);
|
|
|
|
client.getDevices.mockResolvedValue({
|
2022-12-12 12:24:14 +01:00
|
|
|
devices: [aliceWeb, aliceDesktop, aliceDesktopOffline, aliceDesktopNeverOnline],
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("doesn't clean up valid devices", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await call.start();
|
2022-09-16 17:12:27 +02:00
|
|
|
await client.sendStateEvent(
|
|
|
|
room.roomId,
|
|
|
|
JitsiCall.MEMBER_EVENT_TYPE,
|
|
|
|
mkContent([aliceWeb, aliceDesktop]),
|
|
|
|
alice.userId,
|
2022-08-30 21:13:39 +02:00
|
|
|
);
|
2022-09-16 17:12:27 +02:00
|
|
|
|
|
|
|
await call.clean();
|
|
|
|
expectDevices([aliceWeb, aliceDesktop]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("cleans up our own device if we're disconnected", async () => {
|
|
|
|
await client.sendStateEvent(
|
|
|
|
room.roomId,
|
|
|
|
JitsiCall.MEMBER_EVENT_TYPE,
|
|
|
|
mkContent([aliceWeb, aliceDesktop]),
|
|
|
|
alice.userId,
|
2022-08-30 21:13:39 +02:00
|
|
|
);
|
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
await call.clean();
|
|
|
|
expectDevices([aliceDesktop]);
|
|
|
|
});
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
it("cleans up devices that have been offline for too long", async () => {
|
|
|
|
await client.sendStateEvent(
|
|
|
|
room.roomId,
|
|
|
|
JitsiCall.MEMBER_EVENT_TYPE,
|
|
|
|
mkContent([aliceDesktop, aliceDesktopOffline]),
|
|
|
|
alice.userId,
|
|
|
|
);
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
await call.clean();
|
|
|
|
expectDevices([aliceDesktop]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("cleans up devices that have never been online", async () => {
|
|
|
|
await client.sendStateEvent(
|
|
|
|
room.roomId,
|
|
|
|
JitsiCall.MEMBER_EVENT_TYPE,
|
|
|
|
mkContent([aliceDesktop, aliceDesktopNeverOnline]),
|
|
|
|
alice.userId,
|
|
|
|
);
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
await call.clean();
|
|
|
|
expectDevices([aliceDesktop]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("no-ops if there are no state events", async () => {
|
|
|
|
await call.clean();
|
|
|
|
expect(room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, alice.userId)).toBe(null);
|
|
|
|
});
|
|
|
|
});
|
2022-08-30 21:13:39 +02:00
|
|
|
});
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("ElementCall", () => {
|
|
|
|
let client: Mocked<MatrixClient>;
|
|
|
|
let room: Room;
|
|
|
|
let alice: RoomMember;
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
function setRoomMembers(memberIds: string[]) {
|
|
|
|
jest.spyOn(room, "getJoinedMembers").mockReturnValue(memberIds.map((id) => ({ userId: id }) as RoomMember));
|
|
|
|
}
|
|
|
|
|
|
|
|
const callConnectProcedure: (call: ElementCall) => Promise<void> = async (call) => {
|
|
|
|
async function sessionConnect() {
|
|
|
|
await new Promise<void>((r) => {
|
|
|
|
setTimeout(() => r(), 400);
|
|
|
|
});
|
|
|
|
client.matrixRTC.emit(MatrixRTCSessionManagerEvents.SessionStarted, call.roomId, {
|
|
|
|
sessionId: undefined,
|
|
|
|
} as unknown as MatrixRTCSession);
|
|
|
|
call.session?.emit(
|
|
|
|
MatrixRTCSessionEvent.MembershipsChanged,
|
|
|
|
[],
|
|
|
|
[{ sender: client.getUserId() } as CallMembership],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
async function runTimers() {
|
|
|
|
jest.advanceTimersByTime(500);
|
|
|
|
jest.advanceTimersByTime(500);
|
|
|
|
}
|
|
|
|
sessionConnect();
|
|
|
|
const promise = call.start();
|
|
|
|
runTimers();
|
|
|
|
await promise;
|
|
|
|
};
|
|
|
|
const callDisconnectionProcedure: (call: ElementCall) => Promise<void> = async (call) => {
|
|
|
|
async function sessionDisconnect() {
|
|
|
|
await new Promise<void>((r) => {
|
|
|
|
setTimeout(() => r(), 400);
|
|
|
|
});
|
|
|
|
client.matrixRTC.emit(MatrixRTCSessionManagerEvents.SessionStarted, call.roomId, {
|
|
|
|
sessionId: undefined,
|
|
|
|
} as unknown as MatrixRTCSession);
|
|
|
|
call.session?.emit(MatrixRTCSessionEvent.MembershipsChanged, [], []);
|
|
|
|
}
|
|
|
|
async function runTimers() {
|
|
|
|
jest.advanceTimersByTime(500);
|
|
|
|
jest.advanceTimersByTime(500);
|
|
|
|
}
|
|
|
|
sessionDisconnect();
|
|
|
|
const promise = call.disconnect();
|
|
|
|
runTimers();
|
|
|
|
await promise;
|
|
|
|
};
|
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
beforeEach(() => {
|
2024-01-29 17:06:12 +01:00
|
|
|
jest.useFakeTimers();
|
2023-10-30 16:14:27 +01:00
|
|
|
({ client, room, alice } = setUpClientRoomAndStores());
|
2022-08-30 21:13:39 +02:00
|
|
|
});
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
afterEach(() => {
|
|
|
|
jest.useRealTimers();
|
|
|
|
cleanUpClientRoomAndStores(client, room);
|
|
|
|
});
|
2022-08-30 21:13:39 +02:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
describe("get", () => {
|
|
|
|
it("finds no calls", () => {
|
|
|
|
expect(Call.get(room)).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("finds calls", async () => {
|
|
|
|
await ElementCall.create(room);
|
|
|
|
expect(Call.get(room)).toBeInstanceOf(ElementCall);
|
2023-11-07 13:29:05 +01:00
|
|
|
Call.get(room)?.destroy();
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
2023-10-30 16:14:27 +01:00
|
|
|
it("finds ongoing calls that are created by the session manager", async () => {
|
|
|
|
// There is an existing session created by another user in this room.
|
|
|
|
client.matrixRTC.getRoomSession.mockReturnValue({
|
|
|
|
on: (ev: any, fn: any) => {},
|
2023-11-07 13:29:05 +01:00
|
|
|
off: (ev: any, fn: any) => {},
|
2023-10-30 16:14:27 +01:00
|
|
|
memberships: [{ fakeVal: "fake membership" }],
|
|
|
|
} as unknown as MatrixRTCSession);
|
2022-11-28 22:37:32 +01:00
|
|
|
const call = Call.get(room);
|
|
|
|
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
|
2023-11-07 13:29:05 +01:00
|
|
|
call.destroy();
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
2022-12-14 14:23:26 +01:00
|
|
|
|
|
|
|
it("passes font settings through widget URL", async () => {
|
|
|
|
const originalGetValue = SettingsStore.getValue;
|
|
|
|
SettingsStore.getValue = <T>(name: string, roomId?: string, excludeDefault?: boolean) => {
|
|
|
|
switch (name) {
|
2024-02-21 12:23:07 +01:00
|
|
|
case "fontSizeDelta":
|
|
|
|
return 4 as T;
|
2022-12-14 14:23:26 +01:00
|
|
|
case "useSystemFont":
|
|
|
|
return true as T;
|
|
|
|
case "systemFont":
|
|
|
|
return "OpenDyslexic, DejaVu Sans" as T;
|
|
|
|
default:
|
|
|
|
return originalGetValue<T>(name, roomId, excludeDefault);
|
|
|
|
}
|
|
|
|
};
|
2024-02-21 12:23:07 +01:00
|
|
|
document.documentElement.style.fontSize = "12px";
|
2022-12-14 14:23:26 +01:00
|
|
|
|
|
|
|
await ElementCall.create(room);
|
|
|
|
const call = Call.get(room);
|
|
|
|
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
|
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(new URL(call.widget.url).hash.slice(1));
|
2024-02-21 12:23:07 +01:00
|
|
|
expect(urlParams.get("fontScale")).toBe("1.5");
|
2022-12-14 14:23:26 +01:00
|
|
|
expect(urlParams.getAll("font")).toEqual(["OpenDyslexic", "DejaVu Sans"]);
|
|
|
|
|
|
|
|
SettingsStore.getValue = originalGetValue;
|
|
|
|
});
|
2022-12-22 13:09:57 +01:00
|
|
|
|
2023-06-07 15:29:39 +02:00
|
|
|
it("passes ICE fallback preference through widget URL", async () => {
|
|
|
|
// Test with the preference set to false
|
|
|
|
await ElementCall.create(room);
|
|
|
|
const call1 = Call.get(room);
|
|
|
|
if (!(call1 instanceof ElementCall)) throw new Error("Failed to create call");
|
|
|
|
|
|
|
|
const urlParams1 = new URLSearchParams(new URL(call1.widget.url).hash.slice(1));
|
|
|
|
expect(urlParams1.has("allowIceFallback")).toBe(false);
|
2023-11-07 13:29:05 +01:00
|
|
|
call1.destroy();
|
2023-06-07 15:29:39 +02:00
|
|
|
|
|
|
|
// Now test with the preference set to true
|
|
|
|
const originalGetValue = SettingsStore.getValue;
|
|
|
|
SettingsStore.getValue = <T>(name: string, roomId?: string, excludeDefault?: boolean) => {
|
|
|
|
switch (name) {
|
|
|
|
case "fallbackICEServerAllowed":
|
|
|
|
return true as T;
|
|
|
|
default:
|
|
|
|
return originalGetValue<T>(name, roomId, excludeDefault);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-11-07 13:29:05 +01:00
|
|
|
ElementCall.create(room);
|
2023-06-07 15:29:39 +02:00
|
|
|
const call2 = Call.get(room);
|
|
|
|
if (!(call2 instanceof ElementCall)) throw new Error("Failed to create call");
|
|
|
|
|
|
|
|
const urlParams2 = new URLSearchParams(new URL(call2.widget.url).hash.slice(1));
|
|
|
|
expect(urlParams2.has("allowIceFallback")).toBe(true);
|
|
|
|
|
2023-11-07 13:29:05 +01:00
|
|
|
call2.destroy();
|
2023-06-07 15:29:39 +02:00
|
|
|
SettingsStore.getValue = originalGetValue;
|
|
|
|
});
|
|
|
|
|
2022-12-22 13:09:57 +01:00
|
|
|
it("passes analyticsID through widget URL", async () => {
|
|
|
|
client.getAccountData.mockImplementation((eventType: string) => {
|
|
|
|
if (eventType === PosthogAnalytics.ANALYTICS_EVENT_TYPE) {
|
|
|
|
return new MatrixEvent({ content: { id: "123456789987654321", pseudonymousAnalyticsOptIn: true } });
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
await ElementCall.create(room);
|
|
|
|
const call = Call.get(room);
|
|
|
|
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
|
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(new URL(call.widget.url).hash.slice(1));
|
|
|
|
expect(urlParams.get("analyticsID")).toBe("123456789987654321");
|
2023-11-07 13:29:05 +01:00
|
|
|
call.destroy();
|
2022-12-22 13:09:57 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("does not pass analyticsID if `pseudonymousAnalyticsOptIn` set to false", async () => {
|
|
|
|
client.getAccountData.mockImplementation((eventType: string) => {
|
|
|
|
if (eventType === PosthogAnalytics.ANALYTICS_EVENT_TYPE) {
|
|
|
|
return new MatrixEvent({
|
|
|
|
content: { id: "123456789987654321", pseudonymousAnalyticsOptIn: false },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
await ElementCall.create(room);
|
|
|
|
const call = Call.get(room);
|
|
|
|
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
|
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(new URL(call.widget.url).hash.slice(1));
|
|
|
|
expect(urlParams.get("analyticsID")).toBe("");
|
2024-01-29 17:06:12 +01:00
|
|
|
call.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("passes feature_allow_screen_share_only_mode setting to allowVoipWithNoMedia url param", async () => {
|
|
|
|
// Now test with the preference set to true
|
|
|
|
const originalGetValue = SettingsStore.getValue;
|
|
|
|
SettingsStore.getValue = <T>(name: string, roomId?: string, excludeDefault?: boolean) => {
|
|
|
|
switch (name) {
|
|
|
|
case "feature_allow_screen_share_only_mode":
|
|
|
|
return true as T;
|
|
|
|
default:
|
|
|
|
return originalGetValue<T>(name, roomId, excludeDefault);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
await ElementCall.create(room);
|
|
|
|
const call = Call.get(room);
|
|
|
|
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
|
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(new URL(call.widget.url).hash.slice(1));
|
|
|
|
expect(urlParams.get("allowVoipWithNoMedia")).toBe("true");
|
|
|
|
SettingsStore.getValue = originalGetValue;
|
|
|
|
call.destroy();
|
2022-12-22 13:09:57 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("passes empty analyticsID if the id is not in the account data", async () => {
|
|
|
|
client.getAccountData.mockImplementation((eventType: string) => {
|
|
|
|
if (eventType === PosthogAnalytics.ANALYTICS_EVENT_TYPE) {
|
|
|
|
return new MatrixEvent({ content: {} });
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
await ElementCall.create(room);
|
|
|
|
const call = Call.get(room);
|
|
|
|
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
|
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(new URL(call.widget.url).hash.slice(1));
|
|
|
|
expect(urlParams.get("analyticsID")).toBe("");
|
|
|
|
});
|
2022-08-30 21:13:39 +02:00
|
|
|
});
|
|
|
|
|
2022-09-27 13:54:51 +02:00
|
|
|
describe("instance in a non-video room", () => {
|
2022-09-16 17:12:27 +02:00
|
|
|
let call: ElementCall;
|
|
|
|
let widget: Widget;
|
|
|
|
let messaging: Mocked<ClientWidgetApi>;
|
|
|
|
let audioMutedSpy: jest.SpyInstance<boolean, []>;
|
|
|
|
let videoMutedSpy: jest.SpyInstance<boolean, []>;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
jest.setSystemTime(0);
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
await ElementCall.create(room, true);
|
2022-09-16 17:12:27 +02:00
|
|
|
const maybeCall = ElementCall.get(room);
|
|
|
|
if (maybeCall === null) throw new Error("Failed to create call");
|
|
|
|
call = maybeCall;
|
|
|
|
|
|
|
|
({ widget, messaging, audioMutedSpy, videoMutedSpy } = setUpWidget(call));
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => cleanUpCallAndWidget(call, widget, audioMutedSpy, videoMutedSpy));
|
2024-01-29 17:06:12 +01:00
|
|
|
// TODO refactor initial device configuration to use the EW settings.
|
|
|
|
// Add tests for passing EW device configuration to the widget.
|
2022-09-16 17:12:27 +02:00
|
|
|
it("waits for messaging when connecting", async () => {
|
|
|
|
// Temporarily remove the messaging to simulate connecting while the
|
|
|
|
// widget is still initializing
|
2024-01-29 17:06:12 +01:00
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
WidgetMessagingStore.instance.stopMessaging(widget, room.roomId);
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
const connect = callConnectProcedure(call);
|
|
|
|
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.WidgetLoading);
|
2022-09-16 17:12:27 +02:00
|
|
|
|
|
|
|
WidgetMessagingStore.instance.storeMessaging(widget, room.roomId, messaging);
|
|
|
|
await connect;
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("fails to connect if the widget returns an error", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
// we only send a JoinCall action if the widget is preloading
|
|
|
|
call.widget.data = { ...call.widget, preload: true };
|
2022-09-16 17:12:27 +02:00
|
|
|
mocked(messaging.transport).send.mockRejectedValue(new Error("never!!1! >:("));
|
2024-01-29 17:06:12 +01:00
|
|
|
await expect(call.start()).rejects.toBeDefined();
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("fails to disconnect if the widget returns an error", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2022-09-16 17:12:27 +02:00
|
|
|
mocked(messaging.transport).send.mockRejectedValue(new Error("never!!1! >:("));
|
|
|
|
await expect(call.disconnect()).rejects.toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles remote disconnection", async () => {
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
|
|
|
|
messaging.emit(
|
|
|
|
`action:${ElementWidgetActions.HangupCall}`,
|
|
|
|
new CustomEvent("widgetapirequest", { detail: {} }),
|
|
|
|
);
|
|
|
|
await waitFor(() => expect(call.connectionState).toBe(ConnectionState.Disconnected), { interval: 5 });
|
|
|
|
});
|
|
|
|
|
|
|
|
it("disconnects", async () => {
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
2024-01-29 17:06:12 +01:00
|
|
|
await callDisconnectionProcedure(call);
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("disconnects when we leave the room", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
2024-03-12 15:52:54 +01:00
|
|
|
room.emit(RoomEvent.MyMembership, room, KnownMembership.Leave);
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("remains connected if we stay in the room", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
2024-03-12 15:52:54 +01:00
|
|
|
room.emit(RoomEvent.MyMembership, room, KnownMembership.Join);
|
2022-09-16 17:12:27 +02:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
});
|
|
|
|
|
2023-01-04 21:51:42 +01:00
|
|
|
it("disconnects if the widget dies", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2023-01-04 21:51:42 +01:00
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
WidgetMessagingStore.instance.stopMessaging(widget, room.roomId);
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
});
|
|
|
|
|
2022-10-07 04:27:28 +02:00
|
|
|
it("tracks layout", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2022-10-07 04:27:28 +02:00
|
|
|
expect(call.layout).toBe(Layout.Tile);
|
|
|
|
|
|
|
|
messaging.emit(
|
|
|
|
`action:${ElementWidgetActions.SpotlightLayout}`,
|
|
|
|
new CustomEvent("widgetapirequest", { detail: {} }),
|
|
|
|
);
|
|
|
|
expect(call.layout).toBe(Layout.Spotlight);
|
|
|
|
|
|
|
|
messaging.emit(
|
|
|
|
`action:${ElementWidgetActions.TileLayout}`,
|
|
|
|
new CustomEvent("widgetapirequest", { detail: {} }),
|
|
|
|
);
|
|
|
|
expect(call.layout).toBe(Layout.Tile);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets layout", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2022-10-07 04:27:28 +02:00
|
|
|
|
|
|
|
await call.setLayout(Layout.Spotlight);
|
|
|
|
expect(messaging.transport.send).toHaveBeenCalledWith(ElementWidgetActions.SpotlightLayout, {});
|
|
|
|
|
|
|
|
await call.setLayout(Layout.Tile);
|
|
|
|
expect(messaging.transport.send).toHaveBeenCalledWith(ElementWidgetActions.TileLayout, {});
|
|
|
|
});
|
|
|
|
|
2022-09-16 17:12:27 +02:00
|
|
|
it("emits events when connection state changes", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
// const wait = jest.spyOn(CallModule, "waitForEvent");
|
2022-10-07 04:27:28 +02:00
|
|
|
const onConnectionState = jest.fn();
|
2022-09-16 17:12:27 +02:00
|
|
|
call.on(CallEvent.ConnectionState, onConnectionState);
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
|
|
|
await callDisconnectionProcedure(call);
|
2022-10-07 04:27:28 +02:00
|
|
|
expect(onConnectionState.mock.calls).toEqual([
|
2024-01-29 17:06:12 +01:00
|
|
|
[ConnectionState.WidgetLoading, ConnectionState.Disconnected],
|
|
|
|
[ConnectionState.Connecting, ConnectionState.WidgetLoading],
|
2022-10-07 04:27:28 +02:00
|
|
|
[ConnectionState.Connected, ConnectionState.Connecting],
|
|
|
|
[ConnectionState.Disconnecting, ConnectionState.Connected],
|
|
|
|
[ConnectionState.Disconnected, ConnectionState.Disconnecting],
|
2022-09-16 17:12:27 +02:00
|
|
|
]);
|
2022-10-07 04:27:28 +02:00
|
|
|
|
|
|
|
call.off(CallEvent.ConnectionState, onConnectionState);
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("emits events when participants change", async () => {
|
2022-10-07 04:27:28 +02:00
|
|
|
const onParticipants = jest.fn();
|
2023-10-30 16:14:27 +01:00
|
|
|
call.session.memberships = [{ sender: alice.userId, deviceId: "alices_device" } as CallMembership];
|
2022-09-16 17:12:27 +02:00
|
|
|
call.on(CallEvent.Participants, onParticipants);
|
2023-10-30 16:14:27 +01:00
|
|
|
call.session.emit(MatrixRTCSessionEvent.MembershipsChanged, [], []);
|
2022-09-16 17:12:27 +02:00
|
|
|
|
2023-10-30 16:14:27 +01:00
|
|
|
expect(onParticipants.mock.calls).toEqual([[new Map([[alice, new Set(["alices_device"])]]), new Map()]]);
|
2022-10-07 04:27:28 +02:00
|
|
|
|
|
|
|
call.off(CallEvent.Participants, onParticipants);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("emits events when layout changes", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2022-10-07 04:27:28 +02:00
|
|
|
const onLayout = jest.fn();
|
|
|
|
call.on(CallEvent.Layout, onLayout);
|
|
|
|
|
|
|
|
messaging.emit(
|
|
|
|
`action:${ElementWidgetActions.SpotlightLayout}`,
|
|
|
|
new CustomEvent("widgetapirequest", { detail: {} }),
|
|
|
|
);
|
|
|
|
messaging.emit(
|
|
|
|
`action:${ElementWidgetActions.TileLayout}`,
|
|
|
|
new CustomEvent("widgetapirequest", { detail: {} }),
|
|
|
|
);
|
|
|
|
expect(onLayout.mock.calls).toEqual([[Layout.Spotlight], [Layout.Tile]]);
|
|
|
|
|
|
|
|
call.off(CallEvent.Layout, onLayout);
|
2022-09-16 17:12:27 +02:00
|
|
|
});
|
|
|
|
|
2023-10-30 16:14:27 +01:00
|
|
|
it("ends the call immediately if the session ended", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2022-09-27 13:54:51 +02:00
|
|
|
const onDestroy = jest.fn();
|
|
|
|
call.on(CallEvent.Destroy, onDestroy);
|
2024-01-29 17:06:12 +01:00
|
|
|
await callDisconnectionProcedure(call);
|
2023-10-30 16:14:27 +01:00
|
|
|
// this will be called automatically
|
|
|
|
// disconnect -> widget sends state event -> session manager notices no-one left
|
|
|
|
client.matrixRTC.emit(
|
|
|
|
MatrixRTCSessionManagerEvents.SessionEnded,
|
2022-09-27 13:54:51 +02:00
|
|
|
room.roomId,
|
2023-10-30 16:14:27 +01:00
|
|
|
{} as unknown as MatrixRTCSession,
|
2022-09-27 13:54:51 +02:00
|
|
|
);
|
|
|
|
expect(onDestroy).toHaveBeenCalled();
|
|
|
|
call.off(CallEvent.Destroy, onDestroy);
|
|
|
|
});
|
2023-04-21 15:54:27 +02:00
|
|
|
|
|
|
|
it("clears widget persistence when destroyed", async () => {
|
|
|
|
const destroyPersistentWidgetSpy = jest.spyOn(ActiveWidgetStore.instance, "destroyPersistentWidget");
|
|
|
|
call.destroy();
|
|
|
|
expect(destroyPersistentWidgetSpy).toHaveBeenCalled();
|
|
|
|
});
|
2023-11-10 17:46:02 +01:00
|
|
|
|
|
|
|
it("the perParticipantE2EE url flag is used in encrypted rooms while respecting the feature_disable_call_per_sender_encryption flag", async () => {
|
|
|
|
// We destroy the call created in beforeEach because we test the call creation process.
|
|
|
|
call.destroy();
|
|
|
|
const addWidgetSpy = jest.spyOn(WidgetStore.instance, "addVirtualWidget");
|
|
|
|
// If a room is not encrypted we will never add the perParticipantE2EE flag.
|
2024-03-28 13:25:00 +01:00
|
|
|
const roomSpy = jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(true);
|
2023-11-10 17:46:02 +01:00
|
|
|
|
|
|
|
// should create call with perParticipantE2EE flag
|
|
|
|
ElementCall.create(room);
|
2024-01-29 17:06:12 +01:00
|
|
|
expect(Call.get(room)?.widget?.data?.perParticipantE2EE).toBe(true);
|
2023-11-10 17:46:02 +01:00
|
|
|
|
|
|
|
// should create call without perParticipantE2EE flag
|
|
|
|
enabledSettings.add("feature_disable_call_per_sender_encryption");
|
2024-01-29 17:06:12 +01:00
|
|
|
expect(Call.get(room)?.widget?.data?.perParticipantE2EE).toBe(false);
|
2023-11-10 17:46:02 +01:00
|
|
|
enabledSettings.delete("feature_disable_call_per_sender_encryption");
|
2024-03-28 13:25:00 +01:00
|
|
|
roomSpy.mockRestore();
|
2023-11-10 17:46:02 +01:00
|
|
|
addWidgetSpy.mockRestore();
|
|
|
|
});
|
2024-01-29 17:06:12 +01:00
|
|
|
|
|
|
|
it("sends notify event on connect in a room with more than two members", async () => {
|
|
|
|
const sendEventSpy = jest.spyOn(room.client, "sendEvent");
|
|
|
|
await ElementCall.create(room);
|
|
|
|
await callConnectProcedure(Call.get(room) as ElementCall);
|
|
|
|
expect(sendEventSpy).toHaveBeenCalledWith("!1:example.org", "org.matrix.msc4075.call.notify", {
|
|
|
|
"application": "m.call",
|
|
|
|
"call_id": "",
|
|
|
|
"m.mentions": { room: true, user_ids: [] },
|
|
|
|
"notify_type": "notify",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it("sends ring on create in a DM (two participants) room", async () => {
|
|
|
|
setRoomMembers(["@user:example.com", "@user2:example.com"]);
|
|
|
|
|
|
|
|
const sendEventSpy = jest.spyOn(room.client, "sendEvent");
|
|
|
|
await ElementCall.create(room);
|
|
|
|
await callConnectProcedure(Call.get(room) as ElementCall);
|
|
|
|
expect(sendEventSpy).toHaveBeenCalledWith("!1:example.org", "org.matrix.msc4075.call.notify", {
|
|
|
|
"application": "m.call",
|
|
|
|
"call_id": "",
|
|
|
|
"m.mentions": { room: true, user_ids: [] },
|
|
|
|
"notify_type": "ring",
|
|
|
|
});
|
|
|
|
});
|
2022-08-30 21:13:39 +02:00
|
|
|
});
|
2022-09-27 13:54:51 +02:00
|
|
|
|
|
|
|
describe("instance in a video room", () => {
|
|
|
|
let call: ElementCall;
|
|
|
|
let widget: Widget;
|
2024-01-29 17:06:12 +01:00
|
|
|
let messaging: Mocked<ClientWidgetApi>;
|
2022-09-27 13:54:51 +02:00
|
|
|
let audioMutedSpy: jest.SpyInstance<boolean, []>;
|
|
|
|
let videoMutedSpy: jest.SpyInstance<boolean, []>;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
jest.setSystemTime(0);
|
|
|
|
|
|
|
|
jest.spyOn(room, "getType").mockReturnValue(RoomType.UnstableCall);
|
|
|
|
|
|
|
|
await ElementCall.create(room);
|
|
|
|
const maybeCall = ElementCall.get(room);
|
|
|
|
if (maybeCall === null) throw new Error("Failed to create call");
|
|
|
|
call = maybeCall;
|
|
|
|
|
2024-01-29 17:06:12 +01:00
|
|
|
({ widget, messaging, audioMutedSpy, videoMutedSpy } = setUpWidget(call));
|
2022-09-27 13:54:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => cleanUpCallAndWidget(call, widget, audioMutedSpy, videoMutedSpy));
|
|
|
|
|
|
|
|
it("doesn't end the call when the last participant leaves", async () => {
|
2024-01-29 17:06:12 +01:00
|
|
|
await callConnectProcedure(call);
|
2022-09-27 13:54:51 +02:00
|
|
|
const onDestroy = jest.fn();
|
|
|
|
call.on(CallEvent.Destroy, onDestroy);
|
2024-01-29 17:06:12 +01:00
|
|
|
await callDisconnectionProcedure(call);
|
2022-09-27 13:54:51 +02:00
|
|
|
expect(onDestroy).not.toHaveBeenCalled();
|
|
|
|
call.off(CallEvent.Destroy, onDestroy);
|
|
|
|
});
|
2024-01-29 17:06:12 +01:00
|
|
|
|
|
|
|
it("connect to call with ongoing session", async () => {
|
|
|
|
// Mock membership getter used by `roomSessionForRoom`.
|
|
|
|
// This makes sure the roomSession will not be empty.
|
|
|
|
jest.spyOn(MatrixRTCSession, "callMembershipsForRoom").mockImplementation(() => [
|
|
|
|
{ fakeVal: "fake membership", getMsUntilExpiry: () => 1000 } as unknown as CallMembership,
|
|
|
|
]);
|
|
|
|
// Create ongoing session
|
|
|
|
const roomSession = MatrixRTCSession.roomSessionForRoom(client, room);
|
|
|
|
const roomSessionEmitSpy = jest.spyOn(roomSession, "emit");
|
|
|
|
|
|
|
|
// Make sure the created session ends up in the call.
|
|
|
|
// `getActiveRoomSession` will be used during `call.connect`
|
|
|
|
// `getRoomSession` will be used during `Call.get`
|
|
|
|
client.matrixRTC.getActiveRoomSession.mockImplementation(() => {
|
|
|
|
return roomSession;
|
|
|
|
});
|
|
|
|
client.matrixRTC.getRoomSession.mockImplementation(() => {
|
|
|
|
return roomSession;
|
|
|
|
});
|
|
|
|
|
|
|
|
await ElementCall.create(room);
|
|
|
|
const call = Call.get(room);
|
|
|
|
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
|
|
|
|
expect(call.session).toBe(roomSession);
|
|
|
|
await callConnectProcedure(call);
|
|
|
|
expect(roomSessionEmitSpy).toHaveBeenCalledWith(
|
|
|
|
"memberships_changed",
|
|
|
|
[],
|
|
|
|
[{ sender: "@alice:example.org" }],
|
|
|
|
);
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
call.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles remote disconnection and reconnect right after", async () => {
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
|
|
|
await callConnectProcedure(call);
|
|
|
|
expect(call.connectionState).toBe(ConnectionState.Connected);
|
|
|
|
|
|
|
|
messaging.emit(
|
|
|
|
`action:${ElementWidgetActions.HangupCall}`,
|
|
|
|
new CustomEvent("widgetapirequest", { detail: {} }),
|
|
|
|
);
|
|
|
|
// We want the call to be connecting after the hangup.
|
|
|
|
waitFor(() => expect(call.connectionState).toBe(ConnectionState.Connecting), { interval: 5 });
|
|
|
|
});
|
2022-09-27 13:54:51 +02:00
|
|
|
});
|
2023-11-21 18:12:08 +01:00
|
|
|
describe("create call", () => {
|
|
|
|
beforeEach(async () => {
|
2023-11-22 13:08:16 +01:00
|
|
|
setRoomMembers(["@user:example.com", "@user2:example.com", "@user4:example.com"]);
|
2023-11-21 18:12:08 +01:00
|
|
|
});
|
|
|
|
it("don't sent notify event if there are existing room call members", async () => {
|
|
|
|
jest.spyOn(MatrixRTCSession, "callMembershipsForRoom").mockReturnValue([
|
|
|
|
{ application: "m.call", callId: "" } as unknown as CallMembership,
|
|
|
|
]);
|
|
|
|
const sendEventSpy = jest.spyOn(room.client, "sendEvent");
|
|
|
|
await ElementCall.create(room);
|
|
|
|
expect(sendEventSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2022-08-30 21:13:39 +02:00
|
|
|
});
|