-
Notifications
You must be signed in to change notification settings - Fork 335
Expand file tree
/
Copy path_output.test.ts
More file actions
98 lines (86 loc) · 3.24 KB
/
Copy path_output.test.ts
File metadata and controls
98 lines (86 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// SPDX-FileCopyrightText: 2026 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0
import { describe, expect, it, vi } from 'vitest';
import { Future } from '../../utils.js';
import { ParticipantAudioOutput } from './_output.js';
describe('ParticipantAudioOutput waitForPlayoutTask', () => {
it('resets tracked duration after non-interrupted playout', async () => {
let resolvePlayout!: () => void;
const waitForPlayout = new Promise<void>((resolve) => {
resolvePlayout = resolve;
});
const output = Object.create(ParticipantAudioOutput.prototype) as ParticipantAudioOutput & {
pushedDuration: number;
interruptedFuture: Future<void>;
firstFrameEmitted: boolean;
audioSource: {
waitForPlayout: () => Promise<void>;
queuedDuration: number;
clearQueue: () => void;
};
onPlaybackFinished: (event: { playbackPosition: number; interrupted: boolean }) => void;
waitForPlayoutTask: (abortController: AbortController) => Promise<void>;
};
const onPlaybackFinished = vi.fn();
output.pushedDuration = 1.0;
output.interruptedFuture = new Future<void>();
output.firstFrameEmitted = true;
output.onPlaybackFinished = onPlaybackFinished;
output.audioSource = {
waitForPlayout: () => waitForPlayout,
queuedDuration: 0,
clearQueue: vi.fn(),
};
const task = output.waitForPlayoutTask(new AbortController());
resolvePlayout();
await task;
expect(output.pushedDuration).toBe(0);
expect(onPlaybackFinished).toHaveBeenCalledWith({
playbackPosition: 1.0,
interrupted: false,
});
});
it('resets duration to queue state when interrupted flush clears overlap', async () => {
let resolvePlayout!: () => void;
const waitForPlayout = new Promise<void>((resolve) => {
resolvePlayout = resolve;
});
const output = Object.create(ParticipantAudioOutput.prototype) as ParticipantAudioOutput & {
pushedDuration: number;
interruptedFuture: Future<void>;
firstFrameEmitted: boolean;
audioSource: {
waitForPlayout: () => Promise<void>;
queuedDuration: number;
clearQueue: () => void;
};
onPlaybackFinished: (event: { playbackPosition: number; interrupted: boolean }) => void;
waitForPlayoutTask: (abortController: AbortController) => Promise<void>;
};
const onPlaybackFinished = vi.fn();
output.pushedDuration = 1.0;
output.interruptedFuture = new Future<void>();
output.firstFrameEmitted = true;
output.onPlaybackFinished = onPlaybackFinished;
output.audioSource = {
waitForPlayout: () => waitForPlayout,
queuedDuration: 500,
clearQueue: vi.fn(() => {
output.audioSource.queuedDuration = 0;
}),
};
const task = output.waitForPlayoutTask(new AbortController());
// Overlap from the next segment arrives before interruption.
output.pushedDuration += 0.5;
output.interruptedFuture.resolve();
resolvePlayout();
await task;
// interrupted path clears queued overlap, so duration should not retain stale overlap time.
expect(output.pushedDuration).toBe(0);
expect(onPlaybackFinished).toHaveBeenCalledWith({
playbackPosition: 0.5,
interrupted: true,
});
});
});