2022-11-10 08:38:48 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-11-10 08:38:48 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-11-10 08:38:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { mocked } from "jest-mock";
|
2023-08-10 08:01:14 +00:00
|
|
|
import { MatrixClient, MatrixEvent, Room, SyncState } from "matrix-js-sdk/src/matrix";
|
2022-11-10 08:38:48 +00:00
|
|
|
|
2023-01-09 15:08:30 +00:00
|
|
|
import Modal from "../../../src/Modal";
|
2022-11-10 08:38:48 +00:00
|
|
|
import {
|
2022-11-30 10:16:22 +00:00
|
|
|
VoiceBroadcastInfoState,
|
|
|
|
VoiceBroadcastPlayback,
|
|
|
|
VoiceBroadcastPlaybacksStore,
|
2022-11-10 08:38:48 +00:00
|
|
|
VoiceBroadcastPreRecording,
|
|
|
|
VoiceBroadcastPreRecordingStore,
|
|
|
|
VoiceBroadcastRecordingsStore,
|
|
|
|
} from "../../../src/voice-broadcast";
|
|
|
|
import { setUpVoiceBroadcastPreRecording } from "../../../src/voice-broadcast/utils/setUpVoiceBroadcastPreRecording";
|
|
|
|
import { mkRoomMemberJoinEvent, stubClient } from "../../test-utils";
|
2022-11-30 10:16:22 +00:00
|
|
|
import { mkVoiceBroadcastInfoStateEvent } from "./test-utils";
|
2022-11-10 08:38:48 +00:00
|
|
|
|
2023-01-09 15:08:30 +00:00
|
|
|
jest.mock("../../../src/Modal");
|
2022-11-10 08:38:48 +00:00
|
|
|
|
|
|
|
describe("setUpVoiceBroadcastPreRecording", () => {
|
|
|
|
const roomId = "!room:example.com";
|
|
|
|
let client: MatrixClient;
|
|
|
|
let userId: string;
|
|
|
|
let room: Room;
|
|
|
|
let preRecordingStore: VoiceBroadcastPreRecordingStore;
|
2022-11-30 10:16:22 +00:00
|
|
|
let infoEvent: MatrixEvent;
|
|
|
|
let playback: VoiceBroadcastPlayback;
|
|
|
|
let playbacksStore: VoiceBroadcastPlaybacksStore;
|
2022-11-10 08:38:48 +00:00
|
|
|
let recordingsStore: VoiceBroadcastRecordingsStore;
|
2022-12-28 15:13:37 +00:00
|
|
|
let preRecording: VoiceBroadcastPreRecording | null;
|
2022-11-10 08:38:48 +00:00
|
|
|
|
2022-12-28 15:13:37 +00:00
|
|
|
const itShouldNotCreateAPreRecording = () => {
|
2022-11-10 08:38:48 +00:00
|
|
|
it("should return null", () => {
|
2022-12-28 15:13:37 +00:00
|
|
|
expect(preRecording).toBeNull();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
2022-12-28 15:13:37 +00:00
|
|
|
|
|
|
|
it("should not create a broadcast pre recording", () => {
|
|
|
|
expect(preRecordingStore.getCurrent()).toBeNull();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const setUpPreRecording = async () => {
|
|
|
|
preRecording = await setUpVoiceBroadcastPreRecording(
|
|
|
|
room,
|
|
|
|
client,
|
|
|
|
playbacksStore,
|
|
|
|
recordingsStore,
|
|
|
|
preRecordingStore,
|
|
|
|
);
|
2022-11-10 08:38:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
client = stubClient();
|
2023-03-01 15:23:35 +00:00
|
|
|
userId = client.getSafeUserId();
|
2022-11-10 08:38:48 +00:00
|
|
|
room = new Room(roomId, client, userId);
|
2022-11-30 10:16:22 +00:00
|
|
|
infoEvent = mkVoiceBroadcastInfoStateEvent(
|
|
|
|
roomId,
|
|
|
|
VoiceBroadcastInfoState.Started,
|
|
|
|
client.getUserId()!,
|
|
|
|
client.getDeviceId()!,
|
|
|
|
);
|
2022-12-28 15:13:37 +00:00
|
|
|
preRecording = null;
|
2022-11-10 08:38:48 +00:00
|
|
|
preRecordingStore = new VoiceBroadcastPreRecordingStore();
|
|
|
|
recordingsStore = new VoiceBroadcastRecordingsStore();
|
2023-01-02 12:21:33 +00:00
|
|
|
playback = new VoiceBroadcastPlayback(infoEvent, client, recordingsStore);
|
|
|
|
jest.spyOn(playback, "pause");
|
|
|
|
playbacksStore = new VoiceBroadcastPlaybacksStore(recordingsStore);
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
|
2023-01-09 15:08:30 +00:00
|
|
|
describe("when trying to start a broadcast if there is no connection", () => {
|
2022-12-28 15:13:37 +00:00
|
|
|
beforeEach(async () => {
|
2023-01-09 15:08:30 +00:00
|
|
|
mocked(client.getSyncState).mockReturnValue(SyncState.Error);
|
2022-12-28 15:13:37 +00:00
|
|
|
await setUpPreRecording();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
|
2023-01-09 15:08:30 +00:00
|
|
|
it("should show an info dialog and not set up a pre-recording", () => {
|
|
|
|
expect(preRecordingStore.getCurrent()).toBeNull();
|
|
|
|
expect(Modal.createDialog).toMatchSnapshot();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
2023-01-09 15:08:30 +00:00
|
|
|
});
|
2022-11-10 08:38:48 +00:00
|
|
|
|
2023-01-09 15:08:30 +00:00
|
|
|
describe("when setting up a pre-recording", () => {
|
2022-11-10 08:38:48 +00:00
|
|
|
describe("and there is no user id", () => {
|
2022-12-28 15:13:37 +00:00
|
|
|
beforeEach(async () => {
|
2022-11-10 08:38:48 +00:00
|
|
|
mocked(client.getUserId).mockReturnValue(null);
|
2022-12-28 15:13:37 +00:00
|
|
|
await setUpPreRecording();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
|
2022-12-28 15:13:37 +00:00
|
|
|
itShouldNotCreateAPreRecording();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("and there is no room member", () => {
|
2022-12-28 15:13:37 +00:00
|
|
|
beforeEach(async () => {
|
2022-11-10 08:38:48 +00:00
|
|
|
// check test precondition
|
|
|
|
expect(room.getMember(userId)).toBeNull();
|
2022-12-28 15:13:37 +00:00
|
|
|
await setUpPreRecording();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
|
2022-12-28 15:13:37 +00:00
|
|
|
itShouldNotCreateAPreRecording();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
|
2022-11-30 10:16:22 +00:00
|
|
|
describe("and there is a room member and listening to another broadcast", () => {
|
2023-01-09 15:08:30 +00:00
|
|
|
beforeEach(async () => {
|
2022-11-30 10:16:22 +00:00
|
|
|
playbacksStore.setCurrent(playback);
|
2022-12-12 11:24:14 +00:00
|
|
|
room.currentState.setStateEvents([mkRoomMemberJoinEvent(userId, roomId)]);
|
2023-01-09 15:08:30 +00:00
|
|
|
await setUpPreRecording();
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
|
2022-11-30 10:16:22 +00:00
|
|
|
it("should pause the current playback and create a voice broadcast pre-recording", () => {
|
|
|
|
expect(playback.pause).toHaveBeenCalled();
|
|
|
|
expect(playbacksStore.getCurrent()).toBeNull();
|
2022-12-28 15:13:37 +00:00
|
|
|
expect(preRecording).toBeInstanceOf(VoiceBroadcastPreRecording);
|
2022-11-10 08:38:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|