Stop voice broadcast on delete (#9629)
parent
d6ea92f735
commit
3c7781a561
|
@ -18,6 +18,7 @@ import {
|
||||||
EventType,
|
EventType,
|
||||||
MatrixClient,
|
MatrixClient,
|
||||||
MatrixEvent,
|
MatrixEvent,
|
||||||
|
MatrixEventEvent,
|
||||||
MsgType,
|
MsgType,
|
||||||
RelationType,
|
RelationType,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
|
@ -88,6 +89,7 @@ export class VoiceBroadcastPlayback
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.addInfoEvent(this.infoEvent);
|
this.addInfoEvent(this.infoEvent);
|
||||||
|
this.infoEvent.on(MatrixEventEvent.BeforeRedaction, this.onBeforeRedaction);
|
||||||
this.setUpRelationsHelper();
|
this.setUpRelationsHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +171,14 @@ export class VoiceBroadcastPlayback
|
||||||
this.setInfoState(state);
|
this.setInfoState(state);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private onBeforeRedaction = () => {
|
||||||
|
if (this.getState() !== VoiceBroadcastPlaybackState.Stopped) {
|
||||||
|
this.stop();
|
||||||
|
// destroy cleans up everything
|
||||||
|
this.destroy();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private async enqueueChunks(): Promise<void> {
|
private async enqueueChunks(): Promise<void> {
|
||||||
const promises = this.chunkEvents.getEvents().reduce((promises, event: MatrixEvent) => {
|
const promises = this.chunkEvents.getEvents().reduce((promises, event: MatrixEvent) => {
|
||||||
if (!this.playbacks.has(event.getId() || "")) {
|
if (!this.playbacks.has(event.getId() || "")) {
|
||||||
|
|
|
@ -126,6 +126,7 @@ describe("VoiceBroadcastPlayback", () => {
|
||||||
const mkPlayback = async () => {
|
const mkPlayback = async () => {
|
||||||
const playback = new VoiceBroadcastPlayback(infoEvent, client);
|
const playback = new VoiceBroadcastPlayback(infoEvent, client);
|
||||||
jest.spyOn(playback, "removeAllListeners");
|
jest.spyOn(playback, "removeAllListeners");
|
||||||
|
jest.spyOn(playback, "destroy");
|
||||||
playback.on(VoiceBroadcastPlaybackEvent.StateChanged, onStateChanged);
|
playback.on(VoiceBroadcastPlaybackEvent.StateChanged, onStateChanged);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
return playback;
|
return playback;
|
||||||
|
@ -273,6 +274,7 @@ describe("VoiceBroadcastPlayback", () => {
|
||||||
startPlayback();
|
startPlayback();
|
||||||
|
|
||||||
it("should play the last chunk", () => {
|
it("should play the last chunk", () => {
|
||||||
|
expect(playback.getState()).toBe(VoiceBroadcastPlaybackState.Playing);
|
||||||
// assert that the last chunk is played first
|
// assert that the last chunk is played first
|
||||||
expect(chunk2Playback.play).toHaveBeenCalled();
|
expect(chunk2Playback.play).toHaveBeenCalled();
|
||||||
expect(chunk1Playback.play).not.toHaveBeenCalled();
|
expect(chunk1Playback.play).not.toHaveBeenCalled();
|
||||||
|
@ -299,6 +301,17 @@ describe("VoiceBroadcastPlayback", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("and the info event is deleted", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
infoEvent.makeRedacted(new MatrixEvent({}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should stop and destroy the playback", () => {
|
||||||
|
expect(playback.getState()).toBe(VoiceBroadcastPlaybackState.Stopped);
|
||||||
|
expect(playback.destroy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue