@caprid/relay 0.5.0 → 0.6.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 (52) hide show
  1. package/README.md +54 -53
  2. package/dist/client-diagnostics.d.ts +235 -0
  3. package/dist/client-diagnostics.d.ts.map +1 -0
  4. package/dist/client-diagnostics.js +582 -0
  5. package/dist/client-diagnostics.js.map +1 -0
  6. package/dist/connect-session.d.ts +43 -3
  7. package/dist/connect-session.d.ts.map +1 -1
  8. package/dist/connect-session.js +46 -3
  9. package/dist/connect-session.js.map +1 -1
  10. package/dist/connect.d.ts +1 -1
  11. package/dist/connect.d.ts.map +1 -1
  12. package/dist/connect.js.map +1 -1
  13. package/dist/diagnostics-report.d.ts +106 -0
  14. package/dist/diagnostics-report.d.ts.map +1 -0
  15. package/dist/diagnostics-report.js +450 -0
  16. package/dist/diagnostics-report.js.map +1 -0
  17. package/dist/diagnostics.d.ts +20 -0
  18. package/dist/diagnostics.d.ts.map +1 -0
  19. package/dist/diagnostics.js +20 -0
  20. package/dist/diagnostics.js.map +1 -0
  21. package/dist/frame-reader.d.ts +12 -0
  22. package/dist/frame-reader.d.ts.map +1 -1
  23. package/dist/frame-reader.js +65 -0
  24. package/dist/frame-reader.js.map +1 -1
  25. package/dist/frame-writer.d.ts +15 -0
  26. package/dist/frame-writer.d.ts.map +1 -1
  27. package/dist/frame-writer.js +73 -1
  28. package/dist/frame-writer.js.map +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/supervised-publisher.d.ts +7 -0
  33. package/dist/supervised-publisher.d.ts.map +1 -1
  34. package/dist/supervised-publisher.js +4 -1
  35. package/dist/supervised-publisher.js.map +1 -1
  36. package/dist/supervised-relay.d.ts +8 -0
  37. package/dist/supervised-relay.d.ts.map +1 -1
  38. package/dist/supervised-relay.js +5 -2
  39. package/dist/supervised-relay.js.map +1 -1
  40. package/dist/supervised-subscriber.d.ts +10 -2
  41. package/dist/supervised-subscriber.d.ts.map +1 -1
  42. package/dist/supervised-subscriber.js +20 -9
  43. package/dist/supervised-subscriber.js.map +1 -1
  44. package/dist/supervisor.d.ts +9 -0
  45. package/dist/supervisor.d.ts.map +1 -1
  46. package/dist/supervisor.js +26 -2
  47. package/dist/supervisor.js.map +1 -1
  48. package/dist/version.d.ts +6 -0
  49. package/dist/version.d.ts.map +1 -0
  50. package/dist/version.js +6 -0
  51. package/dist/version.js.map +1 -0
  52. package/package.json +13 -9
@@ -0,0 +1,450 @@
1
+ import { RelayError } from './errors.js';
2
+ /**
3
+ * A short, log-safe description of a failure for an event: a RelayError's code and phase, or an error's name, then its
4
+ * message, with tokens redacted and at most 300 characters.
5
+ */
6
+ export function describeFailure(error) {
7
+ let text;
8
+ if (error instanceof RelayError)
9
+ text = `${error.code} (${error.phase}): ${error.message}`;
10
+ else if (error instanceof Error)
11
+ text = `${error.name}: ${error.message}`;
12
+ else
13
+ text = String(error);
14
+ return text
15
+ .replace(/([?&]jwt=)[^&\s"']+/g, '$1[redacted]')
16
+ .replace(/eyJ[\w-]+\.[\w-]+\.[\w-]+/g, '[jwt]')
17
+ .slice(0, 300);
18
+ }
19
+ /** The host of a relay endpoint, port included: never its path or query, which can carry a token. */
20
+ export function endpointHost(endpoint) {
21
+ try {
22
+ return new URL(endpoint).host || undefined;
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
28
+ /** How a connection attempt ended, for a `dial` event. */
29
+ export function dialOutcome(error) {
30
+ if (error instanceof RelayError && error.code === 'CONNECTION_TIMEOUT')
31
+ return 'timeout';
32
+ if (error instanceof RelayError && error.code === 'UNAUTHORIZED')
33
+ return 'refused';
34
+ return 'error';
35
+ }
36
+ /** How often a live connection's transport stats are read, in milliseconds. */
37
+ const TRANSPORT_STATS_MS = 1_000;
38
+ /** A number rounded to a tenth. */
39
+ const tenths = (value) => Math.round(value * 10) / 10;
40
+ /**
41
+ * The fields of a WebTransport `getStats()` result (WebTransportConnectionStats) the `transport` section reports, under
42
+ * its own names, units in the names. A field the runtime does not give is left out: Chromium gives the three RTTs and
43
+ * the estimated send rate, and none of the byte and packet counters.
44
+ */
45
+ const TRANSPORT_FIELDS = [
46
+ ['smoothedRtt', 'rttMs', tenths],
47
+ ['rttVariation', 'rttVarMs', tenths],
48
+ ['minRtt', 'minRttMs', tenths],
49
+ ['bytesSent', 'sentBytes', Math.round],
50
+ ['bytesReceived', 'receivedBytes', Math.round],
51
+ ['packetsSent', 'sentPackets', Math.round],
52
+ ['packetsReceived', 'receivedPackets', Math.round],
53
+ ['packetsLost', 'lostPackets', Math.round],
54
+ ['bytesLost', 'lostBytes', Math.round],
55
+ // Bits per second.
56
+ ['estimatedSendRate', 'sendRateKbps', (bps) => Math.round(bps / 1000)],
57
+ ];
58
+ /** A transport's stats, as the `transport` section reports them: only the fields that are finite numbers (or BigInts). */
59
+ export function transportStats(raw) {
60
+ const out = {};
61
+ if (typeof raw !== 'object' || raw === null)
62
+ return out;
63
+ const stats = raw;
64
+ for (const [from, to, convert] of TRANSPORT_FIELDS) {
65
+ const value = typeof stats[from] === 'bigint' ? Number(stats[from]) : stats[from];
66
+ if (typeof value === 'number' && Number.isFinite(value))
67
+ out[to] = convert(value);
68
+ }
69
+ const capacity = stats['atSendCapacity'];
70
+ if (typeof capacity === 'boolean')
71
+ out['atSendCapacity'] = capacity;
72
+ return out;
73
+ }
74
+ /**
75
+ * What a supervisor reports, under the scope it is given: a `link` event on each status change (with what carries the
76
+ * connection and the relay's host when it goes live, and the error that ended the last one), a `dial` event per
77
+ * connection attempt and a `fallback` event when its factory fell back, a `publication` event per root it publishes, a
78
+ * `link` section, and while a connection whose transport has `getStats()` is live, a `transport` section.
79
+ */
80
+ export function linkDiagnostics(diagnostics) {
81
+ let attempts = 0;
82
+ let stopWatching;
83
+ const state = { status: 'connecting', connects: 0 };
84
+ diagnostics.section('link', () => ({ ...state }));
85
+ return {
86
+ status(status, error) {
87
+ state.status = status;
88
+ if (status === 'live')
89
+ state.connects++;
90
+ diagnostics.event('link', {
91
+ status,
92
+ ...(status === 'live' && state.carrier ? { carrier: state.carrier } : {}),
93
+ ...(status === 'live' && state.relay ? { relay: state.relay } : {}),
94
+ ...(error === undefined ? {} : { error: describeFailure(error) }),
95
+ });
96
+ },
97
+ /** The connection that is about to go live: what carries it, and the endpoint it reached. */
98
+ carrier(framing, endpoint) {
99
+ state.carrier = framing;
100
+ const relay = endpoint === undefined ? undefined : endpointHost(endpoint);
101
+ if (relay === undefined)
102
+ delete state.relay;
103
+ else
104
+ state.relay = relay;
105
+ },
106
+ generation(generation) {
107
+ state.generation = generation;
108
+ diagnostics.event('generation', { generation });
109
+ },
110
+ /**
111
+ * A connection attempt ended: a `dial` event with its number, the carrier and relay host it reached, how long it
112
+ * took from its start, and how it ended; and a `fallback` event first when the factory fell back.
113
+ */
114
+ dial(startedAt, report, error) {
115
+ const attempt = ++attempts;
116
+ const ms = Math.round(performance.now() - startedAt);
117
+ const relay = report?.endpoint === undefined ? undefined : endpointHost(report.endpoint);
118
+ const fallback = report?.fallback;
119
+ if (fallback) {
120
+ diagnostics.event('fallback', {
121
+ attempt,
122
+ from: fallback.from,
123
+ to: fallback.to,
124
+ reason: fallback.reason,
125
+ ...(fallback.error === undefined ? {} : { error: describeFailure(fallback.error) }),
126
+ });
127
+ }
128
+ // On a failure after a fallback, the carrier last dialed.
129
+ const carrier = error === undefined ? report?.framing : (fallback?.to ?? report?.framing);
130
+ diagnostics.event('dial', {
131
+ attempt,
132
+ ...(carrier === undefined ? {} : { carrier }),
133
+ ...(relay === undefined ? {} : { relay }),
134
+ ms,
135
+ outcome: error === undefined ? 'ok' : dialOutcome(error),
136
+ ...(error === undefined ? {} : { error: describeFailure(error) }),
137
+ });
138
+ },
139
+ /**
140
+ * The connection that just went live: read its transport's `getStats()` about once a second into a `transport`
141
+ * section, until `ended` aborts or another connection goes live. Nothing for a transport without it.
142
+ */
143
+ watch(transport, ended) {
144
+ stopWatching?.();
145
+ stopWatching = undefined;
146
+ const getStats = transport?.getStats;
147
+ if (typeof getStats !== 'function' || ended.aborted)
148
+ return;
149
+ let removeSection;
150
+ let reading = false;
151
+ let stopped = false;
152
+ // `getStats()` is async: the section reads what the last call gave, and a call still pending is not repeated.
153
+ // A transport that gives none of the fields (a WebSocket behind a fallback) has no section, not an empty one.
154
+ const read = () => {
155
+ if (reading)
156
+ return;
157
+ reading = true;
158
+ Promise.resolve()
159
+ .then(() => getStats.call(transport))
160
+ .then((raw) => {
161
+ // A read that settles after this connection ended, or another went live, adds nothing.
162
+ if (stopped || ended.aborted)
163
+ return;
164
+ const stats = transportStats(raw);
165
+ removeSection?.();
166
+ removeSection =
167
+ Object.keys(stats).length === 0 ? undefined : diagnostics.section('transport', () => ({ ...stats }));
168
+ }, () => { })
169
+ .finally(() => {
170
+ reading = false;
171
+ });
172
+ };
173
+ read();
174
+ const timer = setInterval(read, TRANSPORT_STATS_MS);
175
+ const stop = () => {
176
+ stopped = true;
177
+ clearInterval(timer);
178
+ removeSection?.();
179
+ ended.removeEventListener('abort', stop);
180
+ if (stopWatching === stop)
181
+ stopWatching = undefined;
182
+ };
183
+ stopWatching = stop;
184
+ ended.addEventListener('abort', stop, { once: true });
185
+ },
186
+ /** A root published, or its publication closed: a `publication` event with its namespace. */
187
+ publication(root, what) {
188
+ diagnostics.event('publication', { what, namespace: root.join('/') });
189
+ },
190
+ };
191
+ }
192
+ /** The MOQT stream reset code DELIVERY_TIMEOUT (draft-22 §12.5). */
193
+ const DELIVERY_TIMEOUT_CODE = 0x2;
194
+ /**
195
+ * What a supervised subscriber reports about its wants, under the scope it is given: a `want` event at each turn of a
196
+ * want's life (`subscribed`, `first-object` with how long it took, `restarted` with the reason and, for a catch-up,
197
+ * how far behind it was, `switched` with how long the replacement took to its first object, `publisher-done`,
198
+ * `error`), and a `wants` section with each want's track, whether it is subscribed, the objects it delivered, its
199
+ * restarts, its first object's delay and its reset groups.
200
+ */
201
+ export function wantDiagnostics(diagnostics) {
202
+ const wants = new Map();
203
+ const delays = new Map();
204
+ diagnostics.section('wants', () => Object.fromEntries([...wants].map(([key, state]) => [key, { ...state }])));
205
+ return {
206
+ /**
207
+ * The handlers to deliver to: `handlers`, each lifecycle callback reported first. `switchMs` says how long the
208
+ * move that just cut over took, from its replacement's SUBSCRIBE to the object that cut over.
209
+ */
210
+ observe(key, track, handlers, switchMs) {
211
+ const state = wants.get(key) ?? {
212
+ track,
213
+ subscribed: false,
214
+ objects: 0,
215
+ restarts: 0,
216
+ groupResets: 0,
217
+ deliveryTimeouts: 0,
218
+ };
219
+ state.track = track;
220
+ wants.set(key, state);
221
+ const delay = delays.get(key) ?? { wantedAt: performance.now(), trackProperties: [] };
222
+ delays.set(key, delay);
223
+ const fresh = (trackProperties) => {
224
+ delay.trackProperties = trackProperties;
225
+ delete delay.least;
226
+ delete delay.latest;
227
+ };
228
+ return {
229
+ ...handlers,
230
+ onSubscribed(info, context) {
231
+ state.subscribed = true;
232
+ fresh(info.trackProperties);
233
+ diagnostics.event('want', {
234
+ want: key,
235
+ what: 'subscribed',
236
+ namespace: context.namespace.join('/'),
237
+ track: state.track,
238
+ });
239
+ handlers.onSubscribed?.(info, context);
240
+ },
241
+ onObject(object) {
242
+ state.objects++;
243
+ const now = performance.now();
244
+ if (state.firstObjectMs === undefined) {
245
+ state.firstObjectMs = Math.round(now - delay.wantedAt);
246
+ diagnostics.event('want', { want: key, what: 'first-object', firstObjectMs: state.firstObjectMs });
247
+ }
248
+ const mediaMs = mediaTimeMs(object.properties, delay.trackProperties);
249
+ if (mediaMs !== undefined) {
250
+ delay.latest = now - mediaMs;
251
+ delay.least = Math.min(delay.least ?? delay.latest, delay.latest);
252
+ }
253
+ handlers.onObject?.(object);
254
+ },
255
+ onSubgroupReset(info) {
256
+ state.groupResets++;
257
+ if (streamErrorCode(info.error) === DELIVERY_TIMEOUT_CODE)
258
+ state.deliveryTimeouts++;
259
+ handlers.onSubgroupReset?.(info);
260
+ },
261
+ onPublisherDone(info) {
262
+ diagnostics.event('want', { want: key, what: 'publisher-done', statusCode: info.statusCode });
263
+ handlers.onPublisherDone?.(info);
264
+ },
265
+ onRestarted(info) {
266
+ state.subscribed = false;
267
+ state.restarts++;
268
+ state.lastRestart = info.reason;
269
+ const behind = info.reason === 'catch-up' && delay.latest !== undefined && delay.least !== undefined
270
+ ? { behindMs: Math.round(delay.latest - delay.least) }
271
+ : {};
272
+ fresh([]);
273
+ diagnostics.event('want', { want: key, what: 'restarted', reason: info.reason, ...behind });
274
+ handlers.onRestarted?.(info);
275
+ },
276
+ onSwitched(info) {
277
+ fresh(info.subscribed.trackProperties);
278
+ const ms = switchMs();
279
+ diagnostics.event('want', {
280
+ want: key,
281
+ what: 'switched',
282
+ from: [...info.from.namespace, info.from.track].join('/'),
283
+ to: [...info.to.namespace, info.to.track].join('/'),
284
+ ...(ms === undefined ? {} : { firstObjectMs: ms }),
285
+ });
286
+ handlers.onSwitched?.(info);
287
+ },
288
+ onError(error) {
289
+ state.subscribed = false;
290
+ diagnostics.event('want', { want: key, what: 'error', error: describeFailure(error) });
291
+ handlers.onError?.(error);
292
+ },
293
+ };
294
+ },
295
+ /** The want is gone: drop it from the section. */
296
+ forget(key) {
297
+ wants.delete(key);
298
+ delays.delete(key);
299
+ },
300
+ /** The subscriber stopped: every want is gone. */
301
+ forgetAll() {
302
+ wants.clear();
303
+ delays.clear();
304
+ },
305
+ };
306
+ }
307
+ /** The code a stream error carries (TA-22): an integer `streamErrorCode`, or `undefined`. */
308
+ function streamErrorCode(error) {
309
+ const code = typeof error === 'object' && error !== null ? error.streamErrorCode : undefined;
310
+ return typeof code === 'number' ? code : undefined;
311
+ }
312
+ /** LOC's Timestamp and Timescale property types (draft-ietf-moq-loc). */
313
+ const LOC_TIMESTAMP = 0x10;
314
+ const LOC_TIMESCALE = 0x08;
315
+ /** The first integer value of `type` among `properties`. */
316
+ function integerProperty(properties, type) {
317
+ for (const property of properties ?? []) {
318
+ if (property.type === type && typeof property.value === 'number')
319
+ return property.value;
320
+ }
321
+ return undefined;
322
+ }
323
+ /**
324
+ * An object's media time in milliseconds: its LOC Timestamp (0x10) in the Timescale (0x08) its own properties declare,
325
+ * else the track's, else microseconds (LOC's default). `undefined` without a Timestamp.
326
+ */
327
+ export function mediaTimeMs(properties, trackProperties) {
328
+ const timestamp = integerProperty(properties, LOC_TIMESTAMP);
329
+ if (timestamp === undefined)
330
+ return undefined;
331
+ const timescale = integerProperty(properties, LOC_TIMESCALE) ?? integerProperty(trackProperties, LOC_TIMESCALE);
332
+ return (timestamp * 1000) / (timescale && timescale > 0 ? timescale : 1_000_000);
333
+ }
334
+ /**
335
+ * The shortest interval that is a gap, how many usual intervals one must be, and how many intervals set the usual one
336
+ * (their median) before any gap is judged, so a slow cadence is learned, not reported.
337
+ */
338
+ const GAP_MIN_MS = 250;
339
+ const GAP_INTERVALS = 8;
340
+ const GAP_LEARN = 4;
341
+ /**
342
+ * Judges intervals between frames: a gap is over 250 ms and over eight times the usual interval, which is the median
343
+ * of the first four and then a moving average of the intervals that were not gaps. Returns whether `intervalMs` is one.
344
+ */
345
+ export function gapJudge() {
346
+ let usualMs;
347
+ const learning = [];
348
+ return (intervalMs) => {
349
+ if (usualMs === undefined) {
350
+ learning.push(intervalMs);
351
+ if (learning.length === GAP_LEARN)
352
+ usualMs = learning.sort((a, b) => a - b)[Math.floor(GAP_LEARN / 2)];
353
+ return false;
354
+ }
355
+ if (intervalMs > Math.max(GAP_MIN_MS, GAP_INTERVALS * usualMs))
356
+ return true;
357
+ // A gap does not move the average.
358
+ usualMs = usualMs * 0.95 + intervalMs * 0.05;
359
+ return false;
360
+ };
361
+ }
362
+ /** How far back the delay spread looks, and the most samples it keeps. */
363
+ const SPREAD_WINDOW_MS = 5_000;
364
+ const SPREAD_SAMPLES = 2_048;
365
+ /**
366
+ * The spread of arrival delays over the last five seconds: each object's arrival time less its media time, relative to
367
+ * the least in the window, so the two clocks need no sync. `read` gives the median, the 95th percentile and the most,
368
+ * in whole milliseconds, or `undefined` with no samples in the window.
369
+ */
370
+ export function delaySpread() {
371
+ const samples = [];
372
+ return {
373
+ add(at, delayMs) {
374
+ samples.push({ at, delayMs });
375
+ if (samples.length > SPREAD_SAMPLES)
376
+ samples.shift();
377
+ },
378
+ clear() {
379
+ samples.length = 0;
380
+ },
381
+ read(now) {
382
+ while (samples.length > 0 && samples[0].at < now - SPREAD_WINDOW_MS)
383
+ samples.shift();
384
+ if (samples.length === 0)
385
+ return undefined;
386
+ const least = Math.min(...samples.map((sample) => sample.delayMs));
387
+ const spread = samples.map((sample) => sample.delayMs - least).sort((a, b) => a - b);
388
+ // Nearest rank: the smallest value with at least that share of the samples at or below it.
389
+ const at = (q) => Math.round(spread[Math.max(0, Math.ceil(q * spread.length) - 1)]);
390
+ return { p50: at(0.5), p95: at(0.95), max: Math.round(spread[spread.length - 1]) };
391
+ },
392
+ };
393
+ }
394
+ /** How many of the newest locations a reorder count keeps, to say how long an overtaken object waited. */
395
+ const REORDER_KEPT = 256;
396
+ /**
397
+ * Counts objects that arrive after a later one of the same subscription (by group, then object), and the longest any
398
+ * of them arrived after the first object that overtook it.
399
+ */
400
+ export function reorderCount() {
401
+ /** The newest location so far each time it moved, with when: ascending by location. */
402
+ const advances = [];
403
+ let reordered = 0;
404
+ let longestWaitMs = 0;
405
+ const compare = (a, b) => a.group - b.group || a.object - b.object;
406
+ return {
407
+ arrived(object, at) {
408
+ const here = { group: object.groupId, object: object.objectId };
409
+ const newest = advances[advances.length - 1];
410
+ if (newest === undefined || compare(here, newest) > 0) {
411
+ advances.push({ ...here, at });
412
+ if (advances.length > REORDER_KEPT)
413
+ advances.shift();
414
+ return;
415
+ }
416
+ if (compare(here, newest) === 0)
417
+ return;
418
+ reordered++;
419
+ // The first object past this one; an older one than kept is at least as old as the oldest kept.
420
+ const overtook = advances.find((advance) => compare(advance, here) > 0) ?? advances[0];
421
+ if (overtook)
422
+ longestWaitMs = Math.max(longestWaitMs, at - overtook.at);
423
+ },
424
+ /** A new subscription numbers its own groups. */
425
+ restart() {
426
+ advances.length = 0;
427
+ },
428
+ get reordered() {
429
+ return reordered;
430
+ },
431
+ get longestWaitMs() {
432
+ return Math.round(longestWaitMs);
433
+ },
434
+ };
435
+ }
436
+ /** A `diagnostics` option: `undefined`, or a recorder or scope from `createDiagnostics`; anything else is a TypeError. */
437
+ export function diagnosticsOption(value) {
438
+ if (value === undefined)
439
+ return undefined;
440
+ const given = value;
441
+ if (typeof given !== 'object' ||
442
+ given === null ||
443
+ typeof given.event !== 'function' ||
444
+ typeof given.section !== 'function' ||
445
+ typeof given.scope !== 'function') {
446
+ throw new TypeError('diagnostics must come from createDiagnostics');
447
+ }
448
+ return given;
449
+ }
450
+ //# sourceMappingURL=diagnostics-report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics-report.js","sourceRoot":"","sources":["../src/diagnostics-report.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,IAAY,CAAC;IACjB,IAAI,KAAK,YAAY,UAAU;QAAE,IAAI,GAAG,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;SACtF,IAAI,KAAK,YAAY,KAAK;QAAE,IAAI,GAAG,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;;QACrE,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,OAAO,IAAI;SACR,OAAO,CAAC,sBAAsB,EAAE,cAAc,CAAC;SAC/C,OAAO,CAAC,4BAA4B,EAAE,OAAO,CAAC;SAC9C,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACnB,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,YAAY,CAAC,QAAgB;IAC3C,IAAI,CAAC;QACH,OA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;QACd,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU;QACjC,OAAO,KAAK,CAAC,OAAO,KAAK,UAAU;QACnC,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,EACjC,CAAC;QACD,MAAM,IAAI,SAAS,CAAC,8CAA8C,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,KAAoB,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `@caprid/relay/diagnostics`: client diagnostics (spec/behavior.md, "Client diagnostics"; TypeScript only). A
3
+ * recorder holds what a client saw, as events and stats sections; `publishDiagnostics` puts it on two tracks of a
4
+ * publication of the client's own, by convention `<account>/diag/<app>/<group>/<client>`, sent only while something
5
+ * subscribes; `followDiagnostics` reads them from elsewhere, for a collector or an operator. Every client can report,
6
+ * a player that publishes no media too. `watchPage` and `watchAudioInput` add the page and an audio input.
7
+ *
8
+ * ```ts
9
+ * import { createDiagnostics, publishDiagnostics } from '@caprid/relay/diagnostics';
10
+ *
11
+ * const diagnostics = createDiagnostics({ app: { name: 'huddle', build } });
12
+ * const relay = await connectSupervisedRelay({ getToken, diagnostics });
13
+ * publishDiagnostics(diagnostics, relay.publish(['diag', 'huddle', room, pid]));
14
+ * diagnostics.event('app.joined', { participant: pid });
15
+ * ```
16
+ *
17
+ * @packageDocumentation
18
+ */
19
+ export { createDiagnostics, DIAGNOSTICS_TRACKS, type DiagnosticEvent, type Diagnostics, type DiagnosticsApp, type DiagnosticsEventsObject, type DiagnosticsOptions, type DiagnosticsPublication, type DiagnosticsPublisher, type DiagnosticsStatsObject, type FollowDiagnosticsHandlers, type FollowDiagnosticsOptions, followDiagnostics, type PublishDiagnosticsOptions, publishDiagnostics, type WatchedAudioInput, watchAudioInput, watchPage, } from './client-diagnostics.js';
20
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,eAAe,EACf,SAAS,GACV,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `@caprid/relay/diagnostics`: client diagnostics (spec/behavior.md, "Client diagnostics"; TypeScript only). A
3
+ * recorder holds what a client saw, as events and stats sections; `publishDiagnostics` puts it on two tracks of a
4
+ * publication of the client's own, by convention `<account>/diag/<app>/<group>/<client>`, sent only while something
5
+ * subscribes; `followDiagnostics` reads them from elsewhere, for a collector or an operator. Every client can report,
6
+ * a player that publishes no media too. `watchPage` and `watchAudioInput` add the page and an audio input.
7
+ *
8
+ * ```ts
9
+ * import { createDiagnostics, publishDiagnostics } from '@caprid/relay/diagnostics';
10
+ *
11
+ * const diagnostics = createDiagnostics({ app: { name: 'huddle', build } });
12
+ * const relay = await connectSupervisedRelay({ getToken, diagnostics });
13
+ * publishDiagnostics(diagnostics, relay.publish(['diag', 'huddle', room, pid]));
14
+ * diagnostics.event('app.joined', { participant: pid });
15
+ * ```
16
+ *
17
+ * @packageDocumentation
18
+ */
19
+ export { createDiagnostics, DIAGNOSTICS_TRACKS, followDiagnostics, publishDiagnostics, watchAudioInput, watchPage, } from './client-diagnostics.js';
20
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAWlB,iBAAiB,EAEjB,kBAAkB,EAElB,eAAe,EACf,SAAS,GACV,MAAM,yBAAyB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { KeyValuePair, MoqtObject, SubscribeOk } from '@caprid/moq-core';
2
+ import type { Diagnostics } from './client-diagnostics.js';
2
3
  import type { WantSwitchedInfo } from './supervised-subscriber.js';
3
4
  /**
4
5
  * What a {@link FrameReader} drives: `@caprid/moq-media`'s `FrameSequencer` qualifies. The reader feeds it a
@@ -24,6 +25,8 @@ export interface FrameReaderSequencer<F> {
24
25
  /** The sequencer asks for the subscription to be replaced at the live edge: see `onCatchUp`. */
25
26
  catchUp?: boolean;
26
27
  };
28
+ /** Counters a reader with diagnostics reports, when the sequencer keeps them: a `FrameSequencer`'s do. */
29
+ readonly stats?: object;
27
30
  }
28
31
  /** Options for {@link createFrameReader}. */
29
32
  export interface FrameReaderOptions<F> {
@@ -39,6 +42,15 @@ export interface FrameReaderOptions<F> {
39
42
  * frames of the same poll; an exception from it goes to `console.error`.
40
43
  */
41
44
  onCatchUp?(): void;
45
+ /**
46
+ * A scope from `@caprid/relay/diagnostics` (spec/behavior.md, "Client diagnostics"), such as
47
+ * `diagnostics.scope('p2/audio')`: the reader reports a `receive` section with the objects it read and their
48
+ * payload bytes, its arrival gaps and the longest, the objects that arrived after a later one and the longest such
49
+ * wait, the spread of arrival delays over the last five seconds, and the sequencer's `stats`, and an `arrival-gap`
50
+ * event when objects stop for longer than 250 ms, or eight times their usual interval if that is longer. The usual
51
+ * interval is learned from the first four before any gap is judged. Give each reader its own scope.
52
+ */
53
+ diagnostics?: Diagnostics;
42
54
  }
43
55
  /**
44
56
  * A subscription's or a want's handlers that read its track as frames in decode order. Pass it, or spread it with
@@ -1 +1 @@
1
- {"version":3,"file":"frame-reader.d.ts","sourceRoot":"","sources":["../src/frame-reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WA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