Skip to content

armgit / Piik

Public Imported from GitHub
0

Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

refactor(stats): remove unused ICE response counters (#243)

AAAb608d189201c
diff --git a/src/client/types.ts b/src/client/types.ts
index a9c8c7c7..920aec43 100644
--- a/src/client/types.ts
+++ b/src/client/types.ts
@@ -15,9 +15,6 @@ export interface ConnectionMetrics {
rtpRid: string | null;
trackIdentifier: string | null;
selectedCandidatePairId: string | null;
- candidatePairResponsesReceived: number | null;
- intervalCandidatePairResponsesReceived: number | null;
- candidatePairSampleWindowMs: number | null;
captureWidth: number | null;
captureHeight: number | null;
captureFramesPerSecond: number | null;
@@ -98,9 +95,6 @@ export const EMPTY_METRICS: ConnectionMetrics = {
rtpRid: null,
trackIdentifier: null,
selectedCandidatePairId: null,
- candidatePairResponsesReceived: null,
- intervalCandidatePairResponsesReceived: null,
- candidatePairSampleWindowMs: null,
captureWidth: null,
captureHeight: null,
captureFramesPerSecond: null,
diff --git a/src/client/webrtc/stats.ts b/src/client/webrtc/stats.ts
index 99f370ab..8d16b59b 100644
--- a/src/client/webrtc/stats.ts
+++ b/src/client/webrtc/stats.ts
@@ -10,12 +10,7 @@ type StatsRecord = Record<string, unknown> & {
timestamp: number;
};
-const MAX_CANDIDATE_PAIR_SAMPLE_WINDOW_MS = 5_000;
-
export interface StatsAccumulator {
- candidatePairId: string | null;
- candidatePairResponsesReceived: number | null;
- candidatePairTimestamp: number | null;
mediaId: string | null;
ssrc: number | null;
trackIdentifier: string | null;
@@ -82,9 +77,6 @@ export function captureMetrics(
export function createStatsAccumulator(): StatsAccumulator {
return {
- candidatePairId: null,
- candidatePairResponsesReceived: null,
- candidatePairTimestamp: null,
mediaId: null,
ssrc: null,
trackIdentifier: null,
@@ -370,16 +362,6 @@ function positiveIntegerValue(
return value !== null && Number.isInteger(value) && value > 0 ? value : null;
}
-function nonNegativeIntegerValue(
- record: StatsRecord | null,
- key: string,
-): number | null {
- const value = numberValue(record, key);
- return value !== null && Number.isSafeInteger(value) && value >= 0
- ? value
- : null;
-}
-
function candidateAddressValue(record: StatsRecord | null): string | null {
const value = stringValue(record, "address");
return value !== null &&
@@ -459,34 +441,6 @@ export function collectConnectionMetricsFromReport(
? "direct"
: "unknown";
- const candidatePairId = pair?.id ?? null;
- const candidatePairResponsesReceived = nonNegativeIntegerValue(
- pair,
- "responsesReceived",
- );
- const candidatePairTimestamp = numberValue(pair, "timestamp");
- const candidatePairSampleWindowMs =
- candidatePairId !== null &&
- candidatePairId === previous.candidatePairId &&
- candidatePairResponsesReceived !== null &&
- previous.candidatePairResponsesReceived !== null &&
- candidatePairResponsesReceived >= previous.candidatePairResponsesReceived &&
- candidatePairTimestamp !== null &&
- previous.candidatePairTimestamp !== null &&
- candidatePairTimestamp > previous.candidatePairTimestamp &&
- candidatePairTimestamp - previous.candidatePairTimestamp <=
- MAX_CANDIDATE_PAIR_SAMPLE_WINDOW_MS
- ? candidatePairTimestamp - previous.candidatePairTimestamp
- : null;
- const intervalCandidatePairResponsesReceived = intervalDelta(
- candidatePairResponsesReceived,
- previous.candidatePairResponsesReceived,
- candidatePairSampleWindowMs !== null,
- );
- previous.candidatePairId = candidatePairId;
- previous.candidatePairResponsesReceived = candidatePairResponsesReceived;
- previous.candidatePairTimestamp = candidatePairTimestamp;
-
const mediaId = media?.id ?? null;
const ssrc = numberValue(media, "ssrc");
const trackIdentifier = media
@@ -824,9 +778,6 @@ export function collectConnectionMetricsFromReport(
rtpRid: stringValue(media, "rid"),
trackIdentifier,
selectedCandidatePairId: pair?.id ?? null,
- candidatePairResponsesReceived,
- intervalCandidatePairResponsesReceived,
- candidatePairSampleWindowMs,
path,
iceProtocol,
localCandidateType: localType,
diff --git a/tests/client-state.test.ts b/tests/client-state.test.ts
index ee52fbaa..5a999552 100644
--- a/tests/client-state.test.ts
+++ b/tests/client-state.test.ts
@@ -37,7 +37,6 @@ import {
import { qualityEvidenceWindowFromMetrics } from "../src/client/media/viewer-quality-evidence.ts";
import {
collectConnectionMetrics,
- collectConnectionMetricsFromReport,
createStatsAccumulator,
} from "../src/client/webrtc/stats.ts";
@@ -1290,139 +1289,6 @@ describe("client signaling recovery policy", () => {
});
describe("WebRTC stats parsing", () => {
- it("rebases selected-pair response observations across identity and sampling gaps", () => {
- const report = (
- pairId: string,
- timestamp: number,
- responsesReceived?: unknown,
- ) =>
- new Map<string, unknown>([
- [
- "transport",
- {
- id: "transport",
- type: "transport",
- timestamp,
- selectedCandidatePairId: pairId,
- },
- ],
- [
- pairId,
- {
- id: pairId,
- type: "candidate-pair",
- timestamp,
- transportId: "transport",
- localCandidateId: "local",
- remoteCandidateId: "remote",
- ...(responsesReceived === undefined ? {} : { responsesReceived }),
- },
- ],
- [
- "local",
- {
- id: "local",
- type: "local-candidate",
- timestamp,
- candidateType: "host",
- protocol: "udp",
- },
- ],
- [
- "remote",
- {
- id: "remote",
- type: "remote-candidate",
- timestamp,
- candidateType: "srflx",
- protocol: "udp",
- },
- ],
- [
- "inbound",
- {
- id: "inbound",
- type: "inbound-rtp",
- timestamp,
- kind: "video",
- transportId: "transport",
- bytesReceived: 1_000,
- framesDecoded: 10,
- },
- ],
- ]) as unknown as RTCStatsReport;
- const accumulator = createStatsAccumulator();
- const sample = (
- pairId: string,
- timestamp: number,
- responsesReceived?: unknown,
- ) =>
- collectConnectionMetricsFromReport(
- report(pairId, timestamp, responsesReceived),
- "receive",
- accumulator,
- );
-
- expect(sample("pair-a", 1_000, 5)).toMatchObject({
- selectedCandidatePairId: "pair-a",
- candidatePairResponsesReceived: 5,
- intervalCandidatePairResponsesReceived: null,
- candidatePairSampleWindowMs: null,
- });
- expect(sample("pair-a", 3_000, 6)).toMatchObject({
- candidatePairResponsesReceived: 6,
- intervalCandidatePairResponsesReceived: 1,
- candidatePairSampleWindowMs: 2_000,
- });
- expect(sample("pair-a", 5_000, 6)).toMatchObject({
- intervalCandidatePairResponsesReceived: 0,
- candidatePairSampleWindowMs: 2_000,
- });
- expect(sample("pair-a", 7_000, 1)).toMatchObject({
- candidatePairResponsesReceived: 1,
- intervalCandidatePairResponsesReceived: null,
- candidatePairSampleWindowMs: null,
- });
- expect(sample("pair-a", 9_000, 2)).toMatchObject({
- intervalCandidatePairResponsesReceived: 1,
- candidatePairSampleWindowMs: 2_000,
- });
- expect(sample("pair-b", 11_000, 10)).toMatchObject({
- selectedCandidatePairId: "pair-b",
- intervalCandidatePairResponsesReceived: null,
- candidatePairSampleWindowMs: null,
- });
- expect(sample("pair-b", 16_001, 11)).toMatchObject({
- intervalCandidatePairResponsesReceived: null,
- candidatePairSampleWindowMs: null,
- });
- expect(sample("pair-b", 18_001, 12)).toMatchObject({
- intervalCandidatePairResponsesReceived: 1,
- candidatePairSampleWindowMs: 2_000,
- });
- expect(sample("pair-b", 20_001)).toMatchObject({
- candidatePairResponsesReceived: null,
- intervalCandidatePairResponsesReceived: null,
- candidatePairSampleWindowMs: null,
- });
- expect(sample("pair-b", 22_001, 13)).toMatchObject({
- candidatePairResponsesReceived: 13,
- intervalCandidatePairResponsesReceived: null,
- candidatePairSampleWindowMs: null,
- });
- expect(
- collectConnectionMetricsFromReport(
- report("pair-b", 24_001, 14),
- "receive",
- createStatsAccumulator(),
- ),
- ).toMatchObject({
- candidatePairResponsesReceived: 14,
- intervalCandidatePairResponsesReceived: null,
- candidatePairSampleWindowMs: null,
- });
- });
-
it("binds media, remote evidence, transport, and pair without guessing", async () => {
const entry = (
id: string,
diff --git a/tests/stats-grid.test.ts b/tests/stats-grid.test.ts
index 55516649..ab0f3003 100644
--- a/tests/stats-grid.test.ts
+++ b/tests/stats-grid.test.ts
@@ -24,9 +24,6 @@ const metrics = {
remoteCandidateAddress: "2001:db8::10",
remoteCandidatePort: 50_001,
selectedCandidatePairId: "candidate-pair-7",
- candidatePairResponsesReceived: 18,
- intervalCandidatePairResponsesReceived: 1,
- candidatePairSampleWindowMs: 2_000,
codec: "video/VP8",
codecParameters: "max-fs=8160",
captureWidth: 1_920,