fix: preserve failed media queue item
This commit is contained in:
@@ -38,11 +38,11 @@ export class MediaQueue {
|
|||||||
this.current = null;
|
this.current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
failCurrent(): void {
|
failCurrent(): MediaQueueItem | null {
|
||||||
if (this.current) {
|
if (!this.current) return null;
|
||||||
this.current = { ...this.current, status: "failed" };
|
const failed = { ...this.current, status: "failed" as const };
|
||||||
}
|
|
||||||
this.current = null;
|
this.current = null;
|
||||||
|
return failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear(): void {
|
clear(): void {
|
||||||
|
|||||||
@@ -55,6 +55,15 @@ describe("MediaQueue", () => {
|
|||||||
expect(queue.snapshot().queue).toEqual([]);
|
expect(queue.snapshot().queue).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("returns the failed current item", () => {
|
||||||
|
const queue = new MediaQueue(() => "item-1", () => 1700000000000);
|
||||||
|
const item = queue.add(source(), "tester");
|
||||||
|
queue.startNext();
|
||||||
|
|
||||||
|
expect(queue.failCurrent()).toEqual({ ...item, status: "failed" });
|
||||||
|
expect(queue.snapshot()).toEqual({ current: null, queue: [] });
|
||||||
|
});
|
||||||
|
|
||||||
it("clears current and queued items", () => {
|
it("clears current and queued items", () => {
|
||||||
const queue = new MediaQueue(() => "item-1", () => 1700000000000);
|
const queue = new MediaQueue(() => "item-1", () => 1700000000000);
|
||||||
queue.add(source(), "tester");
|
queue.add(source(), "tester");
|
||||||
|
|||||||
Reference in New Issue
Block a user