Implement voice broadcast `last_chunk_sequence` (#9513)

t3chguy/dedup-icons-17oct
Michael Weimann 2022-10-27 16:24:03 +02:00 committed by GitHub
parent 07003a5bc1
commit c497046e39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 22 deletions

View File

@ -56,6 +56,7 @@ export interface VoiceBroadcastInfoEventContent {
device_id: string;
state: VoiceBroadcastInfoState;
chunk_length?: number;
last_chunk_sequence?: number;
["m.relates_to"]?: {
rel_type: RelationType;
event_id: string;

View File

@ -21,6 +21,7 @@ import { TypedEventEmitter } from "matrix-js-sdk/src/models/typed-event-emitter"
import {
ChunkRecordedPayload,
createVoiceBroadcastRecorder,
VoiceBroadcastInfoEventContent,
VoiceBroadcastInfoEventType,
VoiceBroadcastInfoState,
VoiceBroadcastRecorder,
@ -207,11 +208,12 @@ export class VoiceBroadcastRecording
{
device_id: this.client.getDeviceId(),
state,
last_chunk_sequence: this.sequence,
["m.relates_to"]: {
rel_type: RelationType.Reference,
event_id: this.infoEvent.getId(),
},
},
} as VoiceBroadcastInfoEventContent,
this.client.getUserId(),
);
}

View File

@ -92,20 +92,20 @@ describe("VoiceBroadcastRecording", () => {
});
};
const itShouldSendAnInfoEvent = (state: VoiceBroadcastInfoState) => {
const itShouldSendAnInfoEvent = (state: VoiceBroadcastInfoState, lastChunkSequence: number) => {
it(`should send a ${state} info event`, () => {
expect(client.sendStateEvent).toHaveBeenCalledWith(
roomId,
VoiceBroadcastInfoEventType,
{
device_id: client.getDeviceId(),
state,
last_chunk_sequence: lastChunkSequence,
["m.relates_to"]: {
rel_type: RelationType.Reference,
event_id: infoEvent.getId(),
},
},
} as VoiceBroadcastInfoEventContent,
client.getUserId(),
);
});
@ -203,22 +203,7 @@ describe("VoiceBroadcastRecording", () => {
voiceBroadcastRecording.stop();
});
it("should send a stopped Voice Broadcast Info event", () => {
expect(mocked(client.sendStateEvent)).toHaveBeenCalledWith(
roomId,
VoiceBroadcastInfoEventType,
{
device_id: client.getDeviceId(),
state: VoiceBroadcastInfoState.Stopped,
["m.relates_to"]: {
rel_type: RelationType.Reference,
event_id: infoEvent.getId(),
},
},
client.getUserId(),
);
});
itShouldSendAnInfoEvent(VoiceBroadcastInfoState.Stopped, 1);
itShouldBeInState(VoiceBroadcastInfoState.Stopped);
it("should emit a stopped state changed event", () => {
@ -383,7 +368,7 @@ describe("VoiceBroadcastRecording", () => {
});
itShouldBeInState(VoiceBroadcastInfoState.Paused);
itShouldSendAnInfoEvent(VoiceBroadcastInfoState.Paused);
itShouldSendAnInfoEvent(VoiceBroadcastInfoState.Paused, 1);
it("should stop the recorder", () => {
expect(mocked(voiceBroadcastRecorder.stop)).toHaveBeenCalled();
@ -424,7 +409,7 @@ describe("VoiceBroadcastRecording", () => {
});
itShouldBeInState(VoiceBroadcastInfoState.Resumed);
itShouldSendAnInfoEvent(VoiceBroadcastInfoState.Resumed);
itShouldSendAnInfoEvent(VoiceBroadcastInfoState.Resumed, 1);
it("should start the recorder", () => {
expect(mocked(voiceBroadcastRecorder.start)).toHaveBeenCalled();