@caprid/relay 0.4.0 → 0.5.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 +4 -3
- package/dist/connect.d.ts +40 -5
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +19 -3
- package/dist/connect.js.map +1 -1
- package/dist/discovery.d.ts +38 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +273 -0
- package/dist/discovery.js.map +1 -0
- package/dist/frame-writer.d.ts +1 -2
- package/dist/frame-writer.d.ts.map +1 -1
- package/dist/frame-writer.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/media-track-properties.js +1 -1
- package/dist/media-track-properties.js.map +1 -1
- package/dist/media.d.ts +4 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +4 -1
- package/dist/media.js.map +1 -1
- package/dist/namespace-events.d.ts +32 -3
- package/dist/namespace-events.d.ts.map +1 -1
- package/dist/namespace-events.js +82 -7
- package/dist/namespace-events.js.map +1 -1
- package/dist/node.d.ts +13 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +17 -0
- package/dist/node.js.map +1 -1
- package/dist/presence.d.ts +155 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +485 -0
- package/dist/presence.js.map +1 -0
- package/dist/publish.d.ts +61 -7
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +208 -87
- package/dist/publish.js.map +1 -1
- package/dist/publishing-roots.d.ts +189 -0
- package/dist/publishing-roots.d.ts.map +1 -0
- package/dist/publishing-roots.js +426 -0
- package/dist/publishing-roots.js.map +1 -0
- package/dist/relay-session.d.ts +31 -0
- package/dist/relay-session.d.ts.map +1 -0
- package/dist/relay-session.js +64 -0
- package/dist/relay-session.js.map +1 -0
- package/dist/subscription-events.d.ts +5 -2
- package/dist/subscription-events.d.ts.map +1 -1
- package/dist/subscription-events.js +20 -6
- package/dist/subscription-events.js.map +1 -1
- package/dist/supervised-publisher.d.ts.map +1 -1
- package/dist/supervised-publisher.js +42 -808
- package/dist/supervised-publisher.js.map +1 -1
- package/dist/supervised-relay.d.ts +112 -0
- package/dist/supervised-relay.d.ts.map +1 -0
- package/dist/supervised-relay.js +80 -0
- package/dist/supervised-relay.js.map +1 -0
- package/dist/supervised-subscriber.d.ts +66 -4
- package/dist/supervised-subscriber.d.ts.map +1 -1
- package/dist/supervised-subscriber.js +244 -557
- package/dist/supervised-subscriber.js.map +1 -1
- package/dist/supervised-track.d.ts +63 -0
- package/dist/supervised-track.d.ts.map +1 -0
- package/dist/supervised-track.js +430 -0
- package/dist/supervised-track.js.map +1 -0
- package/dist/supervisor.d.ts +92 -0
- package/dist/supervisor.d.ts.map +1 -0
- package/dist/supervisor.js +720 -0
- package/dist/supervisor.js.map +1 -0
- package/dist/switchable.d.ts +1 -1
- package/dist/write-slot.d.ts +5 -0
- package/dist/write-slot.d.ts.map +1 -1
- package/dist/write-slot.js +3 -0
- package/dist/write-slot.js.map +1 -1
- package/package.json +8 -7
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { assertTimeoutMs, reportEndpoint } from './connect-session.js';
|
|
2
|
-
import { RelayError } from './errors.js';
|
|
3
1
|
import { connectRelayPublisher, } from './publish.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { namespaceFields
|
|
7
|
-
import { CALL_STARTED_AT, MOVED_OFF, now } from './write-slot.js';
|
|
2
|
+
import { backoffOptions, newGeneration, RECONNECT_BACKOFF, rotateBeforeOption, } from './supervision.js';
|
|
3
|
+
import { createSupervisor } from './supervisor.js';
|
|
4
|
+
import { namespaceFields } from './validation.js';
|
|
8
5
|
/**
|
|
9
6
|
* Open a publisher that reconnects: each connection serves `namespace` plus a fresh generation field, and the track
|
|
10
7
|
* writers `registerTrack` returns outlive the connections. Resolves once the first generation is up; see
|
|
@@ -13,27 +10,6 @@ import { CALL_STARTED_AT, MOVED_OFF, now } from './write-slot.js';
|
|
|
13
10
|
export function connectSupervisedPublisher(options) {
|
|
14
11
|
return superviseRelayPublisher(connectRelayPublisher, options);
|
|
15
12
|
}
|
|
16
|
-
/** Count an operation or open group on `generation` until the returned release runs. */
|
|
17
|
-
function use(generation) {
|
|
18
|
-
generation.busy += 1;
|
|
19
|
-
let released = false;
|
|
20
|
-
return () => {
|
|
21
|
-
if (released)
|
|
22
|
-
return;
|
|
23
|
-
released = true;
|
|
24
|
-
generation.busy -= 1;
|
|
25
|
-
if (generation.busy === 0)
|
|
26
|
-
generation.onIdle?.();
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
/** Resolve once nothing runs on `generation`. */
|
|
30
|
-
function idle(generation) {
|
|
31
|
-
if (generation.busy === 0)
|
|
32
|
-
return Promise.resolve();
|
|
33
|
-
return new Promise((resolve) => {
|
|
34
|
-
generation.onIdle = resolve;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
13
|
/**
|
|
38
14
|
* Open a supervised publisher with `connect` (`connectRelayPublisher` in the browser entry point, the Node one in
|
|
39
15
|
* `@caprid/relay/node`). Resolves once the first generation is up. A first attempt that fails on its arguments or the
|
|
@@ -51,795 +27,53 @@ export async function superviseRelayPublisher(connect, options) {
|
|
|
51
27
|
const backoff = backoffOptions('reconnect', reconnect, RECONNECT_BACKOFF);
|
|
52
28
|
const rotateBeforeMs = rotateBeforeOption(rotateBefore);
|
|
53
29
|
signal?.throwIfAborted();
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const names = new Set();
|
|
57
|
-
let current;
|
|
58
|
-
/** The generation a rotation is replacing, while its tracks move off it. */
|
|
59
|
-
let retiring;
|
|
60
|
-
/** Retired generations still closing: draining groups the relay has not acknowledged. `close()` waits for them. */
|
|
61
|
-
const draining = new Set();
|
|
62
|
-
let status = 'connecting';
|
|
63
|
-
let stopped = false;
|
|
64
|
-
let shutdown;
|
|
65
|
-
let resolveClosed = () => { };
|
|
66
|
-
const closed = new Promise((resolve) => {
|
|
67
|
-
resolveClosed = resolve;
|
|
68
|
-
});
|
|
69
|
-
// Aborts the attempt in progress and the wait between attempts; a live generation is closed gracefully instead.
|
|
70
|
-
const stopping = new AbortController();
|
|
71
|
-
/** Aborts the connection attempt in progress only: once connected, a generation is closed, not aborted. */
|
|
72
|
-
let attemptInProgress;
|
|
73
|
-
/** Asks the live generation to rotate; replaced for each generation served. */
|
|
74
|
-
/**
|
|
75
|
-
* Set by `rotate()` while a connection is up, and consumed by the rotation that answers it: the next one to start, or
|
|
76
|
-
* one whose replacement is still connecting or being discarded.
|
|
77
|
-
*/
|
|
78
|
-
let rotateRequested = false;
|
|
79
|
-
/** Wakes a serve loop waiting for its rotation; replaced for each wait. */
|
|
80
|
-
let wakeRotation = () => { };
|
|
81
|
-
const requestRotation = () => {
|
|
82
|
-
if (stopped || !current)
|
|
83
|
-
return;
|
|
84
|
-
rotateRequested = true;
|
|
85
|
-
wakeRotation();
|
|
86
|
-
};
|
|
87
|
-
const setStatus = (next, error) => {
|
|
88
|
-
if (status === next && error === undefined)
|
|
89
|
-
return;
|
|
90
|
-
status = next;
|
|
91
|
-
onStatus?.(next, error);
|
|
92
|
-
};
|
|
93
|
-
let first;
|
|
94
|
-
const started = new Promise((resolve, reject) => {
|
|
95
|
-
first = { resolve, reject };
|
|
96
|
-
});
|
|
97
|
-
const stop = (result) => {
|
|
98
|
-
if (shutdown)
|
|
99
|
-
return shutdown;
|
|
100
|
-
stopped = true;
|
|
101
|
-
const reason = result.error ?? new RelayError('CLOSED', 'Supervised publisher is closed', 'connection');
|
|
102
|
-
stopping.abort(reason);
|
|
103
|
-
attemptInProgress?.abort(reason);
|
|
104
|
-
// An abort while the first connection is still being made rejects the call that is waiting for it.
|
|
105
|
-
first?.reject(reason);
|
|
106
|
-
first = undefined;
|
|
107
|
-
shutdown = (async () => {
|
|
108
|
-
const open = [current, retiring].filter((generation) => generation !== undefined);
|
|
109
|
-
current = undefined;
|
|
110
|
-
retiring = undefined;
|
|
111
|
-
for (const track of tracks.values())
|
|
112
|
-
track.retire();
|
|
113
|
-
await Promise.all([
|
|
114
|
-
...open.map((generation) => {
|
|
115
|
-
generation.ended = true;
|
|
116
|
-
return generation.publisher.close().catch(() => { });
|
|
117
|
-
}),
|
|
118
|
-
...draining,
|
|
119
|
-
]);
|
|
120
|
-
try {
|
|
121
|
-
setStatus('closed');
|
|
122
|
-
}
|
|
123
|
-
finally {
|
|
124
|
-
resolveClosed(result);
|
|
125
|
-
}
|
|
126
|
-
})();
|
|
127
|
-
// A throwing onStatus fails `close()` for the caller that made it; a stop nobody awaits leaves it observed.
|
|
128
|
-
shutdown.catch(() => { });
|
|
129
|
-
return shutdown;
|
|
130
|
-
};
|
|
131
|
-
const onAbort = () => void stop({ error: signal?.reason });
|
|
132
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
133
|
-
/** Connect one generation, or `undefined` if the supervisor stopped first. Throws the attempt's failure. */
|
|
134
|
-
const connectGeneration = async () => {
|
|
135
|
-
const generation = newGeneration();
|
|
30
|
+
const supervisor = createSupervisor(async (attempt, generation) => {
|
|
31
|
+
// A publisher connection announces one namespace, chosen as it connects: this generation's.
|
|
136
32
|
const namespace = [...root, generation];
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
namespace,
|
|
143
|
-
signal: signal ? AbortSignal.any([signal, attemptInProgress.signal]) : attemptInProgress.signal,
|
|
144
|
-
[reportEndpoint]: (endpoint) => {
|
|
145
|
-
connection.url ??= endpoint;
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
finally {
|
|
150
|
-
attemptInProgress = undefined;
|
|
151
|
-
}
|
|
152
|
-
if (stopped) {
|
|
153
|
-
await publisher.close().catch(() => { });
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
const live = {
|
|
157
|
-
info: { generation, namespace },
|
|
158
|
-
publisher,
|
|
159
|
-
ended: false,
|
|
160
|
-
upAt: performance.now(),
|
|
161
|
-
rotateAt: rotationDeadline(publisher.expiresAt, rotateBeforeMs),
|
|
162
|
-
busy: 0,
|
|
163
|
-
groupHolds: new Map(),
|
|
164
|
-
};
|
|
165
|
-
// Marked in the turn the connection reports its end, before anything awaiting `closed` resumes.
|
|
166
|
-
void publisher.closed.then(() => {
|
|
167
|
-
live.ended = true;
|
|
168
|
-
// The connection's end closed its groups under the application, which may never close them itself.
|
|
169
|
-
for (const release of [...live.groupHolds.keys()])
|
|
170
|
-
release();
|
|
171
|
-
});
|
|
172
|
-
return live;
|
|
173
|
-
};
|
|
174
|
-
const report = (live) => {
|
|
175
|
-
onGeneration?.({ generation: live.info.generation, namespace: [...live.info.namespace] });
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* Bring up the generation that replaces `live` and move the tracks to it, make-before-break. Returns it, or
|
|
179
|
-
* `undefined` when `live` ended or the supervisor stopped before a replacement was up, or when an automatic rotation
|
|
180
|
-
* found no fresher credential.
|
|
181
|
-
*/
|
|
182
|
-
const rotateFrom = async (live, manual) => {
|
|
183
|
-
let failures = 0;
|
|
184
|
-
let next;
|
|
185
|
-
// The live generation ending while its replacement is still connecting is a reconnect: report it at once.
|
|
186
|
-
void live.publisher.closed.then(({ error }) => {
|
|
187
|
-
if (stopped || current !== live)
|
|
188
|
-
return;
|
|
189
|
-
current = undefined;
|
|
190
|
-
for (const track of tracks.values())
|
|
191
|
-
track.unbind(live);
|
|
192
|
-
try {
|
|
193
|
-
setStatus('reconnecting', error);
|
|
194
|
-
}
|
|
195
|
-
catch (thrown) {
|
|
196
|
-
void stop({ error: thrown });
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
while (!stopped && !live.ended) {
|
|
200
|
-
try {
|
|
201
|
-
next = await connectGeneration();
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
catch {
|
|
205
|
-
if (stopped)
|
|
206
|
-
return undefined;
|
|
207
|
-
// The live generation keeps serving; try again after the backoff unless it ends first.
|
|
208
|
-
await Promise.race([
|
|
209
|
-
sleep(backoffDelay(failures++, backoff), stopping.signal).catch(() => { }),
|
|
210
|
-
live.publisher.closed,
|
|
211
|
-
]);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (!next)
|
|
215
|
-
return undefined;
|
|
216
|
-
// `close()` may have run while the helper's result was on its way here: it could not see this connection.
|
|
217
|
-
if (stopped) {
|
|
218
|
-
next.ended = true;
|
|
219
|
-
await next.publisher.close().catch(() => { });
|
|
220
|
-
return undefined;
|
|
221
|
-
}
|
|
222
|
-
// Consulted whatever happened to the old generation: a queued `rotate()` is answered by this replacement.
|
|
223
|
-
const asked = manual();
|
|
224
|
-
if (!live.ended && !asked) {
|
|
225
|
-
// A credential that expires no later than the live one replaces nothing: the relay would end both together.
|
|
226
|
-
const was = live.publisher.expiresAt?.getTime();
|
|
227
|
-
const now = next.publisher.expiresAt?.getTime();
|
|
228
|
-
if (was !== undefined && (now === undefined || now <= was)) {
|
|
229
|
-
next.ended = true;
|
|
230
|
-
await next.publisher.close().catch(() => { });
|
|
231
|
-
return undefined;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
current = next;
|
|
235
|
-
retiring = live;
|
|
236
|
-
const moved = [...tracks.values()].map((track) => track.handOver(next));
|
|
237
|
-
setStatus('live');
|
|
238
|
-
report(next);
|
|
239
|
-
// Every track moved and every write or group still on the old generation finished, or the overlap ran out.
|
|
240
|
-
// The next generation ending cuts the overlap short too: its tracks need the generation after it now. So does its
|
|
241
|
-
// own rotation falling due, for a credential shorter than the overlap.
|
|
242
|
-
const overlap = new AbortController();
|
|
243
|
-
// A group can close without the wrapper hearing of it (its signal, the relay resetting demand): release its hold
|
|
244
|
-
// once it is closed, whatever closed it.
|
|
245
|
-
const sweep = () => {
|
|
246
|
-
for (const [release, group] of [...live.groupHolds])
|
|
247
|
-
if (group.closed)
|
|
248
|
-
release();
|
|
249
|
-
};
|
|
250
|
-
const sweeper = setInterval(sweep, 50);
|
|
251
|
-
await Promise.race([
|
|
252
|
-
Promise.all(moved).then(() => {
|
|
253
|
-
sweep();
|
|
254
|
-
return idle(live);
|
|
255
|
-
}),
|
|
256
|
-
sleep(ROTATION_OVERLAP_MS, stopping.signal).catch(() => { }),
|
|
257
|
-
live.publisher.closed,
|
|
258
|
-
next.publisher.closed,
|
|
259
|
-
rotationDue(next.rotateAt, new Promise(() => { }), AbortSignal.any([stopping.signal, overlap.signal])),
|
|
260
|
-
]);
|
|
261
|
-
overlap.abort();
|
|
262
|
-
clearInterval(sweeper);
|
|
263
|
-
live.onIdle = undefined;
|
|
264
|
-
for (const track of tracks.values())
|
|
265
|
-
track.settle();
|
|
266
|
-
live.ended = true;
|
|
267
|
-
// A track whose next generation ended before it moved is still bound here: it has no generation now.
|
|
268
|
-
for (const track of tracks.values())
|
|
269
|
-
track.unbind(live);
|
|
270
|
-
if (retiring === live)
|
|
271
|
-
retiring = undefined;
|
|
272
|
-
// Closing drains the old generation's unacknowledged groups for up to a write deadline; the next generation is
|
|
273
|
-
// served meanwhile, and `close()` waits for the drain.
|
|
274
|
-
const drain = live.publisher
|
|
275
|
-
.close()
|
|
276
|
-
.catch(() => { })
|
|
277
|
-
.then(() => {
|
|
278
|
-
draining.delete(drain);
|
|
279
|
-
for (const track of tracks.values())
|
|
280
|
-
track.forget(live);
|
|
281
|
-
});
|
|
282
|
-
draining.add(drain);
|
|
283
|
-
return next;
|
|
284
|
-
};
|
|
285
|
-
/** Serve `live` until it ends, or until a rotation replaced it with the generation returned. */
|
|
286
|
-
const serve = async (live) => {
|
|
287
|
-
const scope = new AbortController();
|
|
288
|
-
/** Cleared once an automatic rotation found no fresher credential: only `rotate()` tries again. */
|
|
289
|
-
let automatic = true;
|
|
290
|
-
try {
|
|
291
|
-
for (;;) {
|
|
292
|
-
const asked = new Promise((resolve) => {
|
|
293
|
-
wakeRotation = resolve;
|
|
294
|
-
});
|
|
295
|
-
if (rotateRequested)
|
|
296
|
-
wakeRotation();
|
|
297
|
-
const due = rotationDue(automatic ? live.rotateAt : undefined, asked, AbortSignal.any([stopping.signal, scope.signal])).then(() => undefined);
|
|
298
|
-
const outcome = await Promise.race([live.publisher.closed, due]);
|
|
299
|
-
if (outcome !== undefined || stopped)
|
|
300
|
-
return outcome ?? {};
|
|
301
|
-
// A `rotate()` before the replacement is current makes this rotation a manual one: it takes the replacement.
|
|
302
|
-
let manual = false;
|
|
303
|
-
const isManual = () => {
|
|
304
|
-
if (rotateRequested) {
|
|
305
|
-
rotateRequested = false;
|
|
306
|
-
manual = true;
|
|
307
|
-
}
|
|
308
|
-
return manual;
|
|
309
|
-
};
|
|
310
|
-
isManual();
|
|
311
|
-
const next = await rotateFrom(live, isManual);
|
|
312
|
-
if (next)
|
|
313
|
-
return { next };
|
|
314
|
-
if (live.ended || stopped)
|
|
315
|
-
return await live.publisher.closed;
|
|
316
|
-
if (!manual)
|
|
317
|
-
automatic = false;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
finally {
|
|
321
|
-
scope.abort();
|
|
322
|
-
wakeRotation = () => { };
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
const run = async () => {
|
|
326
|
-
let attempt = 0;
|
|
327
|
-
/** A generation a rotation already brought up, reported and moved the tracks to. */
|
|
328
|
-
let next;
|
|
329
|
-
while (!stopped) {
|
|
330
|
-
let live = next;
|
|
331
|
-
next = undefined;
|
|
332
|
-
if (!live) {
|
|
333
|
-
try {
|
|
334
|
-
live = await connectGeneration();
|
|
335
|
-
}
|
|
336
|
-
catch (error) {
|
|
337
|
-
if (stopped)
|
|
338
|
-
return;
|
|
339
|
-
if (first && isSetupFailure(error)) {
|
|
340
|
-
first.reject(error);
|
|
341
|
-
first = undefined;
|
|
342
|
-
await stop({ error });
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
setStatus('reconnecting', error);
|
|
346
|
-
await sleep(backoffDelay(attempt++, backoff), stopping.signal).catch(() => { });
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
if (!live)
|
|
350
|
-
return;
|
|
351
|
-
// `close()` may have run while the helper's result was on its way here: it could not see this connection.
|
|
352
|
-
if (stopped) {
|
|
353
|
-
live.ended = true;
|
|
354
|
-
await live.publisher.close().catch(() => { });
|
|
355
|
-
return;
|
|
33
|
+
const publisher = await connect({ ...attempt, namespace });
|
|
34
|
+
return {
|
|
35
|
+
publish(announced) {
|
|
36
|
+
if (JSON.stringify(announced) !== JSON.stringify(namespace)) {
|
|
37
|
+
throw new RangeError('A publisher connection serves only the namespace it connected with');
|
|
356
38
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
first?.resolve();
|
|
363
|
-
first = undefined;
|
|
364
|
-
}
|
|
365
|
-
const outcome = await serve(live);
|
|
366
|
-
if (stopped)
|
|
367
|
-
return;
|
|
368
|
-
if ('next' in outcome) {
|
|
369
|
-
next = outcome.next;
|
|
370
|
-
attempt = 0;
|
|
371
|
-
continue;
|
|
372
|
-
}
|
|
373
|
-
live.ended = true;
|
|
374
|
-
current = undefined;
|
|
375
|
-
for (const track of tracks.values())
|
|
376
|
-
track.unbind(live);
|
|
377
|
-
// Already reported if the generation ended while a rotation's replacement was connecting.
|
|
378
|
-
if (status !== 'reconnecting')
|
|
379
|
-
setStatus('reconnecting', outcome.error);
|
|
380
|
-
// A generation that stayed up longer than the longest delay was a success: start the backoff over.
|
|
381
|
-
if (performance.now() - live.upAt > backoff.maxDelayMs)
|
|
382
|
-
attempt = 0;
|
|
383
|
-
await sleep(backoffDelay(attempt++, backoff), stopping.signal).catch(() => { });
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
const supervise = async () => {
|
|
387
|
-
try {
|
|
388
|
-
await run();
|
|
389
|
-
}
|
|
390
|
-
catch (error) {
|
|
391
|
-
// An application callback (onStatus, onGeneration) threw: stop rather than leave the supervisor neither
|
|
392
|
-
// reconnecting nor closed, and fail a caller still waiting to connect.
|
|
393
|
-
void stop({ error });
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
void supervise();
|
|
397
|
-
try {
|
|
398
|
-
await started;
|
|
399
|
-
}
|
|
400
|
-
catch (error) {
|
|
401
|
-
signal?.removeEventListener('abort', onAbort);
|
|
402
|
-
throw error;
|
|
403
|
-
}
|
|
404
|
-
if (stopped)
|
|
405
|
-
throw signal?.reason ?? new RelayError('CLOSED', 'Supervised publisher is closed', 'connection');
|
|
406
|
-
return {
|
|
407
|
-
get generation() {
|
|
408
|
-
return current ? { ...current.info, namespace: [...current.info.namespace] } : undefined;
|
|
409
|
-
},
|
|
410
|
-
get status() {
|
|
411
|
-
return status;
|
|
412
|
-
},
|
|
413
|
-
closed,
|
|
414
|
-
registerTrack(trackOptions) {
|
|
415
|
-
if (typeof trackOptions !== 'object' || trackOptions === null) {
|
|
416
|
-
throw new TypeError('registerTrack takes an options object');
|
|
417
|
-
}
|
|
418
|
-
const { track, trackProperties, writeTimeoutMs = 10_000 } = trackOptions;
|
|
419
|
-
const name = trackName(track);
|
|
420
|
-
trackPropertyPairs(trackProperties);
|
|
421
|
-
assertTimeoutMs('writeTimeoutMs', writeTimeoutMs);
|
|
422
|
-
if (stopped)
|
|
423
|
-
throw new RelayError('CLOSED', 'Supervised publisher is closed', 'connection');
|
|
424
|
-
if (names.has(name))
|
|
425
|
-
throw new RangeError('Track name is already registered on this supervised publisher');
|
|
426
|
-
const properties = trackProperties?.map(({ type, value }) => ({
|
|
427
|
-
type,
|
|
428
|
-
// Copied now: every generation registers the track again, after the caller may have reused its buffers.
|
|
429
|
-
value: typeof value === 'number' ? value : new Uint8Array(value.buffer, value.byteOffset, value.byteLength).slice(),
|
|
430
|
-
}));
|
|
431
|
-
const supervised = new SupervisedTrack({ track: name, writeTimeoutMs, ...(properties ? { trackProperties: properties } : {}) }, () => tracks.delete(name));
|
|
432
|
-
tracks.set(name, supervised);
|
|
433
|
-
names.add(name);
|
|
434
|
-
if (current)
|
|
435
|
-
supervised.bind(current);
|
|
436
|
-
return supervised.writer;
|
|
437
|
-
},
|
|
438
|
-
rotate: () => requestRotation(),
|
|
439
|
-
close: () => {
|
|
440
|
-
signal?.removeEventListener('abort', onAbort);
|
|
441
|
-
return stop({});
|
|
442
|
-
},
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
/** The failure for a write made while no generation is up, or one the connection's end interrupted. */
|
|
446
|
-
function reconnecting(cause) {
|
|
447
|
-
return new RelayError('RECONNECTING', 'The supervised publisher is between connections; nothing was replayed. Write the next object when it is live', 'connection', cause === undefined ? undefined : { cause });
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Whether a failure from a generation's writer means its connection ended under the operation. Only the generation's
|
|
451
|
-
* end decides, never the code: `CLOSED` also means a write to a finished group or an abort without a reason, while
|
|
452
|
-
* the generation stays live. An operation can fail a little before the connection reports its end, so a RelayError
|
|
453
|
-
* waits up to the closure grace for that report.
|
|
454
|
-
*/
|
|
455
|
-
async function endedUnder(error, generation) {
|
|
456
|
-
if (!(error instanceof RelayError))
|
|
457
|
-
return false;
|
|
458
|
-
if (!generation.ended) {
|
|
459
|
-
let timer;
|
|
460
|
-
await Promise.race([
|
|
461
|
-
generation.publisher.closed,
|
|
462
|
-
new Promise((resolve) => {
|
|
463
|
-
timer = setTimeout(resolve, CLOSURE_GRACE_MS);
|
|
464
|
-
}),
|
|
465
|
-
]);
|
|
466
|
-
clearTimeout(timer);
|
|
467
|
-
}
|
|
468
|
-
return generation.ended;
|
|
469
|
-
}
|
|
470
|
-
/** One registered track across generations: its writer, the binding to the live generation, and demand. */
|
|
471
|
-
class SupervisedTrack {
|
|
472
|
-
writer;
|
|
473
|
-
/**
|
|
474
|
-
* The live generation's writer. `covered` is set when a move reported the writer's `true`: its iterator's next `true`
|
|
475
|
-
* is that same demand, not a new one, unless a `false` came first.
|
|
476
|
-
*/
|
|
477
|
-
#binding;
|
|
478
|
-
/** The generation a rotation is moving this track to, until it moves. */
|
|
479
|
-
#pending;
|
|
480
|
-
/** The holds of groups open on any generation, released when the track closes and ends them. */
|
|
481
|
-
#groupHolds = new Set();
|
|
482
|
-
/** Writers on generations a rotation moved this track off, kept until they close: their open groups end with it. */
|
|
483
|
-
#retired = new Map();
|
|
484
|
-
#closed = false;
|
|
485
|
-
/** The demand the iterators last reported, so a lost generation reports `false` only after `true`. */
|
|
486
|
-
#lastDemand = false;
|
|
487
|
-
#demandListeners = new Set();
|
|
488
|
-
options;
|
|
489
|
-
constructor(options, release) {
|
|
490
|
-
this.options = options;
|
|
491
|
-
const track = this;
|
|
492
|
-
/** Run `operation` on the live generation's writer, mapping an interruption by the connection's end. */
|
|
493
|
-
const onLive = async (operation) => {
|
|
494
|
-
if (track.#closed)
|
|
495
|
-
throw new RelayError('CLOSED', 'Published track is closed', 'waiting-for-demand');
|
|
496
|
-
// A rotation moves the track at an operation's start, never under one.
|
|
497
|
-
track.#maybeMove();
|
|
498
|
-
const binding = track.#binding;
|
|
499
|
-
if (!binding)
|
|
500
|
-
throw reconnecting();
|
|
501
|
-
// A rotation keeps the generation open until the operation (and a group it opens) is done.
|
|
502
|
-
const release = use(binding.generation);
|
|
503
|
-
try {
|
|
504
|
-
return await operation(binding.writer, binding.generation, release);
|
|
505
|
-
}
|
|
506
|
-
catch (error) {
|
|
507
|
-
if (!track.#closed && (await endedUnder(error, binding.generation)))
|
|
508
|
-
throw reconnecting(error);
|
|
509
|
-
throw error;
|
|
510
|
-
}
|
|
511
|
-
finally {
|
|
512
|
-
release();
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
this.writer = {
|
|
516
|
-
get hasDemand() {
|
|
517
|
-
return track.#binding?.writer.hasDemand ?? false;
|
|
518
|
-
},
|
|
519
|
-
get closed() {
|
|
520
|
-
return track.#closed;
|
|
521
|
-
},
|
|
522
|
-
demandChanges: () => track.#demandChanges(),
|
|
523
|
-
openGroup: async (options) => {
|
|
524
|
-
// The first object's clock starts at this call, so checking its arguments here counts (§5.2).
|
|
525
|
-
const startedAt = now();
|
|
526
|
-
// Arguments before connection or slot state (spec/behavior.md, "Arguments"), and the checked copies are what
|
|
527
|
-
// the live writer gets: the caller's own objects are read once.
|
|
528
|
-
const signal = options?.signal;
|
|
529
|
-
let opening = { [CALL_STARTED_AT]: startedAt };
|
|
530
|
-
if (options?.payload !== undefined) {
|
|
531
|
-
opening = { ...opening, payload: payloadBytes(options.payload) };
|
|
532
|
-
if (options.properties !== undefined)
|
|
533
|
-
opening = { ...opening, properties: objectPropertyPairs(options.properties) };
|
|
534
|
-
}
|
|
535
|
-
else if (options?.properties !== undefined)
|
|
536
|
-
throw new TypeError('Group properties belong to a first object: pass a payload with them');
|
|
537
|
-
if (signal !== undefined)
|
|
538
|
-
opening = { ...opening, signal };
|
|
539
|
-
return onLive(async (writer, generation) => {
|
|
540
|
-
const group = await writer.openGroup(opening);
|
|
541
|
-
// The generation the group was opened on, read before the await: a disconnect meanwhile clears the binding.
|
|
542
|
-
// The group holds the generation open until it is closed or aborted.
|
|
543
|
-
const hold = use(generation);
|
|
544
|
-
const onAbort = () => {
|
|
545
|
-
if (group.closed)
|
|
546
|
-
release();
|
|
547
|
-
};
|
|
548
|
-
const release = () => {
|
|
549
|
-
track.#groupHolds.delete(release);
|
|
550
|
-
generation.groupHolds.delete(release);
|
|
551
|
-
signal?.removeEventListener('abort', onAbort);
|
|
552
|
-
hold();
|
|
553
|
-
};
|
|
554
|
-
track.#groupHolds.add(release);
|
|
555
|
-
generation.groupHolds.set(release, group);
|
|
556
|
-
// Opened under a connection that has ended meanwhile: nothing will release it on the end.
|
|
557
|
-
if (generation.ended)
|
|
558
|
-
release();
|
|
559
|
-
// A group its signal aborted is closed without the wrapper hearing of it: release then, or now if already so.
|
|
560
|
-
if (group.closed)
|
|
561
|
-
release();
|
|
562
|
-
else
|
|
563
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
564
|
-
return supervisedGroup(group, () => track.#closed, generation, release, () => track.#binding?.generation !== generation);
|
|
565
|
-
});
|
|
566
|
-
},
|
|
567
|
-
write: async (payload, options) => {
|
|
568
|
-
// The object's clock starts at this call, so checking its arguments here counts (§5.2).
|
|
569
|
-
const startedAt = now();
|
|
570
|
-
// Arguments before connection or slot state (spec/behavior.md, "Arguments"), and the checked copies are what
|
|
571
|
-
// the live writer gets: the caller's own objects are read once.
|
|
572
|
-
const bytes = payloadBytes(payload);
|
|
573
|
-
let writing = { [CALL_STARTED_AT]: startedAt };
|
|
574
|
-
if (options?.properties !== undefined)
|
|
575
|
-
writing = { ...writing, properties: objectPropertyPairs(options.properties) };
|
|
576
|
-
if (options?.signal !== undefined)
|
|
577
|
-
writing = { ...writing, signal: options.signal };
|
|
578
|
-
return onLive((writer) => writer.write(bytes, writing));
|
|
579
|
-
},
|
|
580
|
-
writeText: (text, options) => onLive((writer) => writer.writeText(text, options)),
|
|
581
|
-
writeJSON: (value, options) => onLive((writer) => writer.writeJSON(value, options)),
|
|
582
|
-
close: () => {
|
|
583
|
-
if (track.#closed)
|
|
584
|
-
return;
|
|
585
|
-
track.#closed = true;
|
|
586
|
-
release();
|
|
587
|
-
track.#binding?.writer.close();
|
|
588
|
-
track.#binding = undefined;
|
|
589
|
-
for (const retired of track.#retired.values())
|
|
590
|
-
retired.close();
|
|
591
|
-
track.#retired.clear();
|
|
592
|
-
// Closing the writers ended their groups: none holds a rotating generation open any more.
|
|
593
|
-
for (const release of [...track.#groupHolds])
|
|
594
|
-
release();
|
|
595
|
-
track.#dropPending(true);
|
|
596
|
-
track.#endDemand();
|
|
597
|
-
},
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
/** Register this track on a new generation. A registration the new connection refuses leaves it unbound. */
|
|
601
|
-
bind(generation) {
|
|
602
|
-
if (this.#closed)
|
|
603
|
-
return;
|
|
604
|
-
let writer;
|
|
605
|
-
try {
|
|
606
|
-
writer = generation.publisher.registerTrack(this.options);
|
|
607
|
-
}
|
|
608
|
-
catch {
|
|
609
|
-
// Its arguments were checked when the application registered it, so only the connection's end lands here.
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
this.#binding = { generation, writer };
|
|
613
|
-
void this.#follow(generation, writer);
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* A rotation brought up `generation`: register this track on it and move there once it has demand there or none on
|
|
617
|
-
* the current generation. Resolves once moved, or once the track closed or could not be registered.
|
|
618
|
-
*/
|
|
619
|
-
handOver(generation) {
|
|
620
|
-
if (this.#closed)
|
|
621
|
-
return Promise.resolve();
|
|
622
|
-
if (!this.#binding || this.#binding.generation.ended) {
|
|
623
|
-
this.bind(generation);
|
|
624
|
-
return Promise.resolve();
|
|
625
|
-
}
|
|
626
|
-
let writer;
|
|
627
|
-
try {
|
|
628
|
-
writer = generation.publisher.registerTrack(this.options);
|
|
629
|
-
}
|
|
630
|
-
catch {
|
|
631
|
-
// As in `bind`: only the new connection's end lands here.
|
|
632
|
-
return Promise.resolve();
|
|
633
|
-
}
|
|
634
|
-
return new Promise((moved) => {
|
|
635
|
-
this.#pending = { generation, writer, moved };
|
|
636
|
-
void this.#follow(generation, writer);
|
|
637
|
-
this.#maybeMove();
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
/** The rotation closed `generation`: nothing on it is left to close with the track. */
|
|
641
|
-
forget(generation) {
|
|
642
|
-
this.#retired.delete(generation);
|
|
643
|
-
}
|
|
644
|
-
/** The rotation's overlap is over: move to the next generation now, wherever demand is. */
|
|
645
|
-
settle() {
|
|
646
|
-
this.#maybeMove(true);
|
|
647
|
-
}
|
|
648
|
-
/** Move to the pending generation once it has demand or the current one has none, or at once when `force`d. */
|
|
649
|
-
#maybeMove(force = false) {
|
|
650
|
-
const pending = this.#pending;
|
|
651
|
-
if (!pending)
|
|
652
|
-
return;
|
|
653
|
-
if (pending.generation.ended) {
|
|
654
|
-
this.#dropPending(false);
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
const binding = this.#binding;
|
|
658
|
-
const stay = binding && !binding.generation.ended && binding.writer.hasDemand && !pending.writer.hasDemand;
|
|
659
|
-
if (stay && !force)
|
|
660
|
-
return;
|
|
661
|
-
this.#pending = undefined;
|
|
662
|
-
if (binding && !binding.generation.ended)
|
|
663
|
-
this.#retired.set(binding.generation, binding.writer);
|
|
664
|
-
// The move reports `true` for demand the iterator has not yielded yet; one it already yielded is not covered, so the
|
|
665
|
-
// next `true` it yields is new demand.
|
|
666
|
-
const covered = pending.writer.hasDemand && pending.seen !== true;
|
|
667
|
-
this.#binding = { generation: pending.generation, writer: pending.writer, covered };
|
|
668
|
-
// The move reports the next generation's demand as it is now: `true` again if it has demand, so demand-driven state
|
|
669
|
-
// reaches it, or the loss of demand. Values its iterator had queued before the move are stale and not reported.
|
|
670
|
-
this.#emitDemand(pending.writer.hasDemand);
|
|
671
|
-
pending.moved();
|
|
672
|
-
}
|
|
673
|
-
/** Give up the pending generation, closing its writer when the track itself closed. */
|
|
674
|
-
#dropPending(close) {
|
|
675
|
-
const pending = this.#pending;
|
|
676
|
-
if (!pending)
|
|
677
|
-
return;
|
|
678
|
-
this.#pending = undefined;
|
|
679
|
-
if (close)
|
|
680
|
-
pending.writer.close();
|
|
681
|
-
pending.moved();
|
|
682
|
-
}
|
|
683
|
-
/** The generation ended: writes fail with RECONNECTING until the next one binds. */
|
|
684
|
-
unbind(generation) {
|
|
685
|
-
if (this.#pending?.generation === generation)
|
|
686
|
-
this.#dropPending(false);
|
|
687
|
-
if (this.#binding?.generation !== generation)
|
|
688
|
-
return;
|
|
689
|
-
this.#binding = undefined;
|
|
690
|
-
this.#emitDemand(false);
|
|
691
|
-
}
|
|
692
|
-
/** The supervisor stopped: the track is closed for good. */
|
|
693
|
-
retire() {
|
|
694
|
-
for (const release of [...this.#groupHolds])
|
|
695
|
-
release();
|
|
696
|
-
if (this.#closed)
|
|
697
|
-
return;
|
|
698
|
-
this.#closed = true;
|
|
699
|
-
this.#binding = undefined;
|
|
700
|
-
this.#dropPending(false);
|
|
701
|
-
this.#endDemand();
|
|
702
|
-
}
|
|
703
|
-
async #follow(generation, writer) {
|
|
704
|
-
const changes = writer.demandChanges();
|
|
705
|
-
/** The value this iterator yielded last: a `true` after `true` is the relay replacing its upstream subscription. */
|
|
706
|
-
let previous;
|
|
707
|
-
try {
|
|
708
|
-
for await (const value of changes) {
|
|
709
|
-
const bound = this.#binding?.generation === generation;
|
|
710
|
-
const pending = this.#pending?.generation === generation ? this.#pending : undefined;
|
|
711
|
-
if (!bound && !pending)
|
|
712
|
-
break;
|
|
713
|
-
if (pending)
|
|
714
|
-
pending.seen = value;
|
|
715
|
-
// Any `true` after this iterator's first value is new demand: a repeat, or demand back after a `false`.
|
|
716
|
-
const renewed = value && previous !== undefined;
|
|
717
|
-
previous = value;
|
|
718
|
-
// Demand leaving a generation a rotation is moving off: move first if the next one has demand, so the track
|
|
719
|
-
// reports no `false` it did not have. The move reports the next generation's own demand.
|
|
720
|
-
if (bound && !value && this.#pending) {
|
|
721
|
-
this.#maybeMove();
|
|
722
|
-
if (this.#binding?.generation !== generation)
|
|
723
|
-
continue;
|
|
724
|
-
}
|
|
725
|
-
const binding = this.#binding;
|
|
726
|
-
if (bound && binding) {
|
|
727
|
-
// A `false` is not reported when the writer has demand again by now, but the `true` after it is renewed
|
|
728
|
-
// demand all the same, which demand-driven state (a catalog) is written again on. Only the move's own `true`
|
|
729
|
-
// is not repeated.
|
|
730
|
-
if (!value)
|
|
731
|
-
binding.covered = false;
|
|
732
|
-
if (value && binding.covered)
|
|
733
|
-
binding.covered = false;
|
|
734
|
-
else if (value === writer.hasDemand && (value !== this.#lastDemand || renewed))
|
|
735
|
-
this.#emitDemand(value);
|
|
736
|
-
}
|
|
737
|
-
// Demand arriving on the next generation, or leaving the current one, is what moves a rotating track.
|
|
738
|
-
this.#maybeMove();
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
finally {
|
|
742
|
-
await changes.return?.();
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
#emitDemand(value) {
|
|
746
|
-
// A repeated `true` is kept: a new upstream subscription, or a move to a generation with demand, is when demand-driven
|
|
747
|
-
// state (a catalog) is written again. Only a `false` that changes nothing is dropped.
|
|
748
|
-
if (!value && !this.#lastDemand)
|
|
749
|
-
return;
|
|
750
|
-
this.#lastDemand = value;
|
|
751
|
-
for (const listener of this.#demandListeners)
|
|
752
|
-
listener(value);
|
|
753
|
-
}
|
|
754
|
-
#endDemand() {
|
|
755
|
-
for (const listener of this.#demandListeners)
|
|
756
|
-
listener(undefined);
|
|
757
|
-
this.#demandListeners.clear();
|
|
758
|
-
}
|
|
759
|
-
/** The current demand state, then every change across generations; ends when the track closes. */
|
|
760
|
-
#demandChanges() {
|
|
761
|
-
const queue = [this.writer.hasDemand];
|
|
762
|
-
let done = this.#closed;
|
|
763
|
-
let wake;
|
|
764
|
-
const listener = (value) => {
|
|
765
|
-
if (value === undefined)
|
|
766
|
-
done = true;
|
|
767
|
-
else
|
|
768
|
-
queue.push(value);
|
|
769
|
-
wake?.();
|
|
770
|
-
};
|
|
771
|
-
if (!done)
|
|
772
|
-
this.#demandListeners.add(listener);
|
|
773
|
-
const finish = () => {
|
|
774
|
-
done = true;
|
|
775
|
-
queue.length = 0;
|
|
776
|
-
this.#demandListeners.delete(listener);
|
|
777
|
-
wake?.();
|
|
778
|
-
return { done: true, value: undefined };
|
|
779
|
-
};
|
|
780
|
-
const iterator = {
|
|
781
|
-
async next() {
|
|
782
|
-
while (queue.length === 0 && !done)
|
|
783
|
-
await new Promise((resolve) => (wake = resolve));
|
|
784
|
-
wake = undefined;
|
|
785
|
-
const value = queue.shift();
|
|
786
|
-
return value === undefined ? finish() : { done: false, value };
|
|
787
|
-
},
|
|
788
|
-
async return() {
|
|
789
|
-
return finish();
|
|
39
|
+
return {
|
|
40
|
+
registerTrack: (trackOptions) => publisher.registerTrack(trackOptions),
|
|
41
|
+
closed: publisher.closed,
|
|
42
|
+
close: () => publisher.close(),
|
|
43
|
+
};
|
|
790
44
|
},
|
|
791
|
-
|
|
792
|
-
|
|
45
|
+
closed: publisher.closed,
|
|
46
|
+
get expiresAt() {
|
|
47
|
+
return publisher.expiresAt;
|
|
793
48
|
},
|
|
49
|
+
close: () => publisher.close(),
|
|
794
50
|
};
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
throw error;
|
|
809
|
-
}
|
|
810
|
-
finally {
|
|
811
|
-
// A finished or failed group no longer holds a rotating generation open.
|
|
812
|
-
if (group.closed)
|
|
813
|
-
release();
|
|
814
|
-
}
|
|
815
|
-
};
|
|
51
|
+
}, {
|
|
52
|
+
what: 'Supervised publisher',
|
|
53
|
+
connection,
|
|
54
|
+
signal,
|
|
55
|
+
backoff,
|
|
56
|
+
rotateBeforeMs,
|
|
57
|
+
onStatus,
|
|
58
|
+
onGeneration: onGeneration
|
|
59
|
+
? (generation) => onGeneration({ generation, namespace: [...root, generation] })
|
|
60
|
+
: undefined,
|
|
61
|
+
});
|
|
62
|
+
const publication = supervisor.publish(root);
|
|
63
|
+
await supervisor.start();
|
|
816
64
|
return {
|
|
817
|
-
get
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
get groupId() {
|
|
821
|
-
return group.groupId;
|
|
822
|
-
},
|
|
823
|
-
get objectCount() {
|
|
824
|
-
return group.objectCount;
|
|
825
|
-
},
|
|
826
|
-
get closed() {
|
|
827
|
-
return group.closed;
|
|
65
|
+
get generation() {
|
|
66
|
+
const generation = supervisor.generation;
|
|
67
|
+
return generation === undefined ? undefined : { generation, namespace: [...root, generation] };
|
|
828
68
|
},
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
writeJSON: (value, options) => mapped(() => group.writeJSON(value, options)),
|
|
832
|
-
// Released by `mapped` only once the group is closed: a refused close (WRITE_PENDING) keeps it holding.
|
|
833
|
-
close: () => mapped(() => group.close()),
|
|
834
|
-
abort: (reason) => {
|
|
835
|
-
aborted = true;
|
|
836
|
-
try {
|
|
837
|
-
group.abort(reason);
|
|
838
|
-
}
|
|
839
|
-
finally {
|
|
840
|
-
release();
|
|
841
|
-
}
|
|
69
|
+
get status() {
|
|
70
|
+
return supervisor.status;
|
|
842
71
|
},
|
|
72
|
+
closed: supervisor.closed,
|
|
73
|
+
registerTrack: (trackOptions) => publication.registerTrack(trackOptions),
|
|
74
|
+
rotate: () => supervisor.rotate(),
|
|
75
|
+
// A throwing onStatus reporting `closed` rejects the promise rather than throwing from the call.
|
|
76
|
+
close: async () => supervisor.stop({}),
|
|
843
77
|
};
|
|
844
78
|
}
|
|
845
79
|
//# sourceMappingURL=supervised-publisher.js.map
|