@caprid/relay 0.5.0 → 0.7.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 (83) hide show
  1. package/README.md +55 -54
  2. package/dist/client-diagnostics.d.ts +249 -0
  3. package/dist/client-diagnostics.d.ts.map +1 -0
  4. package/dist/client-diagnostics.js +608 -0
  5. package/dist/client-diagnostics.js.map +1 -0
  6. package/dist/cmcd.d.ts +99 -0
  7. package/dist/cmcd.d.ts.map +1 -0
  8. package/dist/cmcd.js +631 -0
  9. package/dist/cmcd.js.map +1 -0
  10. package/dist/connect-session.d.ts +65 -5
  11. package/dist/connect-session.d.ts.map +1 -1
  12. package/dist/connect-session.js +116 -12
  13. package/dist/connect-session.js.map +1 -1
  14. package/dist/connect.d.ts +10 -2
  15. package/dist/connect.d.ts.map +1 -1
  16. package/dist/connect.js +3 -2
  17. package/dist/connect.js.map +1 -1
  18. package/dist/diagnostics-report.d.ts +115 -0
  19. package/dist/diagnostics-report.d.ts.map +1 -0
  20. package/dist/diagnostics-report.js +475 -0
  21. package/dist/diagnostics-report.js.map +1 -0
  22. package/dist/diagnostics.d.ts +23 -0
  23. package/dist/diagnostics.d.ts.map +1 -0
  24. package/dist/diagnostics.js +23 -0
  25. package/dist/diagnostics.js.map +1 -0
  26. package/dist/frame-reader.d.ts +18 -3
  27. package/dist/frame-reader.d.ts.map +1 -1
  28. package/dist/frame-reader.js +86 -3
  29. package/dist/frame-reader.js.map +1 -1
  30. package/dist/frame-writer.d.ts +17 -1
  31. package/dist/frame-writer.d.ts.map +1 -1
  32. package/dist/frame-writer.js +95 -5
  33. package/dist/frame-writer.js.map +1 -1
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js.map +1 -1
  37. package/dist/media-track-properties.d.ts +3 -2
  38. package/dist/media-track-properties.d.ts.map +1 -1
  39. package/dist/media-track-properties.js +3 -2
  40. package/dist/media-track-properties.js.map +1 -1
  41. package/dist/publish.d.ts +19 -6
  42. package/dist/publish.d.ts.map +1 -1
  43. package/dist/publish.js +17 -4
  44. package/dist/publish.js.map +1 -1
  45. package/dist/relay-session.d.ts.map +1 -1
  46. package/dist/relay-session.js +3 -1
  47. package/dist/relay-session.js.map +1 -1
  48. package/dist/replaceable-track.d.ts +2 -2
  49. package/dist/replaceable-track.d.ts.map +1 -1
  50. package/dist/replaceable-track.js +8 -2
  51. package/dist/replaceable-track.js.map +1 -1
  52. package/dist/subscription.d.ts.map +1 -1
  53. package/dist/subscription.js +22 -8
  54. package/dist/subscription.js.map +1 -1
  55. package/dist/supervised-publisher.d.ts +22 -1
  56. package/dist/supervised-publisher.d.ts.map +1 -1
  57. package/dist/supervised-publisher.js +11 -2
  58. package/dist/supervised-publisher.js.map +1 -1
  59. package/dist/supervised-relay.d.ts +23 -1
  60. package/dist/supervised-relay.d.ts.map +1 -1
  61. package/dist/supervised-relay.js +12 -3
  62. package/dist/supervised-relay.js.map +1 -1
  63. package/dist/supervised-subscriber.d.ts +28 -8
  64. package/dist/supervised-subscriber.d.ts.map +1 -1
  65. package/dist/supervised-subscriber.js +36 -11
  66. package/dist/supervised-subscriber.js.map +1 -1
  67. package/dist/supervision.d.ts +18 -0
  68. package/dist/supervision.d.ts.map +1 -1
  69. package/dist/supervision.js +34 -0
  70. package/dist/supervision.js.map +1 -1
  71. package/dist/supervisor.d.ts +23 -9
  72. package/dist/supervisor.d.ts.map +1 -1
  73. package/dist/supervisor.js +193 -14
  74. package/dist/supervisor.js.map +1 -1
  75. package/dist/version.d.ts +6 -0
  76. package/dist/version.d.ts.map +1 -0
  77. package/dist/version.js +6 -0
  78. package/dist/version.js.map +1 -0
  79. package/dist/write-slot.d.ts +11 -0
  80. package/dist/write-slot.d.ts.map +1 -1
  81. package/dist/write-slot.js +16 -1
  82. package/dist/write-slot.js.map +1 -1
  83. package/package.json +13 -9
package/README.md CHANGED
@@ -1,24 +1,27 @@
1
1
  # @caprid/relay
2
2
 
3
- The Relay TypeScript SDK. `connectRelaySubscriber` subscribes to track objects and
4
- `connectRelayPublisher` publishes them, through Relay, Caprid's Media over QUIC (MoQ) relay service.
5
- The SDK does not interpret payloads, so you need no player, media catalog, or Video.js.
3
+ `@caprid/relay` is the Relay TypeScript SDK for browsers and Node. With `@caprid/moq-media` it also
4
+ plays live video and audio in a browser page, with no UI.
5
+
6
+ `connectSupervisedPublisher` and `connectSupervisedSubscriber` publish and subscribe to track objects
7
+ through Relay, Caprid's Media over QUIC (MoQ) relay service, with automatic reconnection and
8
+ credential rotation. Payloads are raw bytes, so a data track needs no media catalog or player. For
9
+ live media, [`@caprid/moq-media`](https://github.com/caprids/relay-sdks/blob/main/ts/packages/moq-media/README.md)
10
+ maps WebCodecs chunks to LOC, reads and writes MSF catalogs, and provides headless audio and video
11
+ players ([browser audio & video](https://www.caprid.com/docs/media/browser/)).
6
12
 
7
13
  ## Requirements
8
14
 
9
- - Browser WebTransport in a secure context (HTTPS or localhost). This is the default transport.
10
- It needs WebTransport protocol negotiation, which the live tests verify against the Relay in
11
- Chromium and in Firefox 155 or later (Playwright's builds). WebKit cannot open a WebTransport
12
- session to the Relay yet.
13
- - Node 24 or later: import from `@caprid/relay/node`, which connects over native QUIC through
14
- `@caprid/relay-quic` ([Node](#node)). Other runtimes must pass a compatible `createTransport`
15
- factory.
16
- - Where UDP is blocked, or the browser has no usable WebTransport (Safari), pass
17
- [`@caprid/relay-websocket`](https://github.com/caprids/relay-sdks/blob/main/ts/packages/relay-websocket/README.md)'s `withWebSocketFallback()` or
18
- `createWebSocketTransport()` as `createTransport`. The connection then runs QMux over WebSocket on
19
- TCP 443 ([networks without UDP](https://github.com/caprids/relay-sdks/blob/main/ts/GUIDE.md#networks-without-udp-qmux-over-websocket)).
20
- - A short-lived Relay JWT authorized for the namespace you use, and the endpoint of any relay other
21
- than the hosted one. The SDK consumes tokens. It does not issue them.
15
+ - **Browsers**: WebTransport in a secure context (HTTPS or localhost) is the default transport
16
+ (verified in Chromium and Firefox 155+).
17
+ - **Node 24+**: import from `@caprid/relay/node`, which connects over native QUIC through
18
+ `@caprid/relay-quic` ([Node](#node)).
19
+ - **Networks without UDP / Safari**: pass
20
+ [`@caprid/relay-websocket`](https://github.com/caprids/relay-sdks/blob/main/ts/packages/relay-websocket/README.md)'s
21
+ `withWebSocketFallback()` or `createWebSocketTransport()` as `createTransport` to run QMux over
22
+ WebSocket on TCP 443 ([networks without UDP](https://www.caprid.com/docs/relay/connecting/#networks-without-udp-typescript)).
23
+ - **Credentials**: a short-lived Relay JWT authorized for the namespace you use (and an explicit
24
+ `url` only for a relay other than the hosted one). The SDK consumes tokens; it does not issue them.
22
25
 
23
26
  ## Install
24
27
 
@@ -26,54 +29,52 @@ The SDK does not interpret payloads, so you need no player, media catalog, or Vi
26
29
  npm install @caprid/relay
27
30
  ```
28
31
 
29
- Add `@caprid/relay-quic` for Node ([Node](#node)), `@caprid/relay-websocket` for networks without
30
- UDP, and `@caprid/moq-media` to publish or play media. To build the packages from a checkout of this
31
- repository instead, see
32
- [Use the local packages in your application](https://github.com/caprids/relay-sdks/blob/main/ts/GUIDE.md#use-the-local-packages-in-your-application).
32
+ Optional companion packages (install matching versions):
33
+
34
+ | Package | When to add it |
35
+ | --- | --- |
36
+ | `@caprid/relay-quic` | Node 24+ native QUIC transport (`@caprid/relay/node`) |
37
+ | `@caprid/relay-websocket` | Fallback over TCP 443 for Safari or UDP-blocked networks |
38
+ | `@caprid/moq-media` | Live browser audio/video players, LOC framing, MSF catalogs |
39
+ | `@caprid/moq-mediabunny` | Publish existing media files with Mediabunny |
33
40
 
34
41
  ## Publish and subscribe
35
42
 
36
43
  ```ts
37
- import { connectRelayPublisher, connectRelaySubscriber, readText } from '@caprid/relay';
44
+ import { connectSupervisedPublisher, connectSupervisedSubscriber, readText } from '@caprid/relay';
38
45
 
39
- const getToken = () => token; // a Relay JWT allowed to publish and subscribe under its root
46
+ const getToken = () => token; // short-lived Relay JWT
40
47
  const namespace = ['quickstart', 'unique-run']; // relative to the token's root
41
48
 
42
- const publisher = await connectRelayPublisher({ namespace, getToken });
49
+ const publisher = await connectSupervisedPublisher({ namespace, getToken });
43
50
  const ticker = publisher.registerTrack({ track: 'ticker' });
44
- await publisher.announced;
45
51
 
46
- const subscriber = await connectRelaySubscriber({ getToken });
47
- let received: (text: string) => void;
48
- const arrived = new Promise<string>((resolve) => { received = resolve; });
49
- const subscription = subscriber.subscribe(
50
- { namespace, track: 'ticker' },
51
- { onObject: (object) => { if (object.status === 'normal') received(readText(object)); } },
52
- );
53
- await subscription.subscribed; // a fresh namespace can briefly reject this with error 16; retry it
52
+ const subscriber = await connectSupervisedSubscriber({ getToken });
53
+ const arrived = new Promise<string>((resolve) => {
54
+ subscriber.want(
55
+ 'ticker',
56
+ { namespace, track: 'ticker', generations: true },
57
+ { onObject: (object) => { if (object.status === 'normal') resolve(readText(object)); } },
58
+ );
59
+ });
54
60
 
55
- await ticker.writeText('hello from @caprid/relay'); // waits for the subscriber's demand
61
+ await ticker.writeText('hello from @caprid/relay');
56
62
  console.log(await arrived);
57
63
  subscriber.close();
58
64
  await publisher.close();
59
65
  ```
60
66
 
61
- With no `url`, each connection dials the hosted Relay, `https://relay.mux.global`, with the
62
- token's root as the path, so namespaces are relative to that root. Pass `url` for another relay,
63
- region or room; `roomEndpoint` builds one
64
- ([endpoint and credentials](https://github.com/caprids/relay-sdks/blob/main/ts/GUIDE.md#endpoint-and-credentials)).
65
-
66
- The [guide's full demo](https://github.com/caprids/relay-sdks/blob/main/ts/GUIDE.md#run-the-full-demo-from-a-checkout) runs the complete version of this, with
67
- credential handling, the subscribe retry, a deadline, and cleanup on failure.
68
-
69
- These connections never reconnect. For a live application, `connectSupervisedPublisher` and
70
- `connectSupervisedSubscriber` reconnect with backoff. They keep tracks registered and subscribed
71
- across connections and publisher restarts ([stay connected](https://github.com/caprids/relay-sdks/blob/main/ts/GUIDE.md#stay-connected-supervised-connections)).
67
+ With no `url`, each connection dials the hosted Relay (`https://relay.mux.global`) rooted at the
68
+ token's root, so namespaces are relative to that root. Pass `url` (or build one with
69
+ `roomEndpoint`) for another relay, region, or room. See
70
+ [Connecting & authentication](https://www.caprid.com/docs/relay/connecting/) and
71
+ [Low-level connections](https://www.caprid.com/docs/relay/low-level/) for single-shot
72
+ `connectRelayPublisher` / `connectRelaySubscriber` usage.
72
73
 
73
74
  ## Node
74
75
 
75
76
  `@caprid/relay/node` exports everything `@caprid/relay` does. Its `connectRelayPublisher`,
76
- `connectRelaySubscriber`, and both `connectSupervised*` functions connect over native QUIC through
77
+ `connectRelaySubscriber`, and all `connectSupervised*` functions connect over native QUIC through
77
78
  [`@caprid/relay-quic`](https://github.com/caprids/relay-sdks/blob/main/ts/packages/relay-quic/README.md), Caprid's transport adapter for Node. Native QUIC
78
79
  means MOQT directly on QUIC, with ALPN `moqt-22` and a fallback to `moqt-20`. Pass the same
79
80
  `https://` endpoint you pass in a browser.
@@ -168,12 +169,12 @@ install matching versions. A release supports:
168
169
 
169
170
  ## Documentation
170
171
 
171
- - [TypeScript guide](https://github.com/caprids/relay-sdks/blob/main/ts/GUIDE.md): the quickstart, subscription and publishing lifecycles, async
172
- consumption, supervised connections, publishing media, the audio and video players, and control
173
- and telemetry tracks.
174
- - API reference: run `mise run ts:docs` from a checkout to build it from the source into
175
- `ts/docs-api/`.
176
- - [Errors and recovery](https://github.com/caprids/relay-sdks/blob/main/ts/GUIDE.md#errors-and-recovery): stable `RelayError` codes and phases, and
177
- how to recover without assuming delivery or safe replay.
178
- - [Shared specification](https://github.com/caprids/relay-sdks/blob/main/spec/README.md): the protocol pins, behavior contract, and test vectors
179
- every Relay SDK implements.
172
+ - [Quickstart](https://www.caprid.com/docs/getting-started/quickstart/) and
173
+ [Relay guides](https://www.caprid.com/docs/relay/connecting/): connecting, pub/sub, discovery,
174
+ switching tracks, control & telemetry, errors & recovery, and browser media.
175
+ - [TypeScript API reference](https://www.caprid.com/docs/reference/typescript/): generated from the
176
+ source with TypeDoc.
177
+ - [Shared specification](https://www.caprid.com/docs/spec/): protocol pins, behavior contract, and
178
+ test vectors every Relay SDK implements.
179
+ - **AI agents**: machine-readable docs at [llms.txt](https://www.caprid.com/llms.txt) and the
180
+ installable Caprid skill at [SKILL.md](https://www.caprid.com/docs/agents/SKILL.md).
@@ -0,0 +1,249 @@
1
+ import type { MessageParameters } from '@caprid/moq-core';
2
+ import type { CmcdRecord } from './cmcd.js';
3
+ import type { RegisterTrackOptions, RelayTrackWriter } from './publish.js';
4
+ import type { SupervisedSubscriber } from './supervised-subscriber.js';
5
+ /**
6
+ * Client diagnostics (spec/behavior.md, "Client diagnostics"; TypeScript only): a recorder that holds what a client
7
+ * saw, published on two tracks of a publication of the client's own (by convention `<account>/diag/<app>/<group>/<client>`)
8
+ * while something subscribes, and followed from elsewhere. Every client can report, whether it publishes media or not.
9
+ * `diag.events` carries events, each with a sequence number; `diag.stats` carries a snapshot of every stats section
10
+ * once a second; `diag.cmcd` carries CMCD v2 records derived from them, when `publishCmcd` publishes it.
11
+ */
12
+ export declare const DIAGNOSTICS_TRACKS: {
13
+ /** Events, as {@link DiagnosticsEventsObject}s. */
14
+ readonly events: "diag.events";
15
+ /** Stats snapshots, as {@link DiagnosticsStatsObject}s. */
16
+ readonly stats: "diag.stats";
17
+ /** CMCD v2 records, each object an MSF Event Timeline array of `CmcdRecord`s. */
18
+ readonly cmcd: "diag.cmcd";
19
+ };
20
+ /** One thing a client saw. SDK kinds are plain words (`link`, `want`); an application's start with `app.`. */
21
+ export interface DiagnosticEvent {
22
+ /** Wall-clock time, in milliseconds since the epoch. */
23
+ readonly t: number;
24
+ /** The recorder's sequence number, from 0, one per event. */
25
+ readonly seq: number;
26
+ /** What happened. */
27
+ readonly kind: string;
28
+ /** The scope that recorded it, as {@link Diagnostics.scope} named it; absent for the recorder itself. */
29
+ readonly source?: string;
30
+ /** The event's own fields: ids and counters, never names or media. */
31
+ readonly [field: string]: unknown;
32
+ }
33
+ /** Options for {@link createDiagnostics}. */
34
+ export interface DiagnosticsOptions {
35
+ /** How long an event is held for a subscriber that arrives later, in milliseconds. Default 10 minutes. */
36
+ keepMs?: number;
37
+ /** The most events held, oldest dropped first. A positive integer; default 5000. */
38
+ keepEvents?: number;
39
+ /**
40
+ * The application and its build, for the `start` event: a follower then knows which bundle a client ran without
41
+ * asking. `name` is a non-empty string; `build` any string the app keeps, such as a commit or a release.
42
+ */
43
+ app?: DiagnosticsApp;
44
+ }
45
+ /** The application a recorder runs in, for its `start` event. */
46
+ export interface DiagnosticsApp {
47
+ /** The application's name, such as `huddle`. Non-empty. */
48
+ name: string;
49
+ /** Its build: a commit, a release, whatever the application keeps. */
50
+ build?: string;
51
+ }
52
+ /**
53
+ * A recorder of events and stats sections, or a scope of one. Create one with {@link createDiagnostics}; the SDK
54
+ * pieces that take a `diagnostics` option report into whichever they are given.
55
+ */
56
+ export interface Diagnostics {
57
+ /** A random id for this recorder. A follower tells two recorders, or a restarted client, apart by it. */
58
+ readonly instance: string;
59
+ /**
60
+ * Record an event and tell the listeners. `kind` is a non-empty string; `fields` are copied, except `t`, `seq` and
61
+ * `kind`, which the recorder sets, and in a scope `source`. Keep them to ids and counters: they leave the client.
62
+ */
63
+ event(kind: string, fields?: Readonly<Record<string, unknown>>): DiagnosticEvent;
64
+ /**
65
+ * The events still held whose sequence number is at least `seq`, oldest first: the `start` event, which is held for
66
+ * the recorder's life, then the rest. Also what an app can send its own server when the client never connects.
67
+ */
68
+ events(seq?: number): DiagnosticEvent[];
69
+ /** Call `listener` with each event as it is recorded. Returns the function that stops it. */
70
+ listen(listener: (event: DiagnosticEvent) => void): () => void;
71
+ /**
72
+ * Add a stats section: `read` is called for every snapshot and returns something JSON can encode, usually counters.
73
+ * In a scope the name is prefixed with the scope's and a dot. A section of the same name is replaced. Returns the
74
+ * function that removes this one.
75
+ */
76
+ section(name: string, read: () => unknown): () => void;
77
+ /** Every section's value now, by name, the whole recorder's from any scope. A section whose `read` throws reads `{ error }`. */
78
+ snapshot(): Record<string, unknown>;
79
+ /**
80
+ * The same recorder under a name: its events carry `source` (a scope of a scope joins the names with `/`) and its
81
+ * section names start with it. Give each link, reader or writer its own, such as `scope('roster')` or
82
+ * `scope('p2/audio')`.
83
+ */
84
+ scope(name: string): Diagnostics;
85
+ }
86
+ /**
87
+ * Record what a client sees, for {@link publishDiagnostics}. Pass it to the SDK pieces that report into it, and add
88
+ * your own events and sections.
89
+ *
90
+ * ```ts
91
+ * const diagnostics = createDiagnostics();
92
+ * diagnostics.event('app.joined', { participant: id });
93
+ * diagnostics.section('app.video', () => ({ layer, freezes }));
94
+ * ```
95
+ */
96
+ export declare function createDiagnostics(options?: DiagnosticsOptions): Diagnostics;
97
+ /**
98
+ * What {@link publishDiagnostics} registers its tracks on: a `RelayPublisher`, a `SupervisedPublisher`, or a root
99
+ * published on a `SupervisedRelay` (the `SupervisedPublication` that `relay.publish(root)` returns).
100
+ */
101
+ export interface DiagnosticsPublisher {
102
+ /** Register a track on the publisher's broadcast, as `RelayPublisher.registerTrack` does. */
103
+ registerTrack(options: RegisterTrackOptions): RelayTrackWriter;
104
+ }
105
+ /** Options for {@link publishDiagnostics}. */
106
+ export interface PublishDiagnosticsOptions {
107
+ /**
108
+ * How often a stats snapshot is sent while `diag.stats` has demand, in milliseconds. Default 1000. A snapshot the
109
+ * transport has not taken within two intervals is dropped: the next one supersedes it.
110
+ */
111
+ statsIntervalMs?: number;
112
+ /**
113
+ * The Default Publisher Priority (0x0E) of `diag.events`, an integer from 0 to 255, lower being more urgent.
114
+ * Default 224: behind every media track (audio 16, video 96), so diagnostics never hold media up on a congested
115
+ * uplink.
116
+ */
117
+ eventsPriority?: number;
118
+ /** The Default Publisher Priority (0x0E) of `diag.stats`, as `eventsPriority`. Default 240, behind events. */
119
+ statsPriority?: number;
120
+ }
121
+ /** The two diagnostics tracks being published. */
122
+ export interface DiagnosticsPublication {
123
+ /** Stop publishing and close both tracks. Idempotent. */
124
+ close(): Promise<void>;
125
+ }
126
+ /** One `diag.events` object: events of one recorder, live or (`backlog`) replayed from what it held. */
127
+ export interface DiagnosticsEventsObject {
128
+ /** The recorder's {@link Diagnostics.instance}. */
129
+ instance: string;
130
+ /** Present when the events are a replay of what the recorder held, not live. */
131
+ backlog?: true;
132
+ /** The events, oldest first. */
133
+ events: DiagnosticEvent[];
134
+ }
135
+ /** One `diag.stats` object: one recorder's sections at one moment. */
136
+ export interface DiagnosticsStatsObject {
137
+ /** The recorder's {@link Diagnostics.instance}. */
138
+ instance: string;
139
+ /** When the snapshot was taken: wall clock, milliseconds since the epoch. */
140
+ t: number;
141
+ /** Every section's value, by name, as {@link Diagnostics.snapshot} returns it. */
142
+ stats: Record<string, unknown>;
143
+ }
144
+ /**
145
+ * Publish a recorder on `diag.events` and `diag.stats` of the publisher's broadcast. Nothing is sent while the relay
146
+ * has no subscription to a track. Each time the relay subscribes to `diag.events`, everything the recorder holds goes
147
+ * first, marked `backlog`, then each event as it is recorded; a follower drops sequence numbers it has seen. Right
148
+ * after the relay replaces its subscription a few live events can still arrive ahead of the replay, so a follower
149
+ * that needs them in order sorts by `seq`. A
150
+ * snapshot goes on `diag.stats` once a second while it has demand. Track names are unique per publisher connection,
151
+ * so publish one recorder per publisher (on a `SupervisedRelay`, per published root).
152
+ *
153
+ * ```ts
154
+ * const publication = publishDiagnostics(diagnostics, publisher);
155
+ * // ...
156
+ * await publication.close();
157
+ * ```
158
+ */
159
+ export declare function publishDiagnostics(diagnostics: Diagnostics, publisher: DiagnosticsPublisher, options?: PublishDiagnosticsOptions): DiagnosticsPublication;
160
+ /** Where {@link followDiagnostics} reads: a client's broadcast, or a supervised publisher's root. */
161
+ export interface FollowDiagnosticsOptions {
162
+ /** The client's namespace, or with `generations` a supervised publisher's root. */
163
+ namespace: readonly string[];
164
+ /** Follow the newest generation under `namespace`, as a want does. */
165
+ generations?: boolean;
166
+ /**
167
+ * The prefix of the want keys, `<key>/diag.events`, `<key>/diag.stats` and with `onCmcd` `<key>/diag.cmcd`. Default
168
+ * the namespace joined by `/`.
169
+ */
170
+ key?: string;
171
+ /**
172
+ * Parameters for the `diag.events` subscription, such as a location filter that asks the relay for the groups it
173
+ * still holds: a follower that subscribes while another already does gets no replay from the client.
174
+ */
175
+ eventsParameters?: MessageParameters;
176
+ }
177
+ /** What {@link followDiagnostics} delivers. Like a want's handlers, they must be synchronous. */
178
+ export interface FollowDiagnosticsHandlers {
179
+ /** Events not delivered before, in the order they arrived; `backlog` when they came from a replay. */
180
+ onEvents?(events: DiagnosticEvent[], info: {
181
+ instance: string;
182
+ backlog: boolean;
183
+ }): void;
184
+ /** One stats snapshot. */
185
+ onStats?(stats: DiagnosticsStatsObject): void;
186
+ /**
187
+ * One `diag.cmcd` object's CMCD records, oldest first: one, or a batch. Given this handler, `diag.cmcd` is wanted
188
+ * too; without it, it is not, since a client publishes it only with `publishCmcd`.
189
+ */
190
+ onCmcd?(records: CmcdRecord[]): void;
191
+ /** A want's failure that it does not retry, as `WantHandlers.onError`. Objects that do not parse are skipped. */
192
+ onError?(error: unknown): void;
193
+ }
194
+ /**
195
+ * Follow a client's diagnostics with a supervised subscriber or a `SupervisedRelay`: want its `diag.events` and
196
+ * `diag.stats`, and `diag.cmcd` when `onCmcd` is given, drop events already delivered (a replay repeats them), and skip
197
+ * objects that do not parse. Returns the function that unwants them.
198
+ *
199
+ * ```ts
200
+ * const unfollow = followDiagnostics(subscriber, { namespace: root, generations: true }, {
201
+ * onEvents: (events) => events.forEach((event) => log(event)),
202
+ * onStats: (stats) => store(stats),
203
+ * });
204
+ * ```
205
+ */
206
+ export declare function followDiagnostics(subscriber: Pick<SupervisedSubscriber, 'want' | 'unwant'>, options: FollowDiagnosticsOptions, handlers: FollowDiagnosticsHandlers): () => void;
207
+ /** What {@link watchAudioInput} reads: `@caprid/moq-media`'s `AudioPlayerInput` qualifies. */
208
+ export interface WatchedAudioInput {
209
+ /** The input's cumulative counters; the four below are the ones episodes are measured with. */
210
+ readonly stats: {
211
+ /** Silence played in place of frames that never came, in microseconds. */
212
+ readonly concealedUs: number;
213
+ /** Audio synthesized in place of frames that never came, in microseconds. */
214
+ readonly synthesizedUs: number;
215
+ /** Times the buffer ran dry while playing. */
216
+ readonly underruns: number;
217
+ /** Frames dropped on arrival. */
218
+ readonly late: number;
219
+ };
220
+ }
221
+ /**
222
+ * Watch an audio player input for diagnostics, under a scope such as `diagnostics.scope('p2/audio')`: an `audio`
223
+ * section with its stats, and an event for each episode of filled audio (concealed or synthesized instead of received),
224
+ * once the input has played received audio again for 300 ms: `audio-dropout` for 250 ms or more, `audio-conceal` for
225
+ * 60 ms or more. Returns the function that stops watching.
226
+ *
227
+ * ```ts
228
+ * const input = player.addInput({ clock, decoderConfig });
229
+ * const unwatch = watchAudioInput(diagnostics.scope(`${participant}/audio`), input);
230
+ * ```
231
+ */
232
+ export declare function watchAudioInput(diagnostics: Diagnostics, input: WatchedAudioInput): () => void;
233
+ /**
234
+ * Watch the page a client runs in, for diagnostics: a background tab slows its timers and can look like network trouble,
235
+ * and a page that is frozen or put in the back/forward cache looks like a client that left. Records a `page` event on
236
+ * each change, with `what`: `visible` or `hidden` (visibility), `freeze` or `resume`, `pagehide` or `pageshow` (with
237
+ * `persisted`, whether the page goes into or comes from the back/forward cache), `online` or `offline`, and
238
+ * `connection` (`effectiveType`, `rttMs`, `downlinkMbps`) when `navigator.connection` changes, where the browser has it.
239
+ * Adds a `page` section: `visibility`, cumulative `hiddenMs`, `freezes`, `online`, and the connection's fields.
240
+ * Browser only: where there is no `document` it records nothing. Returns the function that stops watching.
241
+ *
242
+ * ```ts
243
+ * const unwatch = watchPage(diagnostics);
244
+ * ```
245
+ */
246
+ export declare function watchPage(diagnostics: Diagnostics): () => void;
247
+ /** Internal: a Default Publisher Priority option, an integer from 0 to 255, or the default when absent. */
248
+ export declare function diagnosticsPriority(value: unknown, fallback: number, name: string): number;
249
+ //# sourceMappingURL=client-diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-diagnostics.d.ts","sourceRoot":"","sources":["../src/client-diagn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