@voltkit-rtc/client 0.7.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +255 -4
  3. package/dist/cjs/adaptive.d.ts +104 -0
  4. package/dist/cjs/adaptive.d.ts.map +1 -0
  5. package/dist/cjs/adaptive.js +263 -0
  6. package/dist/cjs/adaptive.js.map +1 -0
  7. package/dist/cjs/devices.d.ts +42 -0
  8. package/dist/cjs/devices.d.ts.map +1 -0
  9. package/dist/cjs/devices.js +56 -0
  10. package/dist/cjs/devices.js.map +1 -0
  11. package/dist/cjs/diagnostics.d.ts +65 -0
  12. package/dist/cjs/diagnostics.d.ts.map +1 -0
  13. package/dist/cjs/diagnostics.js +69 -0
  14. package/dist/cjs/diagnostics.js.map +1 -0
  15. package/dist/cjs/fallback.d.ts +81 -0
  16. package/dist/cjs/fallback.d.ts.map +1 -0
  17. package/dist/cjs/fallback.js +148 -0
  18. package/dist/cjs/fallback.js.map +1 -0
  19. package/dist/cjs/health.d.ts +70 -0
  20. package/dist/cjs/health.d.ts.map +1 -0
  21. package/dist/cjs/health.js +116 -0
  22. package/dist/cjs/health.js.map +1 -0
  23. package/dist/cjs/index.d.ts +350 -0
  24. package/dist/cjs/index.d.ts.map +1 -1
  25. package/dist/cjs/index.js +1201 -36
  26. package/dist/cjs/index.js.map +1 -1
  27. package/dist/cjs/link.d.ts +99 -0
  28. package/dist/cjs/link.d.ts.map +1 -0
  29. package/dist/cjs/link.js +219 -0
  30. package/dist/cjs/link.js.map +1 -0
  31. package/dist/cjs/preflight.d.ts +79 -0
  32. package/dist/cjs/preflight.d.ts.map +1 -0
  33. package/dist/cjs/preflight.js +159 -0
  34. package/dist/cjs/preflight.js.map +1 -0
  35. package/dist/cjs/recording.d.ts +14 -0
  36. package/dist/cjs/recording.d.ts.map +1 -1
  37. package/dist/cjs/recording.js +51 -5
  38. package/dist/cjs/recording.js.map +1 -1
  39. package/dist/cjs/speakers.d.ts +34 -0
  40. package/dist/cjs/speakers.d.ts.map +1 -0
  41. package/dist/cjs/speakers.js +71 -0
  42. package/dist/cjs/speakers.js.map +1 -0
  43. package/dist/esm/adaptive.d.ts +104 -0
  44. package/dist/esm/adaptive.d.ts.map +1 -0
  45. package/dist/esm/adaptive.js +256 -0
  46. package/dist/esm/adaptive.js.map +1 -0
  47. package/dist/esm/devices.d.ts +42 -0
  48. package/dist/esm/devices.d.ts.map +1 -0
  49. package/dist/esm/devices.js +50 -0
  50. package/dist/esm/devices.js.map +1 -0
  51. package/dist/esm/diagnostics.d.ts +65 -0
  52. package/dist/esm/diagnostics.d.ts.map +1 -0
  53. package/dist/esm/diagnostics.js +65 -0
  54. package/dist/esm/diagnostics.js.map +1 -0
  55. package/dist/esm/fallback.d.ts +81 -0
  56. package/dist/esm/fallback.d.ts.map +1 -0
  57. package/dist/esm/fallback.js +142 -0
  58. package/dist/esm/fallback.js.map +1 -0
  59. package/dist/esm/health.d.ts +70 -0
  60. package/dist/esm/health.d.ts.map +1 -0
  61. package/dist/esm/health.js +111 -0
  62. package/dist/esm/health.js.map +1 -0
  63. package/dist/esm/index.d.ts +350 -0
  64. package/dist/esm/index.d.ts.map +1 -1
  65. package/dist/esm/index.js +1199 -36
  66. package/dist/esm/index.js.map +1 -1
  67. package/dist/esm/link.d.ts +99 -0
  68. package/dist/esm/link.d.ts.map +1 -0
  69. package/dist/esm/link.js +214 -0
  70. package/dist/esm/link.js.map +1 -0
  71. package/dist/esm/preflight.d.ts +79 -0
  72. package/dist/esm/preflight.d.ts.map +1 -0
  73. package/dist/esm/preflight.js +153 -0
  74. package/dist/esm/preflight.js.map +1 -0
  75. package/dist/esm/recording.d.ts +14 -0
  76. package/dist/esm/recording.d.ts.map +1 -1
  77. package/dist/esm/recording.js +51 -5
  78. package/dist/esm/recording.js.map +1 -1
  79. package/dist/esm/speakers.d.ts +34 -0
  80. package/dist/esm/speakers.d.ts.map +1 -0
  81. package/dist/esm/speakers.js +67 -0
  82. package/dist/esm/speakers.js.map +1 -0
  83. package/package.json +1 -1
  84. package/src/adaptive.ts +295 -0
  85. package/src/devices.ts +70 -0
  86. package/src/diagnostics.ts +94 -0
  87. package/src/fallback.ts +169 -0
  88. package/src/health.ts +127 -0
  89. package/src/index.ts +1192 -36
  90. package/src/link.ts +255 -0
  91. package/src/preflight.ts +191 -0
  92. package/src/recording.ts +59 -21
  93. package/src/speakers.ts +66 -0
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Diagnostics for support (docs/implementation-progress/RTC_PERF_PROGRESS.md S4).
3
+ *
4
+ * Agora uploads its SDK log on request (`enableLogUpload`), Twilio sends call telemetry to Insights, Stream Video
5
+ * traces session events to its servers. Shipping telemetry needs a backend; what helps today is a snapshot an app can
6
+ * attach to a support ticket: the SDK's recent events (a ring buffer) and its state now.
7
+ */
8
+
9
+ /** This package's version; kept equal to package.json by a test. */
10
+ export const SDK_VERSION = '0.8.0';
11
+
12
+ /** How many recent events the log keeps. */
13
+ export const DIAGNOSTICS_LOG_SIZE = 200;
14
+
15
+ export interface DiagnosticsEntry {
16
+ /** Unix ms. */
17
+ at: number;
18
+ event: string;
19
+ /** A short summary of what the event carried (no media objects). */
20
+ detail?: string;
21
+ }
22
+
23
+ /** The events worth keeping for support, and how to summarise each. */
24
+ const SUMMARY: Record<string, (args: unknown[]) => string | undefined> = {
25
+ connectionStateChanged: ([e]) => { const s = e as { previous?: string; state?: string }; return `${s.previous} → ${s.state}`; },
26
+ disconnected: ([reason]) => String(reason),
27
+ closed: ([reason]) => String(reason),
28
+ mustReconnect: ([e]) => (e as { reason?: string }).reason,
29
+ mediaReconnecting: ([e]) => { const m = e as { transportId?: string; reconnecting?: boolean }; return `${m.transportId} ${m.reconnecting ? 'recovering' : 'recovered'}`; },
30
+ error: ([e]) => {
31
+ const err = e as { code?: string; message?: string };
32
+ const message = err.message ?? '';
33
+ // RpcError's message already starts with its code.
34
+ return (err.code && !message.startsWith(`${err.code}:`) ? `${err.code}: ${message}` : message).slice(0, 300);
35
+ },
36
+ streamFallback: ([e]) => { const f = e as { producerId?: string; fallback?: boolean; reason?: string }; return `${f.producerId} ${f.fallback ? 'held' : 'back'} (${f.reason})`; },
37
+ mediaWarning: ([e]) => { const w = e as { code?: string; active?: boolean }; return `${w.code} ${w.active ? 'started' : 'cleared'}`; },
38
+ cpuConstrained: ([e]) => String((e as { constrained?: boolean }).constrained),
39
+ videoLimited: ([e]) => (e as { reason?: string }).reason,
40
+ localTrackEnded: ([e]) => { const t = e as { kind?: string; recovered?: boolean }; return `${t.kind} ${t.recovered ? 'recovered' : 'off'}`; },
41
+ devicesChanged: ([e]) => { const d = e as { added?: unknown[]; removed?: unknown[] }; return `+${d.added?.length ?? 0} -${d.removed?.length ?? 0}`; },
42
+ kicked: ([e]) => (e as { reason?: string }).reason,
43
+ roomClosed: ([e]) => (e as { reason?: string }).reason,
44
+ usageLimit: ([e]) => (e as { reason?: string }).reason,
45
+ autoplayFailed: () => undefined,
46
+ trackEnded: ([e]) => (e as { producerId?: string }).producerId,
47
+ track: ([e]) => { const t = e as { identity?: string; source?: string }; return `${t.identity} ${t.source}`; },
48
+ };
49
+
50
+ /** A ring buffer of the SDK's recent events. */
51
+ export class DiagnosticsLog {
52
+ private readonly entries: DiagnosticsEntry[] = [];
53
+
54
+ constructor(private readonly now: () => number = Date.now) {}
55
+
56
+ /** Keep an emitted event, when it is one worth keeping. */
57
+ record(event: string, args: unknown[]): void {
58
+ const summarize = SUMMARY[event];
59
+ if (!summarize) return;
60
+ let detail: string | undefined;
61
+ try {
62
+ detail = summarize(args);
63
+ } catch {
64
+ detail = undefined;
65
+ }
66
+ this.entries.push(detail === undefined ? { at: this.now(), event } : { at: this.now(), event, detail });
67
+ if (this.entries.length > DIAGNOSTICS_LOG_SIZE) this.entries.shift();
68
+ }
69
+
70
+ list(): DiagnosticsEntry[] {
71
+ return this.entries.map((e) => ({ ...e }));
72
+ }
73
+ }
74
+
75
+ export interface DiagnosticsTransport {
76
+ state: string;
77
+ path: { protocol: 'udp' | 'tcp' | null; relayed: boolean } | null;
78
+ }
79
+
80
+ export interface Diagnostics {
81
+ sdk: string;
82
+ at: number;
83
+ userAgent: string;
84
+ connectionState: string;
85
+ room: string | null;
86
+ identity: string | null;
87
+ role: string | null;
88
+ transports: { send: DiagnosticsTransport | null; recv: DiagnosticsTransport | null };
89
+ network: { rttMs: number | null; availableKbps: number | null } | null;
90
+ published: { source: string; kind: string; paused: boolean }[];
91
+ received: { identity: string; source: string; kind: string; paused: boolean }[];
92
+ /** Recent events, oldest first. */
93
+ log: DiagnosticsEntry[];
94
+ }
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Audio-only fallback (docs/implementation-progress/RTC_PERF_PROGRESS.md H1).
3
+ *
4
+ * When this viewer's connection is so poor that even the sound breaks up, remote camera videos are paused at the
5
+ * server so what bandwidth there is goes to the audio, and they come back once the connection has recovered.
6
+ *
7
+ * - Agora's `setStreamFallbackOption(uid, AUDIO_ONLY)` drops to the low stream and then to audio only, and reports
8
+ * `stream-fallback` (fallback / recover).
9
+ * - Amazon Chime watches the audio it receives (`UnusableAudioWarningConnectionHealthPolicy`): about half of the
10
+ * expected packets missing over 15 one-second samples suggests stopping video, with a 60 s cool-down.
11
+ *
12
+ * This follows Chime's signal -- the audio actually received -- measured as RTP loss (sequence gaps) rather than
13
+ * packet counts, because Opus DTX sends almost nothing during silence and a count would read silence as loss.
14
+ * Extreme only: {@link FALLBACK_LOSS} of the audio lost over {@link FALLBACK_SAMPLES} samples, with at least
15
+ * {@link MIN_PACKETS} packets to judge by. Back after a hold ({@link FIRST_HOLD_MS}, doubled for each relapse within
16
+ * {@link RELAPSE_MS}, up to {@link MAX_HOLD_MS}) once the loss is under {@link RECOVER_LOSS} -- or nobody spoke
17
+ * enough to tell, in which case video comes back and a still-bad connection falls back again, holding longer.
18
+ *
19
+ * The SFU cutting a video for bandwidth by itself is reported separately, by the server (`reason: 'bandwidth'`).
20
+ * Pure: the decisions take counters and a clock.
21
+ */
22
+ import type { StatsEntry } from './stats.js';
23
+
24
+ /** How often the received audio is sampled while the fallback could be needed. */
25
+ export const PROTECT_SAMPLE_MS = 3000;
26
+ /** This share of the audio lost (RTP sequence gaps) over the window: fall back. */
27
+ export const FALLBACK_LOSS = 0.25;
28
+ /** Below this share lost over the recovery window: video may come back. */
29
+ export const RECOVER_LOSS = 0.05;
30
+ /** Samples judged for falling back (15 s at 3 s) -- at least 3 of them. */
31
+ export const FALLBACK_SAMPLES = 5;
32
+ /** Samples judged for coming back (12 s). */
33
+ export const RECOVER_SAMPLES = 4;
34
+ /** Fewer audio packets than this over the fallback window are too few to judge. */
35
+ export const MIN_PACKETS = 150;
36
+ /** Fewer than this over the recovery window: nobody spoke enough to tell. */
37
+ export const MIN_RECOVER_PACKETS = 30;
38
+ /** The first fallback lasts at least this long. */
39
+ export const FIRST_HOLD_MS = 20_000;
40
+ /** A relapse doubles the hold, up to this. */
41
+ export const MAX_HOLD_MS = 160_000;
42
+ /** Falling back again within this long of coming back is a relapse. */
43
+ export const RELAPSE_MS = 120_000;
44
+
45
+ export interface AudioCounters {
46
+ received: number;
47
+ lost: number;
48
+ }
49
+
50
+ const num = (value: unknown): number => (typeof value === 'number' && Number.isFinite(value) ? value : 0);
51
+
52
+ /** The received-audio counters of a receive transport's report, summed over its audio streams. */
53
+ export function readInboundAudio(report: Iterable<StatsEntry>): AudioCounters {
54
+ let received = 0;
55
+ let lost = 0;
56
+ for (const e of report) {
57
+ if (typeof e !== 'object' || e === null || e.type !== 'inbound-rtp') continue;
58
+ if (e.kind !== 'audio' && e.mediaType !== 'audio') continue;
59
+ received += num(e.packetsReceived);
60
+ lost += Math.max(0, num(e.packetsLost));
61
+ }
62
+ return { received, lost };
63
+ }
64
+
65
+ /**
66
+ * The sent-audio counters of a send transport's report: packets sent, and how many of them the server reported
67
+ * lost (its RTCP receiver reports). For the publisher side (Agora's setLocalPublishFallbackOption): `received` is what
68
+ * got through.
69
+ */
70
+ export function readOutboundAudio(report: Iterable<StatsEntry>): AudioCounters {
71
+ let sent = 0;
72
+ let lost = 0;
73
+ for (const e of report) {
74
+ if (typeof e !== 'object' || e === null) continue;
75
+ const audio = e.kind === 'audio' || e.mediaType === 'audio';
76
+ if (!audio) continue;
77
+ if (e.type === 'outbound-rtp') sent += num(e.packetsSent);
78
+ else if (e.type === 'remote-inbound-rtp') lost += Math.max(0, num(e.packetsLost));
79
+ }
80
+ return { received: Math.max(0, sent - lost), lost };
81
+ }
82
+
83
+ /** Decides when to fall back to audio only and when video may come back. */
84
+ export class AudioProtection {
85
+ private samples: AudioCounters[] = [];
86
+ private previous: AudioCounters | null = null;
87
+ private activeSince: number | null = null;
88
+ private hold = FIRST_HOLD_MS;
89
+ private recoveredAt: number | null = null;
90
+
91
+ constructor(
92
+ private readonly onChange: (active: boolean) => void,
93
+ private readonly now: () => number = Date.now,
94
+ ) {}
95
+
96
+ /** Whether remote camera videos are held back now. */
97
+ get active(): boolean {
98
+ return this.activeSince !== null;
99
+ }
100
+
101
+ /** How long the current (or next first) fallback holds, in ms. */
102
+ get holdMs(): number {
103
+ return this.hold;
104
+ }
105
+
106
+ /**
107
+ * One reading of the cumulative counters. They only go up on one transport; lower ones are a new transport, and
108
+ * judging starts over from them.
109
+ */
110
+ feed(counters: AudioCounters): void {
111
+ const before = this.previous;
112
+ this.previous = counters;
113
+ if (before === null || counters.received < before.received || counters.lost < before.lost) {
114
+ this.samples = [];
115
+ return;
116
+ }
117
+ this.samples.push({ received: counters.received - before.received, lost: counters.lost - before.lost });
118
+ if (this.samples.length > Math.max(FALLBACK_SAMPLES, RECOVER_SAMPLES)) this.samples.shift();
119
+
120
+ if (this.activeSince === null) {
121
+ const window = this.samples.slice(-FALLBACK_SAMPLES);
122
+ if (window.length < 3) return;
123
+ const { total, lost } = sum(window);
124
+ if (total >= MIN_PACKETS && lost / total >= FALLBACK_LOSS) this.activate();
125
+ return;
126
+ }
127
+ if (this.now() - this.activeSince < this.hold || this.samples.length < RECOVER_SAMPLES) return;
128
+ const { total, lost } = sum(this.samples.slice(-RECOVER_SAMPLES));
129
+ if (total < MIN_RECOVER_PACKETS || lost / total < RECOVER_LOSS) this.recover();
130
+ }
131
+
132
+ /** Come back now (the app turned the fallback off). */
133
+ release(): void {
134
+ if (this.activeSince !== null) this.recover();
135
+ }
136
+
137
+ /** The transports went away (reconnect, close): forget everything, without telling. */
138
+ reset(): void {
139
+ this.activeSince = null;
140
+ this.samples = [];
141
+ this.previous = null;
142
+ }
143
+
144
+ private activate(): void {
145
+ const now = this.now();
146
+ const relapse = this.recoveredAt !== null && now - this.recoveredAt < RELAPSE_MS;
147
+ this.hold = relapse ? Math.min(this.hold * 2, MAX_HOLD_MS) : FIRST_HOLD_MS;
148
+ this.activeSince = now;
149
+ this.samples = [];
150
+ this.onChange(true);
151
+ }
152
+
153
+ private recover(): void {
154
+ this.activeSince = null;
155
+ this.recoveredAt = this.now();
156
+ this.samples = [];
157
+ this.onChange(false);
158
+ }
159
+ }
160
+
161
+ function sum(samples: readonly AudioCounters[]): { total: number; lost: number } {
162
+ let total = 0;
163
+ let lost = 0;
164
+ for (const s of samples) {
165
+ total += s.received + s.lost;
166
+ lost += s.lost;
167
+ }
168
+ return { total, lost };
169
+ }
package/src/health.ts ADDED
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Media health warnings (docs/implementation-progress/RTC_PERF_PROGRESS.md K1).
3
+ *
4
+ * - Agora's `exception` event pairs each problem with its recovery: FRAMERATE_INPUT_TOO_LOW / _RECOVER (the camera
5
+ * delivers too few frames), AUDIO_INPUT_LEVEL_TOO_LOW / _RECOVER, ...
6
+ * - LiveKit's `AudioSilenceDetected`: a microphone that delivers nothing but silence (a hardware mute switch, a
7
+ * broken device) right after it starts.
8
+ * - LiveKit watches the track's `mute` event (the OS took the device: a phone call, another app) and reacts after 5 s.
9
+ *
10
+ * Each warning is reported once when it starts (`active: true`) and once when it clears (`active: false`).
11
+ * Pure: the decisions take samples.
12
+ */
13
+
14
+ export type MediaWarningCode =
15
+ /** The microphone is on but delivers exact digital silence: a mute switch, a broken or wrongly chosen device. */
16
+ | 'mic-silent'
17
+ /** The camera delivers far fewer frames than asked: usually a dark room (the camera exposes longer), or a busy device. */
18
+ | 'camera-fps-low'
19
+ /** The system took the camera from this page for now (a phone call, another app, a locked screen). */
20
+ | 'camera-interrupted'
21
+ /** The system took the microphone (a phone call, another app). */
22
+ | 'mic-interrupted';
23
+
24
+ export interface MediaWarning {
25
+ code: MediaWarningCode;
26
+ /** true when it starts, false when it clears. */
27
+ active: boolean;
28
+ }
29
+
30
+ /** How often the published camera and microphone are sampled while someone listens. */
31
+ export const HEALTH_SAMPLE_MS = 2000;
32
+ /** Samples of exact silence before mic-silent (6 s). */
33
+ export const SILENT_SAMPLES = 3;
34
+ /** Below this the level counts as exact digital silence (a real room's noise floor is well above it). */
35
+ export const SILENCE_LEVEL = 0.0001;
36
+ /** Fewer frames than this per second, when 24 or more were asked, is camera-fps-low. */
37
+ export const LOW_FPS = 15;
38
+ /** Samples below LOW_FPS before warning (6 s); samples at RECOVERED_FPS or more before clearing. */
39
+ export const LOW_FPS_SAMPLES = 3;
40
+ export const RECOVERED_FPS = 20;
41
+ export const RECOVER_SAMPLES = 2;
42
+ /** A system mute shorter than this is a glitch, not an interruption. */
43
+ export const INTERRUPTED_AFTER_MS = 2000;
44
+
45
+ /** One reading of the published devices. null: not published (or nothing measured). */
46
+ export interface HealthSample {
47
+ /** The microphone's level, while it is on. */
48
+ micLevel: number | null;
49
+ /** The frames per second the camera delivers, while it is on, and what was asked. */
50
+ cameraFps: number | null;
51
+ askedFps: number;
52
+ }
53
+
54
+ /** Decides mic-silent and camera-fps-low from samples. */
55
+ export class HealthDecisions {
56
+ private silent = 0;
57
+ private lowFps = 0;
58
+ private goodFps = 0;
59
+ private readonly activeNow = new Set<MediaWarningCode>();
60
+
61
+ constructor(private readonly report: (warning: MediaWarning) => void) {}
62
+
63
+ isActive(code: MediaWarningCode): boolean {
64
+ return this.activeNow.has(code);
65
+ }
66
+
67
+ feed(sample: HealthSample): void {
68
+ // mic-silent: exact silence held; any sound clears it. Off or unpublished: not a warning.
69
+ if (sample.micLevel === null) {
70
+ this.silent = 0;
71
+ this.set('mic-silent', false);
72
+ } else if (sample.micLevel <= SILENCE_LEVEL) {
73
+ this.silent += 1;
74
+ if (this.silent >= SILENT_SAMPLES) this.set('mic-silent', true);
75
+ } else {
76
+ this.silent = 0;
77
+ this.set('mic-silent', false);
78
+ }
79
+
80
+ // camera-fps-low: only when a smooth rate was asked; cleared once it holds again.
81
+ if (sample.cameraFps === null || sample.askedFps < 24) {
82
+ this.lowFps = 0;
83
+ this.goodFps = 0;
84
+ this.set('camera-fps-low', false);
85
+ } else if (sample.cameraFps < LOW_FPS) {
86
+ this.goodFps = 0;
87
+ this.lowFps += 1;
88
+ if (this.lowFps >= LOW_FPS_SAMPLES) this.set('camera-fps-low', true);
89
+ } else {
90
+ this.lowFps = 0;
91
+ if (sample.cameraFps >= RECOVERED_FPS) this.goodFps += 1;
92
+ if (this.goodFps >= RECOVER_SAMPLES) this.set('camera-fps-low', false);
93
+ }
94
+ }
95
+
96
+ /** A system interruption started or ended (decided by the caller's timer). */
97
+ interrupted(code: 'camera-interrupted' | 'mic-interrupted', active: boolean): void {
98
+ this.set(code, active);
99
+ }
100
+
101
+ /** Everything clears (unpublished, closed): each active warning is reported cleared. */
102
+ clearAll(): void {
103
+ for (const code of [...this.activeNow]) this.set(code, false);
104
+ this.silent = 0;
105
+ this.lowFps = 0;
106
+ this.goodFps = 0;
107
+ }
108
+
109
+ private set(code: MediaWarningCode, active: boolean): void {
110
+ if (this.activeNow.has(code) === active) return;
111
+ if (active) this.activeNow.add(code);
112
+ else this.activeNow.delete(code);
113
+ this.report({ code, active });
114
+ }
115
+ }
116
+
117
+ /** The microphone level and camera frame rate from a producer's statistics (media-source). */
118
+ export function readMediaSource(report: Iterable<Record<string, unknown>>): { level: number | null; fps: number | null } {
119
+ let level: number | null = null;
120
+ let fps: number | null = null;
121
+ for (const s of report) {
122
+ if (s.type !== 'media-source') continue;
123
+ if (typeof s.audioLevel === 'number') level = s.audioLevel;
124
+ if (typeof s.framesPerSecond === 'number') fps = s.framesPerSecond;
125
+ }
126
+ return { level, fps };
127
+ }