Files
WebSpeak-client-for-TeamSpeak/web/test/jitter-buffer.test.ts
T
LabKit de16417474 feat(voice): harden tunnel fallback and add tuning controls
Add v3 batched downlink with tick-aligned timestamps, audio-clock playback and PLC; add adaptive Opus/PCM uplink and one-shot TURN relay retry. Expose frame size, automatic relay retry and Cloudflare ingress assumptions in the admin console, with persistence, i18n, docs and regression tests.
2026-12-03 02:40:19 +08:00

37 lines
1.3 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
import {
computeTargetAheadMs,
JitterEstimator,
shouldRecover,
shouldResetSchedule,
} from "../src/voice/jitter-buffer.ts";
test("target buffer maps p95 jitter to the 80-300 ms adaptive range", () => {
assert.equal(computeTargetAheadMs(0), 80);
assert.equal(computeTargetAheadMs(30), 90);
assert.equal(computeTargetAheadMs(100), 160);
assert.equal(computeTargetAheadMs(1_000), 300);
});
test("a configured 80 ms ceiling restores the old buffer bound", () => {
assert.equal(computeTargetAheadMs(100, 80), 80);
assert.equal(computeTargetAheadMs(0, 80), 80);
});
test("jitter estimator raises the target after a late burst", () => {
const estimator = new JitterEstimator();
assert.equal(estimator.observe(0, 1_000), 80);
assert.equal(estimator.observe(20, 1_020), 80);
const target = estimator.observe(40, 1_080);
assert.ok(target > 80, `expected target above 80 ms, received ${target}`);
assert.ok(target <= 300);
});
test("schedule reset and recovery thresholds keep hysteresis", () => {
assert.equal(shouldResetSchedule(400, 80), true);
assert.equal(shouldResetSchedule(300, 80), false);
assert.equal(shouldRecover(10), true);
assert.equal(shouldRecover(30), false);
});