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

Commit 3c7781a

Browse files
authored
Stop voice broadcast on delete (#9629)
1 parent d6ea92f commit 3c7781a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/voice-broadcast/models/VoiceBroadcastPlayback.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
EventType,
1919
MatrixClient,
2020
MatrixEvent,
21+
MatrixEventEvent,
2122
MsgType,
2223
RelationType,
2324
} from "matrix-js-sdk/src/matrix";
@@ -88,6 +89,7 @@ export class VoiceBroadcastPlayback
8889
) {
8990
super();
9091
this.addInfoEvent(this.infoEvent);
92+
this.infoEvent.on(MatrixEventEvent.BeforeRedaction, this.onBeforeRedaction);
9193
this.setUpRelationsHelper();
9294
}
9395

@@ -169,6 +171,14 @@ export class VoiceBroadcastPlayback
169171
this.setInfoState(state);
170172
};
171173

174+
private onBeforeRedaction = () => {
175+
if (this.getState() !== VoiceBroadcastPlaybackState.Stopped) {
176+
this.stop();
177+
// destroy cleans up everything
178+
this.destroy();
179+
}
180+
};
181+
172182
private async enqueueChunks(): Promise<void> {
173183
const promises = this.chunkEvents.getEvents().reduce((promises, event: MatrixEvent) => {
174184
if (!this.playbacks.has(event.getId() || "")) {

test/voice-broadcast/models/VoiceBroadcastPlayback-test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ describe("VoiceBroadcastPlayback", () => {
126126
const mkPlayback = async () => {
127127
const playback = new VoiceBroadcastPlayback(infoEvent, client);
128128
jest.spyOn(playback, "removeAllListeners");
129+
jest.spyOn(playback, "destroy");
129130
playback.on(VoiceBroadcastPlaybackEvent.StateChanged, onStateChanged);
130131
await flushPromises();
131132
return playback;
@@ -273,6 +274,7 @@ describe("VoiceBroadcastPlayback", () => {
273274
startPlayback();
274275

275276
it("should play the last chunk", () => {
277+
expect(playback.getState()).toBe(VoiceBroadcastPlaybackState.Playing);
276278
// assert that the last chunk is played first
277279
expect(chunk2Playback.play).toHaveBeenCalled();
278280
expect(chunk1Playback.play).not.toHaveBeenCalled();
@@ -299,6 +301,17 @@ describe("VoiceBroadcastPlayback", () => {
299301
});
300302
});
301303
});
304+
305+
describe("and the info event is deleted", () => {
306+
beforeEach(() => {
307+
infoEvent.makeRedacted(new MatrixEvent({}));
308+
});
309+
310+
it("should stop and destroy the playback", () => {
311+
expect(playback.getState()).toBe(VoiceBroadcastPlaybackState.Stopped);
312+
expect(playback.destroy).toHaveBeenCalled();
313+
});
314+
});
302315
});
303316
});
304317

0 commit comments

Comments
 (0)