@caprid/relay 0.4.1 → 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 +7 -7
package/dist/publish.js
CHANGED
|
@@ -23,39 +23,155 @@ function reportingObjects(subgroup, track) {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* namespace and subscribe upstream before data can flow.
|
|
26
|
+
* Create the publishing state of one connection. `onNamespaceEnded` is told when the relay withdraws its interest in
|
|
27
|
+
* a namespace while the connection lives (no solicitation covers it anymore).
|
|
29
28
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
// One write slot per registered track; the session's binding callback and the connection's end
|
|
35
|
-
// reach the slots through here.
|
|
36
|
-
const tracks = new Map();
|
|
37
|
-
// Each relay subscription's delivery timeouts (§5.2), by its request ID, which the core also uses as
|
|
38
|
-
// its track alias: SUBSCRIBE's parameters, as REQUEST_UPDATE changes them.
|
|
29
|
+
function createPublishHost(onNamespaceEnded) {
|
|
30
|
+
const publications = new Map();
|
|
31
|
+
// Each relay subscription's delivery timeouts (§5.2), by its request ID, which the core also uses as its track alias:
|
|
32
|
+
// SUBSCRIBE's parameters, as REQUEST_UPDATE changes them.
|
|
39
33
|
const subscriptionTimeouts = new Map();
|
|
40
|
-
// Groups whose FIN the transport took but the relay has not acknowledged, shared by every track.
|
|
34
|
+
// Groups whose FIN the transport took but the relay has not acknowledged, shared by every track on the connection.
|
|
41
35
|
const settlingGroups = createSettlingGroups();
|
|
42
|
-
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
/** Set once the connection starts closing: no publication may start after `endAll()` took its snapshot. */
|
|
37
|
+
let shuttingDown = false;
|
|
38
|
+
let bound;
|
|
39
|
+
let ended = false;
|
|
40
|
+
const key = (namespace) => JSON.stringify(namespace);
|
|
41
|
+
const create = (namespace, { session, assertOpen, closed: connectionClosed }) => {
|
|
42
|
+
const tracks = new Map();
|
|
43
|
+
// The connection's limit applies to every publication's groups, but closing one waits only for its own.
|
|
44
|
+
const ownGroups = createSettlingGroups(Number.POSITIVE_INFINITY);
|
|
45
|
+
const groups = {
|
|
46
|
+
hasRoom: () => settlingGroups.hasRoom(),
|
|
47
|
+
waitForRoom: (interrupted) => settlingGroups.waitForRoom(interrupted),
|
|
48
|
+
add(settled) {
|
|
49
|
+
settlingGroups.add(settled);
|
|
50
|
+
ownGroups.add(settled);
|
|
51
|
+
},
|
|
52
|
+
drain: (timeoutMs, stop) => ownGroups.drain(timeoutMs, stop),
|
|
53
|
+
get size() {
|
|
54
|
+
return ownGroups.size;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
/** Set once the application's close() starts. */
|
|
58
|
+
let closingByApplication = false;
|
|
59
|
+
/** Set when the namespace was lost while the connection lives: every later operation fails with it. */
|
|
60
|
+
let lost;
|
|
61
|
+
const assertPublished = () => {
|
|
62
|
+
assertOpen();
|
|
63
|
+
if (lost)
|
|
64
|
+
throw lost.error;
|
|
65
|
+
};
|
|
66
|
+
// What closing waits for: the largest write deadline among the tracks.
|
|
67
|
+
let drainMs = 0;
|
|
68
|
+
let closing = false;
|
|
69
|
+
let shutdown;
|
|
70
|
+
let resolveClosed = () => { };
|
|
71
|
+
const closed = new Promise((resolve) => {
|
|
72
|
+
resolveClosed = resolve;
|
|
73
|
+
});
|
|
74
|
+
let announce = () => { };
|
|
75
|
+
let abandonAnnounce = () => { };
|
|
76
|
+
const announced = new Promise((resolve, reject) => {
|
|
77
|
+
announce = resolve;
|
|
78
|
+
abandonAnnounce = reject;
|
|
79
|
+
});
|
|
80
|
+
// Nobody may await readiness; a rejection must not surface as an unhandled rejection.
|
|
81
|
+
void announced.catch(() => { });
|
|
82
|
+
const endTracks = async (atLeastMs = 0) => {
|
|
83
|
+
closing = true;
|
|
84
|
+
for (const slot of tracks.values())
|
|
85
|
+
slot.writer.close();
|
|
86
|
+
// Chromium resets every stream still awaiting its acknowledgment when the session closes, so give the last
|
|
87
|
+
// groups up to one write deadline to settle; after that they may be lost.
|
|
88
|
+
await groups.drain(Math.max(drainMs, atLeastMs), connectionClosed);
|
|
89
|
+
};
|
|
90
|
+
session.announce(namespace);
|
|
91
|
+
return {
|
|
92
|
+
tracks,
|
|
93
|
+
announce: () => announce(),
|
|
94
|
+
disconnect(error, live = false) {
|
|
95
|
+
closing = true;
|
|
96
|
+
if (live)
|
|
97
|
+
lost = { error };
|
|
98
|
+
// Only a clean shutdown (no error at all) becomes CLOSED; a closure reason of `null` is preserved.
|
|
99
|
+
abandonAnnounce(error === undefined
|
|
100
|
+
? new RelayError('CLOSED', 'Relay publisher closed before its namespace was announced', 'connection')
|
|
101
|
+
: error);
|
|
102
|
+
// A namespace lost while the connection lives ends its tracks as `close()` would, failing what is in flight with
|
|
103
|
+
// `error` before the core ends the track; the transport goes on, and so do the delivery timeouts it still needs.
|
|
104
|
+
for (const slot of tracks.values()) {
|
|
105
|
+
if (live)
|
|
106
|
+
slot.end(error);
|
|
107
|
+
else
|
|
108
|
+
slot.disconnect(error);
|
|
109
|
+
}
|
|
110
|
+
// The relay withdrawing the namespace while the application's own close() drains it does not make that close a
|
|
111
|
+
// withdrawal: `closed` reports the close the application asked for.
|
|
112
|
+
resolveClosed(error === undefined || (live && closingByApplication) ? {} : { error });
|
|
113
|
+
},
|
|
114
|
+
end: endTracks,
|
|
115
|
+
get drainMs() {
|
|
116
|
+
return drainMs;
|
|
117
|
+
},
|
|
118
|
+
api: {
|
|
119
|
+
namespace,
|
|
120
|
+
announced,
|
|
121
|
+
closed,
|
|
122
|
+
registerTrack({ track, trackProperties, writeTimeoutMs = 10_000 }) {
|
|
123
|
+
// Arguments first, then connection state, then the registry.
|
|
124
|
+
const name = trackName(track);
|
|
125
|
+
const properties = trackPropertyPairs(trackProperties);
|
|
126
|
+
assertTimeoutMs('writeTimeoutMs', writeTimeoutMs);
|
|
127
|
+
assertPublished();
|
|
128
|
+
if (closing)
|
|
129
|
+
throw new RelayError('CLOSED', 'Relay publisher is closed', 'connection');
|
|
130
|
+
if (tracks.has(name))
|
|
131
|
+
throw new RangeError('Track name is already registered on this publisher connection');
|
|
132
|
+
const registered = session.registerTrack({
|
|
133
|
+
trackNamespace: namespace,
|
|
134
|
+
trackName: name,
|
|
135
|
+
trackProperties: properties,
|
|
136
|
+
});
|
|
137
|
+
const sendOptions = trackSendOptions(properties);
|
|
138
|
+
const slot = createWriteSlot({
|
|
139
|
+
openSubgroup: async (trackAlias, groupId) => reportingObjects(createSubgroupWriter(await session.openUniStream(trackAlias, sendOptions), {
|
|
140
|
+
trackAlias,
|
|
141
|
+
groupId,
|
|
142
|
+
hasProperties: true,
|
|
143
|
+
}), registered),
|
|
144
|
+
settlingGroups: groups,
|
|
145
|
+
namespaceSolicited: () => session.isSolicited(namespace),
|
|
146
|
+
assertOpen: assertPublished,
|
|
147
|
+
endTrack: () => registered.end(),
|
|
148
|
+
writeTimeoutMs,
|
|
149
|
+
trackTimeouts: publisherTimeouts(properties),
|
|
150
|
+
subscriberTimeouts: (trackAlias) => subscriptionTimeouts.get(trackAlias) ?? NO_DELIVERY_TIMEOUTS,
|
|
151
|
+
});
|
|
152
|
+
tracks.set(name, slot);
|
|
153
|
+
drainMs = Math.max(drainMs, writeTimeoutMs);
|
|
154
|
+
return slot.writer;
|
|
155
|
+
},
|
|
156
|
+
close() {
|
|
157
|
+
shutdown ??= (async () => {
|
|
158
|
+
if (ended)
|
|
159
|
+
return;
|
|
160
|
+
closingByApplication = true;
|
|
161
|
+
await endTracks();
|
|
162
|
+
abandonAnnounce(new RelayError('CLOSED', 'Relay publication closed before its namespace was announced', 'connection'));
|
|
163
|
+
session.withdraw(namespace);
|
|
164
|
+
resolveClosed({});
|
|
165
|
+
})();
|
|
166
|
+
return shutdown;
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
return {
|
|
56
172
|
callbacks: {
|
|
57
|
-
|
|
58
|
-
|
|
173
|
+
onAnnounced: ({ namespace }) => publications.get(key(namespace))?.announce(),
|
|
174
|
+
onAnnounceEnded: ({ namespace, error }) => onNamespaceEnded(namespace, error),
|
|
59
175
|
onSubscribe: ({ requestId, parameters }) => subscriptionTimeouts.set(requestId, subscriberTimeouts(parameters)),
|
|
60
176
|
onRequestUpdate: ({ requestId, parameters }) => {
|
|
61
177
|
const previous = subscriptionTimeouts.get(requestId);
|
|
@@ -63,72 +179,76 @@ export async function connectRelayPublisher(options) {
|
|
|
63
179
|
subscriptionTimeouts.set(requestId, subscriberTimeouts(parameters, previous));
|
|
64
180
|
},
|
|
65
181
|
onSubscribeEnd: ({ requestId }) => subscriptionTimeouts.delete(requestId),
|
|
66
|
-
onTrackBinding: ({ trackName, trackAlias }) => tracks.get(trackName)?.bind(trackAlias),
|
|
67
|
-
onAnnounceEnded: ({ error }) => callbacks.onClosed?.({
|
|
68
|
-
error: new RelayError('NAMESPACE_ENDED', 'Relay withdrew the namespace', 'connection', { cause: error }),
|
|
69
|
-
}),
|
|
182
|
+
onTrackBinding: ({ trackNamespace, trackName, trackAlias }) => publications.get(key(trackNamespace))?.tracks.get(trackName)?.bind(trackAlias),
|
|
70
183
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
184
|
+
bind(session, lifetime) {
|
|
185
|
+
bound = { session, assertOpen: lifetime.assertOpen, closed: lifetime.closed };
|
|
186
|
+
void lifetime.closed.then(({ error }) => {
|
|
187
|
+
ended = true;
|
|
188
|
+
for (const publication of publications.values())
|
|
189
|
+
publication.disconnect(error);
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
publish(namespace) {
|
|
193
|
+
if (!bound)
|
|
194
|
+
throw new Error('publish before the connection is up');
|
|
195
|
+
bound.assertOpen();
|
|
196
|
+
if (ended || shuttingDown)
|
|
197
|
+
throw new RelayError('CLOSED', 'Relay connection is closed', 'connection');
|
|
198
|
+
if (publications.has(key(namespace)))
|
|
199
|
+
throw new RangeError('Namespace is already published on this connection, including after its publication closed');
|
|
200
|
+
const publication = create(namespace, bound);
|
|
201
|
+
publications.set(key(namespace), publication);
|
|
202
|
+
return publication.api;
|
|
203
|
+
},
|
|
204
|
+
disconnect(namespace, error) {
|
|
205
|
+
const publication = publications.get(key(namespace));
|
|
206
|
+
if (!publication || ended)
|
|
207
|
+
return;
|
|
208
|
+
bound?.session.withdraw([...namespace]);
|
|
209
|
+
publication.disconnect(error, true);
|
|
210
|
+
},
|
|
211
|
+
async endAll() {
|
|
212
|
+
shuttingDown = true;
|
|
213
|
+
// The connection's groups get the largest deadline among all its tracks, as a publisher connection's do.
|
|
214
|
+
const all = [...publications.values()];
|
|
215
|
+
const drainMs = Math.max(0, ...all.map((publication) => publication.drainMs));
|
|
216
|
+
await Promise.all(all.map((publication) => publication.end(drainMs)));
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Open a dedicated Relay publisher connection. Subscribers use connectRelaySubscriber; `connectRelay` opens one
|
|
222
|
+
* connection that does both. A relay must solicit the namespace and subscribe upstream before data can flow.
|
|
223
|
+
*/
|
|
224
|
+
export async function connectRelayPublisher(options) {
|
|
225
|
+
// Arguments before anything else: an invalid namespace never reaches the token provider or the
|
|
226
|
+
// transport factory.
|
|
227
|
+
const namespace = namespaceFields(options.namespace);
|
|
228
|
+
let endConnection = () => { };
|
|
229
|
+
const host = createPublishHost((_namespace, error) => endConnection(error));
|
|
230
|
+
const lifetime = await openRelaySession(options, (transport, callbacks, setupOptions) => {
|
|
231
|
+
endConnection = (error) => callbacks.onClosed?.({
|
|
232
|
+
error: new RelayError('NAMESPACE_ENDED', 'Relay withdrew the namespace', 'connection', { cause: error }),
|
|
233
|
+
});
|
|
234
|
+
return createMoqtPublishSession(transport, {
|
|
235
|
+
implementationName: '@caprid/relay publisher',
|
|
236
|
+
setupOptions,
|
|
237
|
+
callbacks: { ...callbacks, ...host.callbacks },
|
|
238
|
+
});
|
|
84
239
|
});
|
|
240
|
+
host.bind(lifetime.session, lifetime);
|
|
241
|
+
const publication = host.publish(namespace);
|
|
242
|
+
let shutdown;
|
|
85
243
|
const closed = lifetime.transportClosed.then(() => lifetime.closed, () => lifetime.closed);
|
|
86
244
|
return {
|
|
87
|
-
announced,
|
|
245
|
+
announced: publication.announced,
|
|
88
246
|
closed,
|
|
89
247
|
expiresAt: lifetime.expiresAt === undefined ? undefined : new Date(lifetime.expiresAt.getTime()),
|
|
90
|
-
registerTrack(
|
|
91
|
-
// Arguments first, then connection state, then the registry.
|
|
92
|
-
const name = trackName(track);
|
|
93
|
-
const properties = trackPropertyPairs(trackProperties);
|
|
94
|
-
assertTimeoutMs('writeTimeoutMs', writeTimeoutMs);
|
|
95
|
-
lifetime.assertOpen();
|
|
96
|
-
if (closing)
|
|
97
|
-
throw new RelayError('CLOSED', 'Relay publisher is closed', 'connection');
|
|
98
|
-
if (tracks.has(name))
|
|
99
|
-
throw new RangeError('Track name is already registered on this publisher connection');
|
|
100
|
-
const registered = session.registerTrack({
|
|
101
|
-
trackNamespace: namespace,
|
|
102
|
-
trackName: name,
|
|
103
|
-
trackProperties: properties,
|
|
104
|
-
});
|
|
105
|
-
const sendOptions = trackSendOptions(properties);
|
|
106
|
-
const slot = createWriteSlot({
|
|
107
|
-
openSubgroup: async (trackAlias, groupId) => reportingObjects(createSubgroupWriter(await session.openUniStream(trackAlias, sendOptions), {
|
|
108
|
-
trackAlias,
|
|
109
|
-
groupId,
|
|
110
|
-
hasProperties: true,
|
|
111
|
-
}), registered),
|
|
112
|
-
settlingGroups,
|
|
113
|
-
namespaceSolicited: () => session.namespaceSolicited,
|
|
114
|
-
assertOpen: lifetime.assertOpen,
|
|
115
|
-
endTrack: () => registered.end(),
|
|
116
|
-
writeTimeoutMs,
|
|
117
|
-
trackTimeouts: publisherTimeouts(properties),
|
|
118
|
-
subscriberTimeouts: (trackAlias) => subscriptionTimeouts.get(trackAlias) ?? NO_DELIVERY_TIMEOUTS,
|
|
119
|
-
});
|
|
120
|
-
tracks.set(track, slot);
|
|
121
|
-
drainMs = Math.max(drainMs, writeTimeoutMs);
|
|
122
|
-
return slot.writer;
|
|
123
|
-
},
|
|
248
|
+
registerTrack: (options) => publication.registerTrack(options),
|
|
124
249
|
close() {
|
|
125
250
|
shutdown ??= (async () => {
|
|
126
|
-
|
|
127
|
-
for (const slot of tracks.values())
|
|
128
|
-
slot.writer.close();
|
|
129
|
-
// Chromium resets every stream still awaiting its acknowledgment when the session closes,
|
|
130
|
-
// so give the last groups up to one write deadline to settle; after that they may be lost.
|
|
131
|
-
await settlingGroups.drain(drainMs, lifetime.closed);
|
|
251
|
+
await host.endAll();
|
|
132
252
|
lifetime.close();
|
|
133
253
|
await closed;
|
|
134
254
|
})();
|
|
@@ -136,4 +256,5 @@ export async function connectRelayPublisher(options) {
|
|
|
136
256
|
},
|
|
137
257
|
};
|
|
138
258
|
}
|
|
259
|
+
export { createPublishHost };
|
|
139
260
|
//# sourceMappingURL=publish.js.map
|
package/dist/publish.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,GAMrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAA4B,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAEL,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAuB,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAkB,MAAM,iBAAiB,CAAC;AAElE;;;GAGG;AACH,SAAS,gBAAgB,CAAC,QAAwB,EAAE,KAAsB;IACxE,OAAO;QACL,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO;YAC/B,MAAM,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC5C,KAAK,CAAC,eAAe,CAAC,EAAE,K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AE,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC;QAC9D,KAAK;YACH,QAAQ,KAAK,CAAC,KAAK,IAAI,EAAE;gBACvB,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;gBACpB,QAAQ,CAAC,KAAK,EAAE,CAAC;gBACjB,MAAM,MAAM,CAAC;YACf,CAAC,CAAC,EAAE,CAAC;YACL,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAoB,CAAC"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { type DiscoveryIndex } from './discovery.js';
|
|
2
|
+
/**
|
|
3
|
+
* A root under the prefix: the namespace one field below it, publishing while a namespace at it or one field below it
|
|
4
|
+
* is announced. A supervised publisher announces its generations one field below its root; an unsupervised publisher
|
|
5
|
+
* announces the root itself (depth 1).
|
|
6
|
+
*/
|
|
7
|
+
export interface PublishingRoot {
|
|
8
|
+
/** The field one below the prefix, as the root's publisher chose it. */
|
|
9
|
+
readonly id: string;
|
|
10
|
+
/** The prefix followed by `id`. Want it with `generations: true` to follow the root's supervised publisher. */
|
|
11
|
+
readonly namespace: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
/** What `onChanged` receives: which roots were added and removed since the last call, and which are publishing now. */
|
|
14
|
+
export interface PublishingRootsChange {
|
|
15
|
+
/**
|
|
16
|
+
* Roots that started publishing. On the first call (`initial`), every root publishing when the view loaded, possibly
|
|
17
|
+
* none.
|
|
18
|
+
*/
|
|
19
|
+
readonly added: readonly PublishingRoot[];
|
|
20
|
+
/** Roots that stopped publishing. Empty on the first call. */
|
|
21
|
+
readonly removed: readonly PublishingRoot[];
|
|
22
|
+
/**
|
|
23
|
+
* Every root publishing after this change, by id, in the order the view first saw them. The same map as `present`.
|
|
24
|
+
*/
|
|
25
|
+
readonly present: ReadonlyMap<string, PublishingRoot>;
|
|
26
|
+
/** True on the first call only: the view has just loaded. A UI that announces arrivals skips this one. */
|
|
27
|
+
readonly initial: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** What a publishing-roots view follows. */
|
|
30
|
+
export interface PublishingRootsOptions {
|
|
31
|
+
/**
|
|
32
|
+
* The prefix whose roots to follow: each namespace one field below it is a root, and one field further is that
|
|
33
|
+
* root's generation. Same rules as a namespace, with room for the two fields under it. The subscriber's token must
|
|
34
|
+
* allow discovering it.
|
|
35
|
+
*/
|
|
36
|
+
prefix: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
/** The callbacks a publishing-roots view delivers to. Like `WantHandlers`, they must be synchronous. */
|
|
39
|
+
export interface PublishingRootsHandlers {
|
|
40
|
+
/**
|
|
41
|
+
* The view loaded, or roots were added or removed. The first call is the load and runs once, even for an empty
|
|
42
|
+
* prefix; every later call names at least one root in `added` or `removed`. A root whose last namespace is withdrawn
|
|
43
|
+
* is removed once it has had none for 100 ms, so a rotation whose withdrawal arrives just before the new generation's
|
|
44
|
+
* announce calls nothing. A root's generations changing, the relay repeating an announce, and the subscriber's
|
|
45
|
+
* reconnects and rotations call nothing. A reconnect, rotation or retry calls it once with the roots its new
|
|
46
|
+
* discovery adds, if there are any. A root the new discovery misses is removed in a later call, once the new
|
|
47
|
+
* discovery has shown it nothing for 100 ms.
|
|
48
|
+
*/
|
|
49
|
+
onChanged?(change: PublishingRootsChange): void;
|
|
50
|
+
/**
|
|
51
|
+
* A discovery failure no wait fixes: the relay refusing the request with a REQUEST_ERROR that does not invite a
|
|
52
|
+
* retry, such as NOT_SUPPORTED from a relay without namespace discovery. The view is closed. A prefix outside the
|
|
53
|
+
* token's grant is not one: moq-relay accepts the request and sends nothing, so the view loads empty and this is
|
|
54
|
+
* never called. An empty view with no error can therefore mean the token does not grant the prefix.
|
|
55
|
+
*/
|
|
56
|
+
onError?(error: unknown): void;
|
|
57
|
+
}
|
|
58
|
+
/** A live view of the roots publishing under a prefix. Create one with `SupervisedSubscriber.publishingRoots`. */
|
|
59
|
+
export interface PublishingRoots {
|
|
60
|
+
/**
|
|
61
|
+
* False until the prefix's first discovery has reported everything announced under it; then `present` is empty only
|
|
62
|
+
* when no root is publishing. Stays true across reconnects, while the last settled view is held.
|
|
63
|
+
*/
|
|
64
|
+
readonly loaded: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The roots publishing, by id: empty until loaded, and the last settled view while a reconnect's discovery loads. A
|
|
67
|
+
* root whose last namespace went stays until it is reported as removed. The same map until the next `onChanged`, so
|
|
68
|
+
* a UI can compare it by identity.
|
|
69
|
+
*/
|
|
70
|
+
readonly present: ReadonlyMap<string, PublishingRoot>;
|
|
71
|
+
/** Stop following the prefix. Idempotent; nothing is delivered after it, even when called from `onChanged`. */
|
|
72
|
+
close(): void;
|
|
73
|
+
}
|
|
74
|
+
export type Presence = Map<string, Set<string>>;
|
|
75
|
+
export declare function rootField(prefix: readonly string[], namespace: readonly string[]): {
|
|
76
|
+
id: string;
|
|
77
|
+
field: string;
|
|
78
|
+
} | undefined;
|
|
79
|
+
export declare function applyNamespace(presence: Presence, prefix: readonly string[], type: 'announced' | 'unannounced', namespace: readonly string[]): {
|
|
80
|
+
kind: 'added' | 'removed';
|
|
81
|
+
id: string;
|
|
82
|
+
} | undefined;
|
|
83
|
+
export declare function diffRoots(settled: ReadonlyMap<string, PublishingRoot>, loaded: Presence, prefix: readonly string[]): {
|
|
84
|
+
added: PublishingRoot[];
|
|
85
|
+
removed: PublishingRoot[];
|
|
86
|
+
};
|
|
87
|
+
export interface PublishingRootsConnection {
|
|
88
|
+
readonly discovery: DiscoveryIndex;
|
|
89
|
+
readonly signal: AbortSignal;
|
|
90
|
+
readonly retiring: AbortSignal;
|
|
91
|
+
}
|
|
92
|
+
export interface Source {
|
|
93
|
+
readonly connection: PublishingRootsConnection;
|
|
94
|
+
readonly presence: Presence;
|
|
95
|
+
}
|
|
96
|
+
type Settled = ReadonlyMap<string, PublishingRoot>;
|
|
97
|
+
type Leaving = ReadonlySet<string>;
|
|
98
|
+
export type PublishingRootsPhase = {
|
|
99
|
+
readonly kind: 'loading';
|
|
100
|
+
readonly candidate: Source | undefined;
|
|
101
|
+
readonly failures: number;
|
|
102
|
+
} | {
|
|
103
|
+
readonly kind: 'live';
|
|
104
|
+
readonly settled: Settled;
|
|
105
|
+
readonly leaving: Leaving;
|
|
106
|
+
readonly source: Source;
|
|
107
|
+
} | {
|
|
108
|
+
readonly kind: 'replacing';
|
|
109
|
+
readonly settled: Settled;
|
|
110
|
+
readonly leaving: Leaving;
|
|
111
|
+
readonly source: Source | undefined;
|
|
112
|
+
readonly candidate: Source | undefined;
|
|
113
|
+
readonly failures: number;
|
|
114
|
+
} | {
|
|
115
|
+
readonly kind: 'closed';
|
|
116
|
+
readonly settled: Settled | undefined;
|
|
117
|
+
};
|
|
118
|
+
export type PublishingRootsInput = {
|
|
119
|
+
readonly kind: 'connection';
|
|
120
|
+
readonly connection: PublishingRootsConnection;
|
|
121
|
+
} | {
|
|
122
|
+
readonly kind: 'retiring';
|
|
123
|
+
readonly connection: PublishingRootsConnection;
|
|
124
|
+
readonly next: PublishingRootsConnection | undefined;
|
|
125
|
+
} | {
|
|
126
|
+
readonly kind: 'namespace';
|
|
127
|
+
readonly source: Source;
|
|
128
|
+
readonly type: 'announced' | 'unannounced';
|
|
129
|
+
readonly namespace: readonly string[];
|
|
130
|
+
} | {
|
|
131
|
+
readonly kind: 'loaded';
|
|
132
|
+
readonly source: Source;
|
|
133
|
+
} | {
|
|
134
|
+
readonly kind: 'ended';
|
|
135
|
+
readonly source: Source;
|
|
136
|
+
readonly error: unknown;
|
|
137
|
+
} | {
|
|
138
|
+
readonly kind: 'leave-due';
|
|
139
|
+
readonly id: string;
|
|
140
|
+
readonly following: (source: Source) => boolean;
|
|
141
|
+
} | {
|
|
142
|
+
readonly kind: 'close';
|
|
143
|
+
};
|
|
144
|
+
export type PublishingRootsEffect = {
|
|
145
|
+
readonly kind: 'open';
|
|
146
|
+
readonly source: Source;
|
|
147
|
+
} | {
|
|
148
|
+
readonly kind: 'release';
|
|
149
|
+
readonly source: Source;
|
|
150
|
+
} | {
|
|
151
|
+
readonly kind: 'emit';
|
|
152
|
+
readonly change: PublishingRootsChange;
|
|
153
|
+
} | {
|
|
154
|
+
readonly kind: 'schedule-leave';
|
|
155
|
+
readonly id: string;
|
|
156
|
+
} | {
|
|
157
|
+
readonly kind: 'cancel-leave';
|
|
158
|
+
readonly id: string;
|
|
159
|
+
} | {
|
|
160
|
+
readonly kind: 'await-connection';
|
|
161
|
+
readonly after: PublishingRootsConnection;
|
|
162
|
+
} | {
|
|
163
|
+
readonly kind: 'retry';
|
|
164
|
+
readonly attempt: number;
|
|
165
|
+
} | {
|
|
166
|
+
readonly kind: 'error';
|
|
167
|
+
readonly error: unknown;
|
|
168
|
+
};
|
|
169
|
+
type Step = {
|
|
170
|
+
phase: PublishingRootsPhase;
|
|
171
|
+
effects: PublishingRootsEffect[];
|
|
172
|
+
};
|
|
173
|
+
export declare function transition(phase: PublishingRootsPhase, input: PublishingRootsInput, prefix: readonly string[]): Step;
|
|
174
|
+
export interface PublishingRootsDependencies {
|
|
175
|
+
liveConnection(scope: AbortSignal): Promise<PublishingRootsConnection | undefined>;
|
|
176
|
+
current(): PublishingRootsConnection | undefined;
|
|
177
|
+
/** Keep `connection` open through a rotation until the returned release runs. */
|
|
178
|
+
hold(connection: PublishingRootsConnection): () => void;
|
|
179
|
+
onClosed(): void;
|
|
180
|
+
/**
|
|
181
|
+
* Whether a namespace is the supervisor's own publishing: its announcement is never reported. The relay hides a
|
|
182
|
+
* connection's own announcements from it, but not those of the connection a rotation is replacing or bringing up.
|
|
183
|
+
* Withdrawals still count, so a root seen before the supervisor published it leaves when it is withdrawn.
|
|
184
|
+
*/
|
|
185
|
+
hides?(namespace: readonly string[]): boolean;
|
|
186
|
+
}
|
|
187
|
+
export declare function openPublishingRoots(deps: PublishingRootsDependencies, prefix: readonly string[], handlers: PublishingRootsHandlers): PublishingRoots;
|
|
188
|
+
export {};
|
|
189
|
+
//# sourceMappingURL=publishing-roots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