Handle voice broadcast last_chunk_sequence (#9812)
This commit is contained in:
parent
539a50ae30
commit
2b7d106481
5 changed files with 118 additions and 18 deletions
|
@ -279,26 +279,62 @@ describe("VoiceBroadcastPlayback", () => {
|
|||
expect(chunk1Playback.play).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("and the playback of the last chunk ended", () => {
|
||||
beforeEach(() => {
|
||||
chunk2Playback.emit(PlaybackState.Stopped);
|
||||
});
|
||||
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Buffering);
|
||||
|
||||
describe("and the next chunk arrived", () => {
|
||||
describe(
|
||||
"and receiving a stop info event with last_chunk_sequence = 2 and " +
|
||||
"the playback of the last available chunk ends",
|
||||
() => {
|
||||
beforeEach(() => {
|
||||
room.addLiveEvents([chunk3Event]);
|
||||
room.relations.aggregateChildEvent(chunk3Event);
|
||||
const stoppedEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Stopped,
|
||||
client.getSafeUserId(),
|
||||
client.deviceId!,
|
||||
infoEvent,
|
||||
2,
|
||||
);
|
||||
room.addLiveEvents([stoppedEvent]);
|
||||
room.relations.aggregateChildEvent(stoppedEvent);
|
||||
chunk2Playback.emit(PlaybackState.Stopped);
|
||||
});
|
||||
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Playing);
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Stopped);
|
||||
},
|
||||
);
|
||||
|
||||
it("should play the next chunk", () => {
|
||||
expect(chunk3Playback.play).toHaveBeenCalled();
|
||||
describe(
|
||||
"and receiving a stop info event with last_chunk_sequence = 3 and " +
|
||||
"the playback of the last available chunk ends",
|
||||
() => {
|
||||
beforeEach(() => {
|
||||
const stoppedEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Stopped,
|
||||
client.getSafeUserId(),
|
||||
client.deviceId!,
|
||||
infoEvent,
|
||||
3,
|
||||
);
|
||||
room.addLiveEvents([stoppedEvent]);
|
||||
room.relations.aggregateChildEvent(stoppedEvent);
|
||||
chunk2Playback.emit(PlaybackState.Stopped);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Buffering);
|
||||
|
||||
describe("and the next chunk arrives", () => {
|
||||
beforeEach(() => {
|
||||
room.addLiveEvents([chunk3Event]);
|
||||
room.relations.aggregateChildEvent(chunk3Event);
|
||||
});
|
||||
|
||||
itShouldSetTheStateTo(VoiceBroadcastPlaybackState.Playing);
|
||||
|
||||
it("should play the next chunk", () => {
|
||||
expect(chunk3Playback.play).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
describe("and the info event is deleted", () => {
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -62,6 +62,10 @@ describe("VoiceBroadcastChunkEvents", () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it("getNumberOfEvents should return 4", () => {
|
||||
expect(chunkEvents.getNumberOfEvents()).toBe(4);
|
||||
});
|
||||
|
||||
it("getLength should return the total length of all chunks", () => {
|
||||
expect(chunkEvents.getLength()).toBe(3259);
|
||||
});
|
||||
|
@ -110,6 +114,7 @@ describe("VoiceBroadcastChunkEvents", () => {
|
|||
eventSeq3Time2T,
|
||||
eventSeq4Time1,
|
||||
]);
|
||||
expect(chunkEvents.getNumberOfEvents()).toBe(4);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -129,6 +134,17 @@ describe("VoiceBroadcastChunkEvents", () => {
|
|||
eventSeqUTime3,
|
||||
eventSeq2Time4Dup,
|
||||
]);
|
||||
expect(chunkEvents.getNumberOfEvents()).toBe(5);
|
||||
});
|
||||
|
||||
describe("getSequenceForEvent", () => {
|
||||
it("should return the sequence if provided by the event", () => {
|
||||
expect(chunkEvents.getSequenceForEvent(eventSeq3Time2)).toBe(3);
|
||||
});
|
||||
|
||||
it("should return the index if no sequence provided by event", () => {
|
||||
expect(chunkEvents.getSequenceForEvent(eventSeqUTime3)).toBe(4);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -24,12 +24,16 @@ import {
|
|||
} from "../../../src/voice-broadcast";
|
||||
import { mkEvent } from "../../test-utils";
|
||||
|
||||
// timestamp incremented on each call to prevent duplicate timestamp
|
||||
let timestamp = new Date().getTime();
|
||||
|
||||
export const mkVoiceBroadcastInfoStateEvent = (
|
||||
roomId: Optional<string>,
|
||||
state: Optional<VoiceBroadcastInfoState>,
|
||||
senderId: Optional<string>,
|
||||
senderDeviceId: Optional<string>,
|
||||
startedInfoEvent?: MatrixEvent,
|
||||
lastChunkSequence?: number,
|
||||
): MatrixEvent => {
|
||||
const relationContent = {};
|
||||
|
||||
|
@ -40,6 +44,8 @@ export const mkVoiceBroadcastInfoStateEvent = (
|
|||
};
|
||||
}
|
||||
|
||||
const lastChunkSequenceContent = lastChunkSequence ? { last_chunk_sequence: lastChunkSequence } : {};
|
||||
|
||||
return mkEvent({
|
||||
event: true,
|
||||
// @ts-ignore allow everything here for edge test cases
|
||||
|
@ -53,7 +59,9 @@ export const mkVoiceBroadcastInfoStateEvent = (
|
|||
state,
|
||||
device_id: senderDeviceId,
|
||||
...relationContent,
|
||||
...lastChunkSequenceContent,
|
||||
},
|
||||
ts: timestamp++,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue