@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.
- package/README.md +54 -53
- package/dist/client-diagnostics.d.ts +235 -0
- package/dist/client-diagnostics.d.ts.map +1 -0
- package/dist/client-diagnostics.js +582 -0
- package/dist/client-diagnostics.js.map +1 -0
- package/dist/connect-session.d.ts +43 -3
- package/dist/connect-session.d.ts.map +1 -1
- package/dist/connect-session.js +46 -3
- package/dist/connect-session.js.map +1 -1
- package/dist/connect.d.ts +1 -1
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js.map +1 -1
- package/dist/diagnostics-report.d.ts +106 -0
- package/dist/diagnostics-report.d.ts.map +1 -0
- package/dist/diagnostics-report.js +450 -0
- package/dist/diagnostics-report.js.map +1 -0
- package/dist/diagnostics.d.ts +20 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +20 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/frame-reader.d.ts +12 -0
- package/dist/frame-reader.d.ts.map +1 -1
- package/dist/frame-reader.js +65 -0
- package/dist/frame-reader.js.map +1 -1
- package/dist/frame-writer.d.ts +15 -0
- package/dist/frame-writer.d.ts.map +1 -1
- package/dist/frame-writer.js +73 -1
- package/dist/frame-writer.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/supervised-publisher.d.ts +7 -0
- package/dist/supervised-publisher.d.ts.map +1 -1
- package/dist/supervised-publisher.js +4 -1
- package/dist/supervised-publisher.js.map +1 -1
- package/dist/supervised-relay.d.ts +8 -0
- package/dist/supervised-relay.d.ts.map +1 -1
- package/dist/supervised-relay.js +5 -2
- package/dist/supervised-relay.js.map +1 -1
- package/dist/supervised-subscriber.d.ts +10 -2
- package/dist/supervised-subscriber.d.ts.map +1 -1
- package/dist/supervised-subscriber.js +20 -9
- package/dist/supervised-subscriber.js.map +1 -1
- package/dist/supervisor.d.ts +9 -0
- package/dist/supervisor.d.ts.map +1 -1
- package/dist/supervisor.js +26 -2
- package/dist/supervisor.js.map +1 -1
- package/dist/version.d.ts +6 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +13 -9
package/README.md
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
# @caprid/relay
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
`@caprid/relay-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
`
|
|
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,49 +29,47 @@ 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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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 {
|
|
44
|
+
import { connectSupervisedPublisher, connectSupervisedSubscriber, readText } from '@caprid/relay';
|
|
38
45
|
|
|
39
|
-
const getToken = () => token; //
|
|
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
|
|
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
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
|
|
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');
|
|
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
|
|
62
|
-
token's root
|
|
63
|
-
region or room
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
|
@@ -168,12 +169,12 @@ install matching versions. A release supports:
|
|
|
168
169
|
|
|
169
170
|
## Documentation
|
|
170
171
|
|
|
171
|
-
- [
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
- API reference:
|
|
175
|
-
|
|
176
|
-
- [
|
|
177
|
-
|
|
178
|
-
- [
|
|
179
|
-
|
|
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,235 @@
|
|
|
1
|
+
import type { MessageParameters } from '@caprid/moq-core';
|
|
2
|
+
import type { RegisterTrackOptions, RelayTrackWriter } from './publish.js';
|
|
3
|
+
import type { SupervisedSubscriber } from './supervised-subscriber.js';
|
|
4
|
+
/**
|
|
5
|
+
* Client diagnostics (spec/behavior.md, "Client diagnostics"; TypeScript only): a recorder that holds what a client
|
|
6
|
+
* saw, published on two tracks of a publication of the client's own (by convention `<account>/diag/<app>/<group>/<client>`)
|
|
7
|
+
* while something subscribes, and followed from elsewhere. Every client can report, whether it publishes media or not.
|
|
8
|
+
* `diag.events` carries events, each with a sequence number; `diag.stats` carries a snapshot of every stats section
|
|
9
|
+
* once a second.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DIAGNOSTICS_TRACKS: {
|
|
12
|
+
/** Events, as {@link DiagnosticsEventsObject}s. */
|
|
13
|
+
readonly events: "diag.events";
|
|
14
|
+
/** Stats snapshots, as {@link DiagnosticsStatsObject}s. */
|
|
15
|
+
readonly stats: "diag.stats";
|
|
16
|
+
};
|
|
17
|
+
/** One thing a client saw. SDK kinds are plain words (`link`, `want`); an application's start with `app.`. */
|
|
18
|
+
export interface DiagnosticEvent {
|
|
19
|
+
/** Wall-clock time, in milliseconds since the epoch. */
|
|
20
|
+
readonly t: number;
|
|
21
|
+
/** The recorder's sequence number, from 0, one per event. */
|
|
22
|
+
readonly seq: number;
|
|
23
|
+
/** What happened. */
|
|
24
|
+
readonly kind: string;
|
|
25
|
+
/** The scope that recorded it, as {@link Diagnostics.scope} named it; absent for the recorder itself. */
|
|
26
|
+
readonly source?: string;
|
|
27
|
+
/** The event's own fields: ids and counters, never names or media. */
|
|
28
|
+
readonly [field: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
/** Options for {@link createDiagnostics}. */
|
|
31
|
+
export interface DiagnosticsOptions {
|
|
32
|
+
/** How long an event is held for a subscriber that arrives later, in milliseconds. Default 10 minutes. */
|
|
33
|
+
keepMs?: number;
|
|
34
|
+
/** The most events held, oldest dropped first. A positive integer; default 5000. */
|
|
35
|
+
keepEvents?: number;
|
|
36
|
+
/**
|
|
37
|
+
* The application and its build, for the `start` event: a follower then knows which bundle a client ran without
|
|
38
|
+
* asking. `name` is a non-empty string; `build` any string the app keeps, such as a commit or a release.
|
|
39
|
+
*/
|
|
40
|
+
app?: DiagnosticsApp;
|
|
41
|
+
}
|
|
42
|
+
/** The application a recorder runs in, for its `start` event. */
|
|
43
|
+
export interface DiagnosticsApp {
|
|
44
|
+
/** The application's name, such as `huddle`. Non-empty. */
|
|
45
|
+
name: string;
|
|
46
|
+
/** Its build: a commit, a release, whatever the application keeps. */
|
|
47
|
+
build?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A recorder of events and stats sections, or a scope of one. Create one with {@link createDiagnostics}; the SDK
|
|
51
|
+
* pieces that take a `diagnostics` option report into whichever they are given.
|
|
52
|
+
*/
|
|
53
|
+
export interface Diagnostics {
|
|
54
|
+
/** A random id for this recorder. A follower tells two recorders, or a restarted client, apart by it. */
|
|
55
|
+
readonly instance: string;
|
|
56
|
+
/**
|
|
57
|
+
* Record an event and tell the listeners. `kind` is a non-empty string; `fields` are copied, except `t`, `seq` and
|
|
58
|
+
* `kind`, which the recorder sets, and in a scope `source`. Keep them to ids and counters: they leave the client.
|
|
59
|
+
*/
|
|
60
|
+
event(kind: string, fields?: Readonly<Record<string, unknown>>): DiagnosticEvent;
|
|
61
|
+
/**
|
|
62
|
+
* The events still held whose sequence number is at least `seq`, oldest first: the `start` event, which is held for
|
|
63
|
+
* the recorder's life, then the rest. Also what an app can send its own server when the client never connects.
|
|
64
|
+
*/
|
|
65
|
+
events(seq?: number): DiagnosticEvent[];
|
|
66
|
+
/** Call `listener` with each event as it is recorded. Returns the function that stops it. */
|
|
67
|
+
listen(listener: (event: DiagnosticEvent) => void): () => void;
|
|
68
|
+
/**
|
|
69
|
+
* Add a stats section: `read` is called for every snapshot and returns something JSON can encode, usually counters.
|
|
70
|
+
* In a scope the name is prefixed with the scope's and a dot. A section of the same name is replaced. Returns the
|
|
71
|
+
* function that removes this one.
|
|
72
|
+
*/
|
|
73
|
+
section(name: string, read: () => unknown): () => void;
|
|
74
|
+
/** Every section's value now, by name, the whole recorder's from any scope. A section whose `read` throws reads `{ error }`. */
|
|
75
|
+
snapshot(): Record<string, unknown>;
|
|
76
|
+
/**
|
|
77
|
+
* The same recorder under a name: its events carry `source` (a scope of a scope joins the names with `/`) and its
|
|
78
|
+
* section names start with it. Give each link, reader or writer its own, such as `scope('roster')` or
|
|
79
|
+
* `scope('p2/audio')`.
|
|
80
|
+
*/
|
|
81
|
+
scope(name: string): Diagnostics;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Record what a client sees, for {@link publishDiagnostics}. Pass it to the SDK pieces that report into it, and add
|
|
85
|
+
* your own events and sections.
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* const diagnostics = createDiagnostics();
|
|
89
|
+
* diagnostics.event('app.joined', { participant: id });
|
|
90
|
+
* diagnostics.section('app.video', () => ({ layer, freezes }));
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function createDiagnostics(options?: DiagnosticsOptions): Diagnostics;
|
|
94
|
+
/**
|
|
95
|
+
* What {@link publishDiagnostics} registers its tracks on: a `RelayPublisher`, a `SupervisedPublisher`, or a root
|
|
96
|
+
* published on a `SupervisedRelay` (the `SupervisedPublication` that `relay.publish(root)` returns).
|
|
97
|
+
*/
|
|
98
|
+
export interface DiagnosticsPublisher {
|
|
99
|
+
/** Register a track on the publisher's broadcast, as `RelayPublisher.registerTrack` does. */
|
|
100
|
+
registerTrack(options: RegisterTrackOptions): RelayTrackWriter;
|
|
101
|
+
}
|
|
102
|
+
/** Options for {@link publishDiagnostics}. */
|
|
103
|
+
export interface PublishDiagnosticsOptions {
|
|
104
|
+
/**
|
|
105
|
+
* How often a stats snapshot is sent while `diag.stats` has demand, in milliseconds. Default 1000. A snapshot the
|
|
106
|
+
* transport has not taken within two intervals is dropped: the next one supersedes it.
|
|
107
|
+
*/
|
|
108
|
+
statsIntervalMs?: number;
|
|
109
|
+
/**
|
|
110
|
+
* The Default Publisher Priority (0x0E) of `diag.events`, an integer from 0 to 255, lower being more urgent.
|
|
111
|
+
* Default 224: behind every media track (audio 16, video 96), so diagnostics never hold media up on a congested
|
|
112
|
+
* uplink.
|
|
113
|
+
*/
|
|
114
|
+
eventsPriority?: number;
|
|
115
|
+
/** The Default Publisher Priority (0x0E) of `diag.stats`, as `eventsPriority`. Default 240, behind events. */
|
|
116
|
+
statsPriority?: number;
|
|
117
|
+
}
|
|
118
|
+
/** The two diagnostics tracks being published. */
|
|
119
|
+
export interface DiagnosticsPublication {
|
|
120
|
+
/** Stop publishing and close both tracks. Idempotent. */
|
|
121
|
+
close(): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
/** One `diag.events` object: events of one recorder, live or (`backlog`) replayed from what it held. */
|
|
124
|
+
export interface DiagnosticsEventsObject {
|
|
125
|
+
/** The recorder's {@link Diagnostics.instance}. */
|
|
126
|
+
instance: string;
|
|
127
|
+
/** Present when the events are a replay of what the recorder held, not live. */
|
|
128
|
+
backlog?: true;
|
|
129
|
+
/** The events, oldest first. */
|
|
130
|
+
events: DiagnosticEvent[];
|
|
131
|
+
}
|
|
132
|
+
/** One `diag.stats` object: one recorder's sections at one moment. */
|
|
133
|
+
export interface DiagnosticsStatsObject {
|
|
134
|
+
/** The recorder's {@link Diagnostics.instance}. */
|
|
135
|
+
instance: string;
|
|
136
|
+
/** When the snapshot was taken: wall clock, milliseconds since the epoch. */
|
|
137
|
+
t: number;
|
|
138
|
+
/** Every section's value, by name, as {@link Diagnostics.snapshot} returns it. */
|
|
139
|
+
stats: Record<string, unknown>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Publish a recorder on `diag.events` and `diag.stats` of the publisher's broadcast. Nothing is sent while the relay
|
|
143
|
+
* has no subscription to a track. Each time the relay subscribes to `diag.events`, everything the recorder holds goes
|
|
144
|
+
* first, marked `backlog`, then each event as it is recorded; a follower drops sequence numbers it has seen. Right
|
|
145
|
+
* after the relay replaces its subscription a few live events can still arrive ahead of the replay, so a follower
|
|
146
|
+
* that needs them in order sorts by `seq`. A
|
|
147
|
+
* snapshot goes on `diag.stats` once a second while it has demand. Track names are unique per publisher connection,
|
|
148
|
+
* so publish one recorder per publisher (on a `SupervisedRelay`, per published root).
|
|
149
|
+
*
|
|
150
|
+
* ```ts
|
|
151
|
+
* const publication = publishDiagnostics(diagnostics, publisher);
|
|
152
|
+
* // ...
|
|
153
|
+
* await publication.close();
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export declare function publishDiagnostics(diagnostics: Diagnostics, publisher: DiagnosticsPublisher, options?: PublishDiagnosticsOptions): DiagnosticsPublication;
|
|
157
|
+
/** Where {@link followDiagnostics} reads: a client's broadcast, or a supervised publisher's root. */
|
|
158
|
+
export interface FollowDiagnosticsOptions {
|
|
159
|
+
/** The client's namespace, or with `generations` a supervised publisher's root. */
|
|
160
|
+
namespace: readonly string[];
|
|
161
|
+
/** Follow the newest generation under `namespace`, as a want does. */
|
|
162
|
+
generations?: boolean;
|
|
163
|
+
/** The prefix of the two want keys, `<key>/diag.events` and `<key>/diag.stats`. Default the namespace joined by `/`. */
|
|
164
|
+
key?: string;
|
|
165
|
+
/**
|
|
166
|
+
* Parameters for the `diag.events` subscription, such as a location filter that asks the relay for the groups it
|
|
167
|
+
* still holds: a follower that subscribes while another already does gets no replay from the client.
|
|
168
|
+
*/
|
|
169
|
+
eventsParameters?: MessageParameters;
|
|
170
|
+
}
|
|
171
|
+
/** What {@link followDiagnostics} delivers. Like a want's handlers, they must be synchronous. */
|
|
172
|
+
export interface FollowDiagnosticsHandlers {
|
|
173
|
+
/** Events not delivered before, in the order they arrived; `backlog` when they came from a replay. */
|
|
174
|
+
onEvents?(events: DiagnosticEvent[], info: {
|
|
175
|
+
instance: string;
|
|
176
|
+
backlog: boolean;
|
|
177
|
+
}): void;
|
|
178
|
+
/** One stats snapshot. */
|
|
179
|
+
onStats?(stats: DiagnosticsStatsObject): void;
|
|
180
|
+
/** A want's failure that it does not retry, as `WantHandlers.onError`. Objects that do not parse are skipped. */
|
|
181
|
+
onError?(error: unknown): void;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Follow a client's diagnostics with a supervised subscriber or a `SupervisedRelay`: want its `diag.events` and `diag.stats`, drop events
|
|
185
|
+
* already delivered (a replay repeats them), and skip objects that do not parse. Returns the function that unwants both.
|
|
186
|
+
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* const unfollow = followDiagnostics(subscriber, { namespace: root, generations: true }, {
|
|
189
|
+
* onEvents: (events) => events.forEach((event) => log(event)),
|
|
190
|
+
* onStats: (stats) => store(stats),
|
|
191
|
+
* });
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare function followDiagnostics(subscriber: Pick<SupervisedSubscriber, 'want' | 'unwant'>, options: FollowDiagnosticsOptions, handlers: FollowDiagnosticsHandlers): () => void;
|
|
195
|
+
/** What {@link watchAudioInput} reads: `@caprid/moq-media`'s `AudioPlayerInput` qualifies. */
|
|
196
|
+
export interface WatchedAudioInput {
|
|
197
|
+
/** The input's cumulative counters; the four below are the ones episodes are measured with. */
|
|
198
|
+
readonly stats: {
|
|
199
|
+
/** Silence played in place of frames that never came, in microseconds. */
|
|
200
|
+
readonly concealedUs: number;
|
|
201
|
+
/** Audio synthesized in place of frames that never came, in microseconds. */
|
|
202
|
+
readonly synthesizedUs: number;
|
|
203
|
+
/** Times the buffer ran dry while playing. */
|
|
204
|
+
readonly underruns: number;
|
|
205
|
+
/** Frames dropped on arrival. */
|
|
206
|
+
readonly late: number;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Watch an audio player input for diagnostics, under a scope such as `diagnostics.scope('p2/audio')`: an `audio`
|
|
211
|
+
* section with its stats, and an event for each episode of filled audio (concealed or synthesized instead of received),
|
|
212
|
+
* once the input has played received audio again for 300 ms: `audio-dropout` for 250 ms or more, `audio-conceal` for
|
|
213
|
+
* 60 ms or more. Returns the function that stops watching.
|
|
214
|
+
*
|
|
215
|
+
* ```ts
|
|
216
|
+
* const input = player.addInput({ clock, decoderConfig });
|
|
217
|
+
* const unwatch = watchAudioInput(diagnostics.scope(`${participant}/audio`), input);
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare function watchAudioInput(diagnostics: Diagnostics, input: WatchedAudioInput): () => void;
|
|
221
|
+
/**
|
|
222
|
+
* Watch the page a client runs in, for diagnostics: a background tab slows its timers and can look like network trouble,
|
|
223
|
+
* and a page that is frozen or put in the back/forward cache looks like a client that left. Records a `page` event on
|
|
224
|
+
* each change, with `what`: `visible` or `hidden` (visibility), `freeze` or `resume`, `pagehide` or `pageshow` (with
|
|
225
|
+
* `persisted`, whether the page goes into or comes from the back/forward cache), `online` or `offline`, and
|
|
226
|
+
* `connection` (`effectiveType`, `rttMs`, `downlinkMbps`) when `navigator.connection` changes, where the browser has it.
|
|
227
|
+
* Adds a `page` section: `visibility`, cumulative `hiddenMs`, `freezes`, `online`, and the connection's fields.
|
|
228
|
+
* Browser only: where there is no `document` it records nothing. Returns the function that stops watching.
|
|
229
|
+
*
|
|
230
|
+
* ```ts
|
|
231
|
+
* const unwatch = watchPage(diagnostics);
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export declare function watchPage(diagnostics: Diagnostics): () => void;
|
|
235
|
+
//# sourceMappingURL=client-diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-diagnostics.d.ts","sourceRoot":"","sources":["../src/client-diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAc,MAAM,kBAAkB,CAAC;AAKtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAIvE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;IAC7B,mDAAmD;;IAEnD,2DAA2D;;CAEnD,CAAC;AAEX,8GAA8G;AAC9G,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yGAAyG;IACzG,QAAQ,CAAC,M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