Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Implement voice broadcast last_chunk_sequence (#9513)
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 authored Oct 27, 2022
1 parent 07003a5 commit c497046
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/voice-broadcast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/voice-broadcast/models/VoiceBroadcastRecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { TypedEventEmitter } from "matrix-js-sdk/src/models/typed-event-emitter"
import {
ChunkRecordedPayload,
createVoiceBroadcastRecorder,
VoiceBroadcastInfoEventContent,
VoiceBroadcastInfoEventType,
VoiceBroadcastInfoState,
VoiceBroadcastRecorder,
Expand Down Expand Up @@ -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(),
);
}
Expand Down
27 changes: 6 additions & 21 deletions test/voice-broadcast/models/VoiceBroadcastRecording-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
});
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c497046

Please sign in to comment.