2022-09-28 10:22:50 +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 { mocked } from "jest-mock";
|
2022-10-12 00:31:28 +02:00
|
|
|
import {
|
|
|
|
EventTimelineSet,
|
|
|
|
EventType,
|
|
|
|
MatrixClient,
|
|
|
|
MatrixEvent,
|
2022-10-19 18:02:48 +02:00
|
|
|
MatrixEventEvent,
|
2022-10-12 00:31:28 +02:00
|
|
|
MsgType,
|
|
|
|
RelationType,
|
|
|
|
Room,
|
|
|
|
} from "matrix-js-sdk/src/matrix";
|
2022-09-28 10:22:50 +02:00
|
|
|
import { Relations } from "matrix-js-sdk/src/models/relations";
|
|
|
|
|
2022-10-12 00:31:28 +02:00
|
|
|
import { uploadFile } from "../../../src/ContentMessages";
|
|
|
|
import { IEncryptedFile } from "../../../src/customisations/models/IMediaEventContent";
|
|
|
|
import { createVoiceMessageContent } from "../../../src/utils/createVoiceMessageContent";
|
2022-09-28 10:22:50 +02:00
|
|
|
import {
|
2022-10-12 00:31:28 +02:00
|
|
|
createVoiceBroadcastRecorder,
|
2022-11-10 11:53:49 +01:00
|
|
|
getChunkLength,
|
|
|
|
getMaxBroadcastLength,
|
2022-09-28 10:22:50 +02:00
|
|
|
VoiceBroadcastInfoEventContent,
|
|
|
|
VoiceBroadcastInfoEventType,
|
|
|
|
VoiceBroadcastInfoState,
|
2022-10-12 00:31:28 +02:00
|
|
|
VoiceBroadcastRecorder,
|
|
|
|
VoiceBroadcastRecorderEvent,
|
2022-09-28 10:22:50 +02:00
|
|
|
VoiceBroadcastRecording,
|
|
|
|
VoiceBroadcastRecordingEvent,
|
|
|
|
} from "../../../src/voice-broadcast";
|
|
|
|
import { mkEvent, mkStubRoom, stubClient } from "../../test-utils";
|
2022-10-16 13:35:25 +02:00
|
|
|
import dis from "../../../src/dispatcher/dispatcher";
|
2022-11-10 11:53:49 +01:00
|
|
|
import { VoiceRecording } from "../../../src/audio/VoiceRecording";
|
2022-09-28 10:22:50 +02:00
|
|
|
|
2022-10-12 00:31:28 +02:00
|
|
|
jest.mock("../../../src/voice-broadcast/audio/VoiceBroadcastRecorder", () => ({
|
2022-12-12 12:24:14 +01:00
|
|
|
...(jest.requireActual("../../../src/voice-broadcast/audio/VoiceBroadcastRecorder") as object),
|
2022-10-12 00:31:28 +02:00
|
|
|
createVoiceBroadcastRecorder: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
2022-11-10 11:53:49 +01:00
|
|
|
// mock VoiceRecording because it contains all the audio APIs
|
|
|
|
jest.mock("../../../src/audio/VoiceRecording", () => ({
|
|
|
|
VoiceRecording: jest.fn().mockReturnValue({
|
|
|
|
disableMaxLength: jest.fn(),
|
|
|
|
liveData: {
|
|
|
|
onUpdate: jest.fn(),
|
|
|
|
},
|
|
|
|
off: jest.fn(),
|
|
|
|
on: jest.fn(),
|
|
|
|
start: jest.fn(),
|
|
|
|
stop: jest.fn(),
|
|
|
|
destroy: jest.fn(),
|
|
|
|
contentType: "audio/ogg",
|
|
|
|
}),
|
|
|
|
}));
|
|
|
|
|
2022-10-12 00:31:28 +02:00
|
|
|
jest.mock("../../../src/ContentMessages", () => ({
|
|
|
|
uploadFile: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock("../../../src/utils/createVoiceMessageContent", () => ({
|
|
|
|
createVoiceMessageContent: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
2022-09-28 10:22:50 +02:00
|
|
|
describe("VoiceBroadcastRecording", () => {
|
|
|
|
const roomId = "!room:example.com";
|
2022-10-12 00:31:28 +02:00
|
|
|
const uploadedUrl = "mxc://example.com/vb";
|
|
|
|
const uploadedFile = { file: true } as unknown as IEncryptedFile;
|
2022-11-10 11:53:49 +01:00
|
|
|
const maxLength = getMaxBroadcastLength();
|
2022-09-28 10:22:50 +02:00
|
|
|
let room: Room;
|
|
|
|
let client: MatrixClient;
|
|
|
|
let infoEvent: MatrixEvent;
|
|
|
|
let voiceBroadcastRecording: VoiceBroadcastRecording;
|
|
|
|
let onStateChanged: (state: VoiceBroadcastInfoState) => void;
|
2022-10-12 00:31:28 +02:00
|
|
|
let voiceBroadcastRecorder: VoiceBroadcastRecorder;
|
2022-09-28 10:22:50 +02:00
|
|
|
|
|
|
|
const mkVoiceBroadcastInfoEvent = (content: VoiceBroadcastInfoEventContent) => {
|
|
|
|
return mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: VoiceBroadcastInfoEventType,
|
|
|
|
user: client.getUserId(),
|
|
|
|
room: roomId,
|
|
|
|
content,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const setUpVoiceBroadcastRecording = () => {
|
|
|
|
voiceBroadcastRecording = new VoiceBroadcastRecording(infoEvent, client);
|
|
|
|
voiceBroadcastRecording.on(VoiceBroadcastRecordingEvent.StateChanged, onStateChanged);
|
2022-10-19 18:02:48 +02:00
|
|
|
jest.spyOn(voiceBroadcastRecording, "destroy");
|
2022-11-10 11:53:49 +01:00
|
|
|
jest.spyOn(voiceBroadcastRecording, "emit");
|
2022-10-12 00:31:28 +02:00
|
|
|
jest.spyOn(voiceBroadcastRecording, "removeAllListeners");
|
2022-09-28 10:22:50 +02:00
|
|
|
};
|
|
|
|
|
2022-10-16 13:35:25 +02:00
|
|
|
const itShouldBeInState = (state: VoiceBroadcastInfoState) => {
|
|
|
|
it(`should be in state stopped ${state}`, () => {
|
|
|
|
expect(voiceBroadcastRecording.getState()).toBe(state);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-10-27 16:24:03 +02:00
|
|
|
const itShouldSendAnInfoEvent = (state: VoiceBroadcastInfoState, lastChunkSequence: number) => {
|
2022-10-20 14:44:41 +02:00
|
|
|
it(`should send a ${state} info event`, () => {
|
|
|
|
expect(client.sendStateEvent).toHaveBeenCalledWith(
|
|
|
|
roomId,
|
|
|
|
VoiceBroadcastInfoEventType,
|
|
|
|
{
|
|
|
|
device_id: client.getDeviceId(),
|
|
|
|
state,
|
2022-10-27 16:24:03 +02:00
|
|
|
last_chunk_sequence: lastChunkSequence,
|
2022-10-20 14:44:41 +02:00
|
|
|
["m.relates_to"]: {
|
|
|
|
rel_type: RelationType.Reference,
|
|
|
|
event_id: infoEvent.getId(),
|
|
|
|
},
|
2022-10-27 16:24:03 +02:00
|
|
|
} as VoiceBroadcastInfoEventContent,
|
2022-10-20 14:44:41 +02:00
|
|
|
client.getUserId(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-11-10 11:53:49 +01:00
|
|
|
const itShouldSendAVoiceMessage = (data: number[], size: number, duration: number, sequence: number) => {
|
|
|
|
// events contain milliseconds
|
|
|
|
duration *= 1000;
|
|
|
|
|
|
|
|
it("should send a voice message", () => {
|
|
|
|
expect(uploadFile).toHaveBeenCalledWith(
|
|
|
|
client,
|
|
|
|
roomId,
|
|
|
|
new Blob([new Uint8Array(data)], { type: voiceBroadcastRecorder.contentType }),
|
|
|
|
);
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(mocked(client.sendMessage)).toHaveBeenCalledWith(roomId, {
|
|
|
|
body: "Voice message",
|
|
|
|
file: {
|
|
|
|
file: true,
|
|
|
|
},
|
|
|
|
info: {
|
|
|
|
duration,
|
|
|
|
mimetype: "audio/ogg",
|
|
|
|
size,
|
|
|
|
},
|
|
|
|
["m.relates_to"]: {
|
|
|
|
event_id: infoEvent.getId(),
|
|
|
|
rel_type: "m.reference",
|
|
|
|
},
|
|
|
|
msgtype: "m.audio",
|
|
|
|
["org.matrix.msc1767.audio"]: {
|
|
|
|
duration,
|
|
|
|
waveform: undefined,
|
|
|
|
},
|
|
|
|
["org.matrix.msc1767.file"]: {
|
2022-11-10 11:53:49 +01:00
|
|
|
file: {
|
|
|
|
file: true,
|
|
|
|
},
|
2022-12-12 12:24:14 +01:00
|
|
|
mimetype: "audio/ogg",
|
|
|
|
name: "Voice message.ogg",
|
|
|
|
size,
|
2022-11-10 11:53:49 +01:00
|
|
|
url: "mxc://example.com/vb",
|
|
|
|
},
|
2022-12-12 12:24:14 +01:00
|
|
|
["org.matrix.msc1767.text"]: "Voice message",
|
|
|
|
["org.matrix.msc3245.voice"]: {},
|
|
|
|
url: "mxc://example.com/vb",
|
|
|
|
["io.element.voice_broadcast_chunk"]: {
|
|
|
|
sequence,
|
|
|
|
},
|
|
|
|
});
|
2022-11-10 11:53:49 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-09-28 10:22:50 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
client = stubClient();
|
|
|
|
room = mkStubRoom(roomId, "Test Room", client);
|
|
|
|
mocked(client.getRoom).mockImplementation((getRoomId: string) => {
|
|
|
|
if (getRoomId === roomId) {
|
|
|
|
return room;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
onStateChanged = jest.fn();
|
2022-11-10 11:53:49 +01:00
|
|
|
voiceBroadcastRecorder = new VoiceBroadcastRecorder(new VoiceRecording(), getChunkLength());
|
|
|
|
jest.spyOn(voiceBroadcastRecorder, "start");
|
|
|
|
jest.spyOn(voiceBroadcastRecorder, "stop");
|
|
|
|
jest.spyOn(voiceBroadcastRecorder, "destroy");
|
2022-10-12 00:31:28 +02:00
|
|
|
mocked(createVoiceBroadcastRecorder).mockReturnValue(voiceBroadcastRecorder);
|
|
|
|
|
|
|
|
mocked(uploadFile).mockResolvedValue({
|
|
|
|
url: uploadedUrl,
|
|
|
|
file: uploadedFile,
|
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
mocked(createVoiceMessageContent).mockImplementation(
|
|
|
|
(
|
|
|
|
mxc: string,
|
|
|
|
mimetype: string,
|
|
|
|
duration: number,
|
|
|
|
size: number,
|
|
|
|
file?: IEncryptedFile,
|
|
|
|
waveform?: number[],
|
|
|
|
) => {
|
|
|
|
return {
|
|
|
|
body: "Voice message",
|
|
|
|
msgtype: MsgType.Audio,
|
2022-10-12 00:31:28 +02:00
|
|
|
url: mxc,
|
|
|
|
file,
|
2022-12-12 12:24:14 +01:00
|
|
|
info: {
|
|
|
|
duration,
|
|
|
|
mimetype,
|
|
|
|
size,
|
|
|
|
},
|
|
|
|
["org.matrix.msc1767.text"]: "Voice message",
|
|
|
|
["org.matrix.msc1767.file"]: {
|
|
|
|
url: mxc,
|
|
|
|
file,
|
|
|
|
name: "Voice message.ogg",
|
|
|
|
mimetype,
|
|
|
|
size,
|
|
|
|
},
|
|
|
|
["org.matrix.msc1767.audio"]: {
|
|
|
|
duration,
|
|
|
|
// https://github.com/matrix-org/matrix-doc/pull/3246
|
|
|
|
waveform,
|
|
|
|
},
|
|
|
|
["org.matrix.msc3245.voice"]: {}, // No content, this is a rendering hint
|
|
|
|
};
|
|
|
|
},
|
|
|
|
);
|
2022-09-28 10:22:50 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
voiceBroadcastRecording.off(VoiceBroadcastRecordingEvent.StateChanged, onStateChanged);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when created for a Voice Broadcast Info without relations", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
infoEvent = mkVoiceBroadcastInfoEvent({
|
2022-10-12 13:24:30 +02:00
|
|
|
device_id: client.getDeviceId(),
|
2022-09-28 10:22:50 +02:00
|
|
|
state: VoiceBroadcastInfoState.Started,
|
|
|
|
});
|
|
|
|
setUpVoiceBroadcastRecording();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be in Started state", () => {
|
2022-10-12 00:31:28 +02:00
|
|
|
expect(voiceBroadcastRecording.getState()).toBe(VoiceBroadcastInfoState.Started);
|
2022-09-28 10:22:50 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("and calling stop()", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
voiceBroadcastRecording.stop();
|
|
|
|
});
|
|
|
|
|
2022-10-27 16:24:03 +02:00
|
|
|
itShouldSendAnInfoEvent(VoiceBroadcastInfoState.Stopped, 1);
|
2022-10-16 13:35:25 +02:00
|
|
|
itShouldBeInState(VoiceBroadcastInfoState.Stopped);
|
2022-09-28 10:22:50 +02:00
|
|
|
|
|
|
|
it("should emit a stopped state changed event", () => {
|
|
|
|
expect(onStateChanged).toHaveBeenCalledWith(VoiceBroadcastInfoState.Stopped);
|
|
|
|
});
|
|
|
|
});
|
2022-10-12 00:31:28 +02:00
|
|
|
|
|
|
|
describe("and calling start", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await voiceBroadcastRecording.start();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should start the recorder", () => {
|
|
|
|
expect(voiceBroadcastRecorder.start).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2022-10-19 18:02:48 +02:00
|
|
|
describe("and the info event is redacted", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
infoEvent.emit(MatrixEventEvent.BeforeRedaction, null, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
itShouldBeInState(VoiceBroadcastInfoState.Stopped);
|
|
|
|
|
|
|
|
it("should destroy the recording", () => {
|
|
|
|
expect(voiceBroadcastRecording.destroy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-10-16 13:35:25 +02:00
|
|
|
describe("and receiving a call action", () => {
|
|
|
|
beforeEach(() => {
|
2022-12-12 12:24:14 +01:00
|
|
|
dis.dispatch(
|
|
|
|
{
|
|
|
|
action: "call_state",
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2022-10-16 13:35:25 +02:00
|
|
|
});
|
|
|
|
|
2022-11-28 12:43:59 +01:00
|
|
|
itShouldBeInState(VoiceBroadcastInfoState.Paused);
|
2022-10-16 13:35:25 +02:00
|
|
|
});
|
|
|
|
|
2022-11-10 11:53:49 +01:00
|
|
|
describe("and a chunk time update occurs", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
voiceBroadcastRecorder.emit(VoiceBroadcastRecorderEvent.CurrentChunkLengthUpdated, 10);
|
2022-10-12 00:31:28 +02:00
|
|
|
});
|
|
|
|
|
2022-11-10 11:53:49 +01:00
|
|
|
it("should update time left", () => {
|
|
|
|
expect(voiceBroadcastRecording.getTimeLeft()).toBe(maxLength - 10);
|
|
|
|
expect(voiceBroadcastRecording.emit).toHaveBeenCalledWith(
|
|
|
|
VoiceBroadcastRecordingEvent.TimeLeftChanged,
|
|
|
|
maxLength - 10,
|
2022-10-12 00:31:28 +02:00
|
|
|
);
|
2022-11-10 11:53:49 +01:00
|
|
|
});
|
2022-10-12 00:31:28 +02:00
|
|
|
|
2022-11-10 11:53:49 +01:00
|
|
|
describe("and a chunk time update occurs, that would increase time left", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mocked(voiceBroadcastRecording.emit).mockClear();
|
|
|
|
voiceBroadcastRecorder.emit(VoiceBroadcastRecorderEvent.CurrentChunkLengthUpdated, 5);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not change time left", () => {
|
|
|
|
expect(voiceBroadcastRecording.getTimeLeft()).toBe(maxLength - 10);
|
|
|
|
expect(voiceBroadcastRecording.emit).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and a chunk has been recorded", () => {
|
|
|
|
beforeEach(async () => {
|
2022-12-12 12:24:14 +01:00
|
|
|
voiceBroadcastRecorder.emit(VoiceBroadcastRecorderEvent.ChunkRecorded, {
|
|
|
|
buffer: new Uint8Array([1, 2, 3]),
|
|
|
|
length: 23,
|
|
|
|
});
|
2022-10-12 00:31:28 +02:00
|
|
|
});
|
2022-11-10 11:53:49 +01:00
|
|
|
|
|
|
|
itShouldSendAVoiceMessage([1, 2, 3], 3, 23, 1);
|
|
|
|
|
|
|
|
describe("and another chunk has been recorded, that exceeds the max time", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mocked(voiceBroadcastRecorder.stop).mockResolvedValue({
|
|
|
|
buffer: new Uint8Array([23, 24, 25]),
|
|
|
|
length: getMaxBroadcastLength(),
|
|
|
|
});
|
|
|
|
voiceBroadcastRecorder.emit(
|
|
|
|
VoiceBroadcastRecorderEvent.CurrentChunkLengthUpdated,
|
|
|
|
getMaxBroadcastLength(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
itShouldBeInState(VoiceBroadcastInfoState.Stopped);
|
|
|
|
itShouldSendAVoiceMessage([23, 24, 25], 3, getMaxBroadcastLength(), 2);
|
|
|
|
});
|
2022-10-12 00:31:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("and calling stop", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
mocked(voiceBroadcastRecorder.stop).mockResolvedValue({
|
|
|
|
buffer: new Uint8Array([4, 5, 6]),
|
|
|
|
length: 42,
|
|
|
|
});
|
|
|
|
await voiceBroadcastRecording.stop();
|
|
|
|
});
|
|
|
|
|
2022-11-10 11:53:49 +01:00
|
|
|
itShouldSendAVoiceMessage([4, 5, 6], 3, 42, 1);
|
2022-10-12 00:31:28 +02:00
|
|
|
});
|
|
|
|
|
2022-10-20 14:44:41 +02:00
|
|
|
describe.each([
|
|
|
|
["pause", async () => voiceBroadcastRecording.pause()],
|
|
|
|
["toggle", async () => voiceBroadcastRecording.toggle()],
|
|
|
|
])("and calling %s", (_case: string, action: Function) => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await action();
|
|
|
|
});
|
|
|
|
|
|
|
|
itShouldBeInState(VoiceBroadcastInfoState.Paused);
|
2022-10-27 16:24:03 +02:00
|
|
|
itShouldSendAnInfoEvent(VoiceBroadcastInfoState.Paused, 1);
|
2022-10-20 14:44:41 +02:00
|
|
|
|
|
|
|
it("should stop the recorder", () => {
|
|
|
|
expect(mocked(voiceBroadcastRecorder.stop)).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should emit a paused state changed event", () => {
|
|
|
|
expect(onStateChanged).toHaveBeenCalledWith(VoiceBroadcastInfoState.Paused);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-10-12 00:31:28 +02:00
|
|
|
describe("and calling destroy", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
voiceBroadcastRecording.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should stop the recorder and remove all listeners", () => {
|
|
|
|
expect(mocked(voiceBroadcastRecorder.stop)).toHaveBeenCalled();
|
2022-11-10 11:53:49 +01:00
|
|
|
expect(mocked(voiceBroadcastRecorder.destroy)).toHaveBeenCalled();
|
2022-10-12 00:31:28 +02:00
|
|
|
expect(mocked(voiceBroadcastRecording.removeAllListeners)).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-10-20 14:44:41 +02:00
|
|
|
|
|
|
|
describe("and it is in paused state", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await voiceBroadcastRecording.pause();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe.each([
|
|
|
|
["resume", async () => voiceBroadcastRecording.resume()],
|
|
|
|
["toggle", async () => voiceBroadcastRecording.toggle()],
|
|
|
|
])("and calling %s", (_case: string, action: Function) => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await action();
|
|
|
|
});
|
|
|
|
|
2022-10-26 14:54:44 +02:00
|
|
|
itShouldBeInState(VoiceBroadcastInfoState.Resumed);
|
2022-10-27 16:24:03 +02:00
|
|
|
itShouldSendAnInfoEvent(VoiceBroadcastInfoState.Resumed, 1);
|
2022-10-20 14:44:41 +02:00
|
|
|
|
|
|
|
it("should start the recorder", () => {
|
|
|
|
expect(mocked(voiceBroadcastRecorder.start)).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2022-10-26 14:54:44 +02:00
|
|
|
it(`should emit a ${VoiceBroadcastInfoState.Resumed} state changed event`, () => {
|
|
|
|
expect(onStateChanged).toHaveBeenCalledWith(VoiceBroadcastInfoState.Resumed);
|
2022-10-20 14:44:41 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-09-28 10:22:50 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("when created for a Voice Broadcast Info with a Stopped relation", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
infoEvent = mkVoiceBroadcastInfoEvent({
|
2022-10-12 13:24:30 +02:00
|
|
|
device_id: client.getDeviceId(),
|
2022-09-28 10:22:50 +02:00
|
|
|
state: VoiceBroadcastInfoState.Started,
|
2022-10-20 15:41:10 +02:00
|
|
|
chunk_length: 120,
|
2022-09-28 10:22:50 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const relationsContainer = {
|
|
|
|
getRelations: jest.fn(),
|
|
|
|
} as unknown as Relations;
|
|
|
|
mocked(relationsContainer.getRelations).mockReturnValue([
|
|
|
|
mkVoiceBroadcastInfoEvent({
|
2022-10-12 13:24:30 +02:00
|
|
|
device_id: client.getDeviceId(),
|
2022-09-28 10:22:50 +02:00
|
|
|
state: VoiceBroadcastInfoState.Stopped,
|
|
|
|
["m.relates_to"]: {
|
|
|
|
rel_type: RelationType.Reference,
|
|
|
|
event_id: infoEvent.getId(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
|
|
|
|
const timelineSet = {
|
|
|
|
relations: {
|
2022-12-12 12:24:14 +01:00
|
|
|
getChildEventsForEvent: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(
|
|
|
|
(eventId: string, relationType: RelationType | string, eventType: EventType | string) => {
|
|
|
|
if (
|
|
|
|
eventId === infoEvent.getId() &&
|
|
|
|
relationType === RelationType.Reference &&
|
|
|
|
eventType === VoiceBroadcastInfoEventType
|
|
|
|
) {
|
|
|
|
return relationsContainer;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2022-09-28 10:22:50 +02:00
|
|
|
},
|
|
|
|
} as unknown as EventTimelineSet;
|
|
|
|
mocked(room.getUnfilteredTimelineSet).mockReturnValue(timelineSet);
|
|
|
|
|
|
|
|
setUpVoiceBroadcastRecording();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be in Stopped state", () => {
|
2022-10-12 00:31:28 +02:00
|
|
|
expect(voiceBroadcastRecording.getState()).toBe(VoiceBroadcastInfoState.Stopped);
|
2022-09-28 10:22:50 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|