@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,214 @@
1
+ /**
2
+ * Keeping the connection alive between drops (docs/implementation-progress/RTC_PERF_PROGRESS.md G1, G2).
3
+ *
4
+ * Two failures the socket's own close never reports:
5
+ *
6
+ * - **The media path dies while the socket lives** (Wi-Fi to mobile data, a NAT rebinding, UDP blocked mid-call).
7
+ * The video freezes for good. Twilio and LiveKit restart ICE on the same transports first -- new ICE credentials
8
+ * from the server, the same producers and consumers -- and rejoin only when that does not bring the path back.
9
+ * {@link MediaPathWatch} does the same: a transport `disconnected` for {@link DISCONNECTED_GRACE_MS} or `failed`
10
+ * restarts ICE; not `connected` within {@link RESTART_TIMEOUT_MS} of starting recovery (including the request), or a server without `restartIce`, is a
11
+ * full reconnect.
12
+ * - **The socket dies silently**: the network went away and TCP has not noticed yet, which can take minutes. The
13
+ * server pings, but a browser cannot see those. LiveKit pings from the client and reconnects when no pong comes.
14
+ * {@link SocketLiveness} sends `ping` after {@link IDLE_MS} with nothing received, and calls the socket dead when
15
+ * nothing at all arrives within {@link PING_TIMEOUT_MS} of it. Any frame counts, so an older server's
16
+ * `unknown-method` reply proves the socket as well as a pong.
17
+ *
18
+ * Pure: timers and the clock are injectable, so the decisions are unit-tested on their own.
19
+ */
20
+ /** A transport `disconnected` this long is restarted (it often recovers by itself within a second or two). */
21
+ export const DISCONNECTED_GRACE_MS = 3000;
22
+ /** The whole ICE recovery, including the request, has this long before the session rejoins. */
23
+ export const RESTART_TIMEOUT_MS = 10_000;
24
+ /** With nothing received for this long, the client pings. */
25
+ export const IDLE_MS = 15_000;
26
+ /** A ping with nothing at all received for this long after it: the socket is dead. */
27
+ export const PING_TIMEOUT_MS = 8000;
28
+ /** How often liveness is checked. Background tabs may run it less often; the decisions use the clock, not counts. */
29
+ export const LIVENESS_TICK_MS = 5000;
30
+ /** Watches each media transport's connection state and recovers a dead path. */
31
+ export class MediaPathWatch {
32
+ host;
33
+ entries = new Map();
34
+ setTimer;
35
+ clearTimer;
36
+ constructor(host) {
37
+ this.host = host;
38
+ this.setTimer = host.setTimer ?? ((fn, ms) => setTimeout(fn, ms));
39
+ this.clearTimer = host.clearTimer ?? ((h) => clearTimeout(h));
40
+ }
41
+ /** A transport's connection state changed (mediasoup-client `connectionstatechange`). */
42
+ update(transportId, state) {
43
+ let entry = this.entries.get(transportId);
44
+ if (!entry) {
45
+ entry = { state, timer: null, restarting: false, lost: false, revision: 0 };
46
+ this.entries.set(transportId, entry);
47
+ }
48
+ entry.state = state;
49
+ switch (state) {
50
+ case 'connected':
51
+ entry.revision++;
52
+ this.cancel(entry);
53
+ entry.restarting = false;
54
+ this.setLost(transportId, entry, false);
55
+ return;
56
+ case 'closed':
57
+ this.forget(transportId);
58
+ return;
59
+ case 'disconnected':
60
+ // A restart is already waiting for `connected`; its own deadline decides.
61
+ if (entry.restarting || entry.timer !== null)
62
+ return;
63
+ entry.timer = this.setTimer(() => {
64
+ entry.timer = null;
65
+ if (entry.state === 'disconnected' || entry.state === 'failed')
66
+ void this.restart(transportId, entry);
67
+ }, DISCONNECTED_GRACE_MS);
68
+ return;
69
+ case 'failed':
70
+ if (entry.restarting)
71
+ return; // duplicate notification; the deadline decides
72
+ this.cancel(entry);
73
+ void this.restart(transportId, entry);
74
+ return;
75
+ default:
76
+ // new / connecting: a fresh transport, or one mid-restart.
77
+ return;
78
+ }
79
+ }
80
+ /** The transport went away with its session (teardown): no more decisions for it. */
81
+ forget(transportId) {
82
+ const entry = this.entries.get(transportId);
83
+ if (!entry)
84
+ return;
85
+ this.cancel(entry);
86
+ this.entries.delete(transportId);
87
+ if (entry.lost)
88
+ this.host.onPathChange?.(transportId, false);
89
+ }
90
+ /** Every transport went away (teardown, close). */
91
+ reset() {
92
+ for (const id of [...this.entries.keys()])
93
+ this.forget(id);
94
+ }
95
+ /** For tests and the network-change nudge: is this transport being recovered now? */
96
+ restartingNow(transportId) {
97
+ return this.entries.get(transportId)?.restarting === true;
98
+ }
99
+ async restart(transportId, entry) {
100
+ if (!this.host.active() || this.entries.get(transportId) !== entry)
101
+ return;
102
+ entry.restarting = true;
103
+ const revision = ++entry.revision;
104
+ // Include both the RPC and the platform call in the deadline: neither is
105
+ // guaranteed to settle when a network/interface disappears.
106
+ this.cancel(entry);
107
+ entry.timer = this.setTimer(() => {
108
+ entry.timer = null;
109
+ if (!entry.restarting || this.entries.get(transportId) !== entry)
110
+ return;
111
+ entry.revision++;
112
+ entry.restarting = false;
113
+ if (this.host.active())
114
+ this.host.reconnect('media-timeout');
115
+ }, RESTART_TIMEOUT_MS);
116
+ this.setLost(transportId, entry, true);
117
+ let outcome;
118
+ try {
119
+ outcome = await this.host.restartIce(transportId);
120
+ }
121
+ catch {
122
+ outcome = 'unsupported';
123
+ }
124
+ if (this.entries.get(transportId) !== entry || entry.revision !== revision)
125
+ return;
126
+ if (outcome === 'skipped') {
127
+ this.cancel(entry);
128
+ entry.restarting = false;
129
+ return;
130
+ }
131
+ if (outcome === 'unsupported') {
132
+ this.cancel(entry);
133
+ entry.restarting = false;
134
+ if (this.host.active())
135
+ this.host.reconnect('media-failed');
136
+ return;
137
+ }
138
+ // `connected` clears the deadline, including when it arrives during the await.
139
+ }
140
+ setLost(transportId, entry, lost) {
141
+ if (entry.lost === lost)
142
+ return;
143
+ entry.lost = lost;
144
+ this.host.onPathChange?.(transportId, lost);
145
+ }
146
+ cancel(entry) {
147
+ if (entry.timer !== null)
148
+ this.clearTimer(entry.timer);
149
+ entry.timer = null;
150
+ }
151
+ }
152
+ /** Notices a socket that died without closing. */
153
+ export class SocketLiveness {
154
+ host;
155
+ lastReceived = 0;
156
+ pingSentAt = null;
157
+ timer = null;
158
+ now;
159
+ constructor(host) {
160
+ this.host = host;
161
+ this.now = host.now ?? Date.now;
162
+ }
163
+ /** Start watching a newly opened socket. */
164
+ start() {
165
+ this.stop();
166
+ this.lastReceived = this.now();
167
+ this.pingSentAt = null;
168
+ const every = this.host.setInterval ?? ((fn, ms) => setInterval(fn, ms));
169
+ this.timer = every(() => this.check(), LIVENESS_TICK_MS);
170
+ // A Node/SSR process with no other work need not stay alive for a browser
171
+ // connection watch. Browser timers are numbers and have no unref.
172
+ this.timer?.unref?.();
173
+ }
174
+ stop() {
175
+ if (this.timer !== null)
176
+ (this.host.clearInterval ?? ((h) => clearInterval(h)))(this.timer);
177
+ this.timer = null;
178
+ this.pingSentAt = null;
179
+ }
180
+ get running() {
181
+ return this.timer !== null;
182
+ }
183
+ /** Any frame arrived on the socket. */
184
+ received() {
185
+ this.lastReceived = this.now();
186
+ this.pingSentAt = null;
187
+ }
188
+ /** Check now instead of at the next tick (the browser said the network changed). */
189
+ checkNow() {
190
+ if (this.timer === null || !this.host.active())
191
+ return;
192
+ if (this.pingSentAt === null) {
193
+ this.pingSentAt = this.now();
194
+ this.host.ping();
195
+ }
196
+ }
197
+ check() {
198
+ if (this.timer === null || !this.host.active())
199
+ return;
200
+ const now = this.now();
201
+ if (this.pingSentAt !== null) {
202
+ if (now - this.pingSentAt >= PING_TIMEOUT_MS) {
203
+ this.stop();
204
+ this.host.dead();
205
+ }
206
+ return;
207
+ }
208
+ if (now - this.lastReceived >= IDLE_MS) {
209
+ this.pingSentAt = now;
210
+ this.host.ping();
211
+ }
212
+ }
213
+ }
214
+ //# sourceMappingURL=link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link.js","sourceRoot":"","sources":["../../src/link.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,8GAA8G;AAC9G,MAAM,CAAC,MAAM,qBAAqB,GAAG,IA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AAC,KAAK,KAAK,IAAI,CAAC;IAC7B,CAAC;IAED,uCAAuC;IACvC,QAAQ;QACN,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,oFAAoF;IACpF,QAAQ;QACN,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAAE,OAAO;QACvD,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC7B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAAE,OAAO;QACvD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,IAAI,GAAG,GAAG,IAAI,CAAC,UAAU,IAAI,eAAe,EAAE,CAAC;gBAC7C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACZ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACnB,CAAC;YACD,OAAO;QACT,CAAC;QACD,IAAI,GAAG,GAAG,IAAI,CAAC,YAAY,IAAI,OAAO,EAAE,CAAC;YACvC,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;YACtB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Pre-call check (docs/implementation-progress/RTC_PERF_PROGRESS.md L1).
3
+ *
4
+ * - Twilio's `runPreflight` (read from its code) joins a test room, publishes synthetic audio and video and reports
5
+ * timings, the connection path, round trip, jitter and loss.
6
+ * - LiveKit's `ConnectionCheck` runs separate checks -- WebSocket, WebRTC, TURN, publishing audio and video, UDP
7
+ * against TCP -- each with messages and warnings.
8
+ * - Agora's `startLastmileProbeTest` measures the last mile before a call.
9
+ *
10
+ * This joins the room the token names (mint one for a test room nobody else is in: the session is real, and billed
11
+ * like any other for its few seconds), publishes what it is given -- or a tone and a picture it makes -- and reports
12
+ * what it saw. The orchestration takes a small target interface, so it is tested without a browser.
13
+ */
14
+ import { type NetworkQualityLevel } from './network.js';
15
+ import type { StatsEntry } from './stats.js';
16
+ import type { MediaWarningCode } from './health.js';
17
+ export interface PreflightOptions {
18
+ /** What to publish (cloned; your tracks are left running). Without it, a tone and a moving picture are made. */
19
+ media?: MediaStream;
20
+ /** How long media is measured once it flows. Default 5 s. */
21
+ durationMs?: number;
22
+ }
23
+ export type PreflightStepName = 'join' | 'media';
24
+ export interface PreflightStep {
25
+ name: PreflightStepName;
26
+ ok: boolean;
27
+ /** How long it took, in ms. */
28
+ ms: number | null;
29
+ error?: string;
30
+ }
31
+ export interface PreflightReport {
32
+ /** Joined, and media reached the server. */
33
+ ok: boolean;
34
+ steps: PreflightStep[];
35
+ /** How media travelled: UDP is best; TCP or a relay means a firewall in the way (it works, with more delay). */
36
+ path: {
37
+ protocol: 'udp' | 'tcp' | null;
38
+ relayed: boolean;
39
+ } | null;
40
+ rttMs: number | null;
41
+ lossPct: number | null;
42
+ /** The upload the browser estimated it could use, in kbps. */
43
+ uploadKbps: number | null;
44
+ level: NetworkQualityLevel | null;
45
+ /** Camera and microphone problems seen during the test (see the mediaWarning event). */
46
+ warnings: MediaWarningCode[];
47
+ }
48
+ /** What a pre-call check needs from a client. */
49
+ export interface PreflightTarget {
50
+ connect(): Promise<unknown>;
51
+ publish(stream: MediaStream): Promise<void>;
52
+ /** The send transport's connection state, or null before there is one. */
53
+ sendState(): string | null;
54
+ /** The send transport's statistics, or null without one. */
55
+ sendStats(): Promise<Iterable<StatsEntry> | null>;
56
+ onWarning(listener: (code: MediaWarningCode, active: boolean) => void): () => void;
57
+ close(): void;
58
+ }
59
+ export interface PreflightEnv {
60
+ now(): number;
61
+ sleep(ms: number): Promise<void>;
62
+ }
63
+ /** Media has this long to connect once published. */
64
+ export declare const MEDIA_CONNECT_TIMEOUT_MS = 10000;
65
+ /** Statistics are read this often while measuring. */
66
+ export declare const PREFLIGHT_SAMPLE_MS = 1000;
67
+ /** The selected candidate pair's protocol, and whether either end is a relay. */
68
+ export declare function connectionPath(report: Iterable<StatsEntry>): PreflightReport['path'];
69
+ /** Run the check on `target`, closing it at the end whatever happens. */
70
+ export declare function runPreflight(target: PreflightTarget, stream: MediaStream, options?: PreflightOptions, env?: PreflightEnv): Promise<PreflightReport>;
71
+ /**
72
+ * A tone and a moving picture to publish when the app gives none (Twilio's preflight makes synthetic media too).
73
+ * Returns the stream and a function that stops everything it made. Browser only.
74
+ */
75
+ export declare function syntheticMedia(): {
76
+ stream: MediaStream;
77
+ stop: () => void;
78
+ };
79
+ //# sourceMappingURL=preflight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preflight.d.ts","sourceRoot":"","sources":["../../src/preflight.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAwC,KAAK,mBAAmB,EAAwB,MAAM,cAAc,CAAC;AACpH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,WAAW,gBAAgB;IAC/B,gHAAgH;IAChH,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,CAAC;AAEjD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,iBAAiB,CAAC;IACxB,EAAE,EAAE,OAAO,CAAC;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wB,QAAS,CAAC;AAC/C,sDAAsD;AACtD,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,CAgBpF;AAED,yEAAyE;AACzE,wBAAsB,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE,gBAAqB,EAAE,GAAG,GAAE,YAAsB,GAAG,OAAO,CAAC,eAAe,CAAC,CAsDtK;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CAqC1E"}
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Pre-call check (docs/implementation-progress/RTC_PERF_PROGRESS.md L1).
3
+ *
4
+ * - Twilio's `runPreflight` (read from its code) joins a test room, publishes synthetic audio and video and reports
5
+ * timings, the connection path, round trip, jitter and loss.
6
+ * - LiveKit's `ConnectionCheck` runs separate checks -- WebSocket, WebRTC, TURN, publishing audio and video, UDP
7
+ * against TCP -- each with messages and warnings.
8
+ * - Agora's `startLastmileProbeTest` measures the last mile before a call.
9
+ *
10
+ * This joins the room the token names (mint one for a test room nobody else is in: the session is real, and billed
11
+ * like any other for its few seconds), publishes what it is given -- or a tone and a picture it makes -- and reports
12
+ * what it saw. The orchestration takes a small target interface, so it is tested without a browser.
13
+ */
14
+ import { networkQualityOf, readTransportStats } from './network.js';
15
+ const realEnv = { now: () => Date.now(), sleep: (ms) => new Promise((r) => setTimeout(r, ms)) };
16
+ /** Media has this long to connect once published. */
17
+ export const MEDIA_CONNECT_TIMEOUT_MS = 10_000;
18
+ /** Statistics are read this often while measuring. */
19
+ export const PREFLIGHT_SAMPLE_MS = 1000;
20
+ /** The selected candidate pair's protocol, and whether either end is a relay. */
21
+ export function connectionPath(report) {
22
+ const entries = [...report];
23
+ const byId = new Map();
24
+ for (const e of entries)
25
+ if (typeof e.id === 'string')
26
+ byId.set(e.id, e);
27
+ let pair;
28
+ for (const t of entries.filter((e) => e.type === 'transport')) {
29
+ if (typeof t.selectedCandidatePairId === 'string')
30
+ pair = byId.get(t.selectedCandidatePairId);
31
+ if (pair)
32
+ break;
33
+ }
34
+ pair ??= entries.find((e) => e.type === 'candidate-pair' && e.nominated === true && e.state === 'succeeded');
35
+ if (!pair)
36
+ return null;
37
+ const local = typeof pair.localCandidateId === 'string' ? byId.get(pair.localCandidateId) : undefined;
38
+ const remote = typeof pair.remoteCandidateId === 'string' ? byId.get(pair.remoteCandidateId) : undefined;
39
+ const protocol = local?.protocol === 'udp' || local?.protocol === 'tcp' ? local.protocol : null;
40
+ const relayed = local?.candidateType === 'relay' || remote?.candidateType === 'relay';
41
+ return { protocol, relayed };
42
+ }
43
+ /** Run the check on `target`, closing it at the end whatever happens. */
44
+ export async function runPreflight(target, stream, options = {}, env = realEnv) {
45
+ const report = { ok: false, steps: [], path: null, rttMs: null, lossPct: null, uploadKbps: null, level: null, warnings: [] };
46
+ const seen = new Set();
47
+ const stopWarnings = target.onWarning((code, active) => { if (active)
48
+ seen.add(code); });
49
+ try {
50
+ let started = env.now();
51
+ try {
52
+ await target.connect();
53
+ report.steps.push({ name: 'join', ok: true, ms: env.now() - started });
54
+ }
55
+ catch (err) {
56
+ report.steps.push({ name: 'join', ok: false, ms: null, error: String(err?.message ?? err) });
57
+ return report;
58
+ }
59
+ started = env.now();
60
+ try {
61
+ await target.publish(stream);
62
+ while (target.sendState() !== 'connected') {
63
+ const state = target.sendState();
64
+ if (state === 'failed' || state === 'closed')
65
+ throw new Error(`media connection ${state}`);
66
+ if (env.now() - started > MEDIA_CONNECT_TIMEOUT_MS)
67
+ throw new Error('media did not connect in time (a firewall blocking UDP and TCP?)');
68
+ await env.sleep(100);
69
+ }
70
+ report.steps.push({ name: 'media', ok: true, ms: env.now() - started });
71
+ }
72
+ catch (err) {
73
+ report.steps.push({ name: 'media', ok: false, ms: null, error: String(err?.message ?? err) });
74
+ return report;
75
+ }
76
+ // Measure: the worst round trip and loss over the run, the last upload estimate.
77
+ const duration = options.durationMs ?? 5000;
78
+ let previous = new Map();
79
+ const until = env.now() + duration;
80
+ while (env.now() < until) {
81
+ await env.sleep(PREFLIGHT_SAMPLE_MS);
82
+ const stats = await target.sendStats().catch(() => null);
83
+ if (!stats)
84
+ continue;
85
+ const entries = [...stats];
86
+ report.path = connectionPath(entries) ?? report.path;
87
+ const now = new Map([['send', readTransportStats(entries)]]);
88
+ const q = networkQualityOf(now, previous, true);
89
+ previous = now;
90
+ if (q.rttMs !== null)
91
+ report.rttMs = Math.max(report.rttMs ?? 0, q.rttMs);
92
+ if (q.lossPct !== null)
93
+ report.lossPct = Math.max(report.lossPct ?? 0, q.lossPct);
94
+ if (q.availableKbps !== null)
95
+ report.uploadKbps = q.availableKbps;
96
+ report.level = q.level;
97
+ }
98
+ report.ok = true;
99
+ return report;
100
+ }
101
+ finally {
102
+ report.warnings = [...seen];
103
+ stopWarnings();
104
+ target.close();
105
+ }
106
+ }
107
+ /**
108
+ * A tone and a moving picture to publish when the app gives none (Twilio's preflight makes synthetic media too).
109
+ * Returns the stream and a function that stops everything it made. Browser only.
110
+ */
111
+ export function syntheticMedia() {
112
+ const tracks = [];
113
+ const stops = [];
114
+ const AudioCtx = globalThis.AudioContext;
115
+ if (AudioCtx) {
116
+ const ctx = new AudioCtx();
117
+ const osc = ctx.createOscillator();
118
+ const gain = ctx.createGain();
119
+ gain.gain.value = 0.05;
120
+ const dest = ctx.createMediaStreamDestination();
121
+ osc.connect(gain).connect(dest);
122
+ osc.start();
123
+ tracks.push(...dest.stream.getAudioTracks());
124
+ stops.push(() => { osc.stop(); void ctx.close(); });
125
+ }
126
+ if (typeof document !== 'undefined') {
127
+ const canvas = document.createElement('canvas');
128
+ canvas.width = 640;
129
+ canvas.height = 360;
130
+ const g = canvas.getContext('2d');
131
+ let frame = 0;
132
+ const draw = () => {
133
+ if (!g)
134
+ return;
135
+ frame += 1;
136
+ g.fillStyle = `hsl(${frame % 360}, 60%, 40%)`;
137
+ g.fillRect(0, 0, canvas.width, canvas.height);
138
+ g.fillStyle = '#fff';
139
+ g.fillRect((frame * 8) % canvas.width, 150, 60, 60);
140
+ };
141
+ draw();
142
+ const timer = setInterval(draw, 1000 / 30);
143
+ const captured = canvas.captureStream?.(30);
144
+ if (captured)
145
+ tracks.push(...captured.getVideoTracks());
146
+ stops.push(() => clearInterval(timer));
147
+ }
148
+ const stream = new MediaStream(tracks);
149
+ return { stream, stop: () => { for (const t of tracks)
150
+ t.stop(); for (const s of stops)
151
+ s(); } };
152
+ }
153
+ //# sourceMappingURL=preflight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preflight.js","sourceRoot":"","sources":["../../src/preflight.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAkD,MAAM,cAAc,CAAC;AAqDpH,MAAM,OAAO,GAAiB,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;AAE9G,qDAAqD;AACrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAC/C,sDAAsD;AACtD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAExC,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,MAA4B;IACzD,MAAM,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IAC5B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC3C,KAAK,MAAM,CAAC,IAAI,OAAO;QAAE,IAAI,OAAO,CAAC,CAAC,EAAE,KAAK,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KAAK,IAAI,CAAC,CAAC;YACX,CAAC,CAAC,SAAS,GAAG,OAAO,KAAK,GAAG,GAAG,aAAa,CAAC;YAC9C,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YAC9C,CAAC,CAAC,SAAS,GAAG,MAAM,CAAC;YACrB,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACtD,CAAC,CAAC;QACF,IAAI,EAAE,CAAC;QACP,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAI,MAA+E,CAAC,aAAa,EAAE,CAAC,EAAE,CAAC,CAAC;QACtH,IAAI,QAAQ;YAAE,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC;QACxD,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACzC,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC,IAAI,MAAM;YAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,IAAI,KAAK;YAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACnG,CAAC"}
@@ -68,6 +68,20 @@ export declare class RecordingUploader {
68
68
  private upload;
69
69
  waitForCapacity(): Promise<void>;
70
70
  seal(): Promise<void>;
71
+ /**
72
+ * How long complete() waits before asking `/complete` again when the
73
+ * answer was lost or unclear: one wait per extra attempt. Exposed for tests.
74
+ * @internal
75
+ */
76
+ static completeRetryDelaysMs: number[];
77
+ /**
78
+ * Finalise. An accepted `/complete` whose reply cannot be read rejects
79
+ * saying the recording completed. A lost or unclear answer (no reply, an
80
+ * unreadable one, a 5xx, 408/409/425/429) is asked again -- the service's
81
+ * completion is idempotent -- and if it is still unclear, rejects saying the
82
+ * recording may already be saved. Neither is aborted; only a readable
83
+ * refusal is final (V072-04).
84
+ */
71
85
  complete(): Promise<RecordingFile>;
72
86
  abort(): Promise<void>;
73
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"recording.d.ts","sourceRoot":"","sources":["../../src/recording.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,MAAM,cAAc,GACtB,UAAU,GACV,WAAW,GACX,cAAc,GACd,WAAW,GACX,OAAO,GACP,SAAS,GACT,OAAO,CAAC;AACZ,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,cAAc,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AACD,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB;AACD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,aAAa,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc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AC;IAiClC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAe7B;AAED,+EAA+E;AAC/E,qBAAa,eAAe;IASxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAV1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,IAAI,CAAyC;IACrD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoC;IAC1D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4B;IACvD,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,aAAa,CAAK;gBAEP,SAAS,EAAE,MAAM,WAAW,GAAG,IAAI,EACnC,YAAY,EAAE,MAAM,MAAM,EAC1B,OAAO,EAAE,gBAAgB;IAE5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsChB,IAAI,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;YAKxB,GAAG;CAmLlB"}
@@ -7,8 +7,9 @@ export class RecordingError extends Error {
7
7
  }
8
8
  }
9
9
  const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
10
- export async function recordingRequest(base, path, body, token) {
11
- const response = await fetch(`${base.replace(/\/$/, "")}/recording/upload${path}`, {
10
+ /** One POST to the recording API. */
11
+ function recordingFetch(base, path, body, token) {
12
+ return fetch(`${base.replace(/\/$/, "")}/recording/upload${path}`, {
12
13
  method: "POST",
13
14
  credentials: "omit",
14
15
  headers: {
@@ -18,6 +19,9 @@ export async function recordingRequest(base, path, body, token) {
18
19
  body: JSON.stringify(body),
19
20
  signal: AbortSignal.timeout(path.endsWith("/complete") ? 180000 : 15000),
20
21
  });
22
+ }
23
+ export async function recordingRequest(base, path, body, token) {
24
+ const response = await recordingFetch(base, path, body, token);
21
25
  const result = (await response.json());
22
26
  if (!response.ok || !result.success || !result.data)
23
27
  throw new RecordingError(result.error?.message ?? "Recording request failed", response.status);
@@ -222,11 +226,53 @@ export class RecordingUploader {
222
226
  }
223
227
  this.sealed = true;
224
228
  }
229
+ /**
230
+ * How long complete() waits before asking `/complete` again when the
231
+ * answer was lost or unclear: one wait per extra attempt. Exposed for tests.
232
+ * @internal
233
+ */
234
+ static completeRetryDelaysMs = [1000, 3000];
235
+ /**
236
+ * Finalise. An accepted `/complete` whose reply cannot be read rejects
237
+ * saying the recording completed. A lost or unclear answer (no reply, an
238
+ * unreadable one, a 5xx, 408/409/425/429) is asked again -- the service's
239
+ * completion is idempotent -- and if it is still unclear, rejects saying the
240
+ * recording may already be saved. Neither is aborted; only a readable
241
+ * refusal is final (V072-04).
242
+ */
225
243
  async complete() {
226
244
  await this.seal();
227
- const file = await recordingRequest(this.options.apiUrl, `/sessions/${this.session.recording.id}/complete`, {}, this.session.token);
228
- this.emit("ready");
229
- return file;
245
+ const path = `/sessions/${this.session.recording.id}/complete`;
246
+ for (let attempt = 0;; attempt++) {
247
+ let status = 0;
248
+ let body = null;
249
+ try {
250
+ const response = await recordingFetch(this.options.apiUrl, path, {}, this.session.token);
251
+ status = response.status;
252
+ const parsed = await response.json();
253
+ if (parsed && typeof parsed === "object")
254
+ body = parsed;
255
+ }
256
+ catch {
257
+ // Lost, cut short or unreadable: the service may have saved it.
258
+ }
259
+ if (body && status > 0 && status < 400 && body.success === true) {
260
+ const file = body.data;
261
+ if (!file || typeof file !== "object" || typeof file.id !== "string") {
262
+ throw new RecordingError("The recording was completed but its reply could not be read", status);
263
+ }
264
+ this.emit("ready");
265
+ return file;
266
+ }
267
+ if (body && status > 0 && status < 500 && ![408, 409, 425, 429].includes(status)) {
268
+ throw new RecordingError(body.error?.message ?? "Recording request failed", status);
269
+ }
270
+ const delays = RecordingUploader.completeRetryDelaysMs;
271
+ if (attempt >= delays.length) {
272
+ throw new RecordingError("The service did not confirm the recording, which may already be saved; it was not aborted", status);
273
+ }
274
+ await delay(delays[attempt]);
275
+ }
230
276
  }
231
277
  async abort() {
232
278
  this.canceled = true;