@caprid/relay 0.1.1 → 0.3.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 +68 -52
- package/dist/connect-session.d.ts +17 -15
- package/dist/connect-session.d.ts.map +1 -1
- package/dist/connect-session.js +71 -45
- package/dist/connect-session.js.map +1 -1
- package/dist/connect.d.ts +7 -0
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +2 -0
- package/dist/connect.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/media.d.ts +1 -0
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +1 -0
- package/dist/media.js.map +1 -1
- package/dist/publish.d.ts +1 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +19 -3
- package/dist/publish.js.map +1 -1
- package/dist/replaceable-track.d.ts +100 -0
- package/dist/replaceable-track.d.ts.map +1 -0
- package/dist/replaceable-track.js +218 -0
- package/dist/replaceable-track.js.map +1 -0
- package/dist/room-endpoint.d.ts +14 -2
- package/dist/room-endpoint.d.ts.map +1 -1
- package/dist/room-endpoint.js +30 -21
- package/dist/room-endpoint.js.map +1 -1
- package/dist/supervised-publisher.d.ts +2 -2
- package/dist/supervised-publisher.d.ts.map +1 -1
- package/dist/supervised-publisher.js +4 -1
- package/dist/supervised-publisher.js.map +1 -1
- package/dist/supervised-subscriber.d.ts +2 -1
- package/dist/supervised-subscriber.d.ts.map +1 -1
- package/dist/supervised-subscriber.js +4 -1
- package/dist/supervised-subscriber.js.map +1 -1
- package/package.json +7 -7
package/dist/media.d.ts
CHANGED
|
@@ -25,4 +25,5 @@ export { type CatalogService, type CatalogServiceOptions, createCatalogService,
|
|
|
25
25
|
export { createFrameReader, type FrameReader, type FrameReaderOptions, type FrameReaderSequencer, } from './frame-reader.js';
|
|
26
26
|
export { createFrameWriter, type Frame, type FrameGrouping, type FrameOutcome, type FrameOutcomeKind, type FrameWriter, type FrameWriterOptions, } from './frame-writer.js';
|
|
27
27
|
export { type MediaKind, type MediaTrackPropertiesOptions, mediaSubscribeParameters, mediaTrackProperties, } from './media-track-properties.js';
|
|
28
|
+
export { createReplaceableTrack, type ReplaceableTrack, type ReplaceableTrackCatalog, type ReplaceableTrackOptions, type TrackReplacement, } from './replaceable-track.js';
|
|
28
29
|
//# sourceMappingURL=media.d.ts.map
|
package/dist/media.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,SAAS,EACd,KAAK,2BAA2B,EAChC,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,SAAS,EACd,KAAK,2BAA2B,EAChC,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,EACtB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,GACtB,MAAM,wBAAwB,CAAC"}
|
package/dist/media.js
CHANGED
|
@@ -25,4 +25,5 @@ export { createCatalogService, createDocumentService, } from './document-service
|
|
|
25
25
|
export { createFrameReader, } from './frame-reader.js';
|
|
26
26
|
export { createFrameWriter, } from './frame-writer.js';
|
|
27
27
|
export { mediaSubscribeParameters, mediaTrackProperties, } from './media-track-properties.js';
|
|
28
|
+
export { createReplaceableTrack, } from './replaceable-track.js';
|
|
28
29
|
//# sourceMappingURL=media.js.map
|
package/dist/media.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.js","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAGL,oBAAoB,EACpB,qBAAqB,GAItB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,GAIlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,GAOlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGL,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAGL,oBAAoB,EACpB,qBAAqB,GAItB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,GAIlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,GAOlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGL,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,GAKvB,MAAM,wBAAwB,CAAC"}
|
package/dist/publish.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export interface RegisterTrackOptions {
|
|
|
34
34
|
* add, drop, or rewrite properties before delivery to subscribers. With moq-relay 0.17.0 every
|
|
35
35
|
* SUBSCRIBE_OK carries the relay's track properties, not these, and a Timescale (`0x08`) here is
|
|
36
36
|
* what keeps supplied object Timestamps unchanged. See "Relay property handling" in
|
|
37
|
-
* spec/behavior.md. The list rides in every SUBSCRIBE_OK, so it must encode to at most 65525
|
|
37
|
+
* spec/behavior.md. The list rides in every SUBSCRIBE_OK (and TRACK_STATUS_OK), so it must encode to at most 65525
|
|
38
38
|
* bytes, hold at most 64 pairs (the relay's limit) and keep `0x0E` at most 255 and `0x22` at 1
|
|
39
39
|
* or 2 (draft-22); otherwise the relay would refuse every subscriber, so `registerTrack` throws a
|
|
40
40
|
* RangeError instead.
|
package/dist/publish.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EAGlB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAmB,KAAK,mBAAmB,EAAoB,MAAM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EAAE,SAAS,eAAe,EAAE,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvH;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,gBAAgB,CAAC;IAC/D;;;;;;;;;OASG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,4FAA4F;IAC5F,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;QACvB,4EAA4E;QAC5E,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC,CAAC;IACH;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,IAAI,GAAG,SAAS,CAAC;IACrC;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,cAAc,CAAC,CAuH1G"}
|
package/dist/publish.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMoqtPublishSession, createSubgroupWriter } from '@caprid/moq-core';
|
|
1
|
+
import { createMoqtPublishSession, createSubgroupWriter, } from '@caprid/moq-core';
|
|
2
2
|
import { assertTimeoutMs, openRelaySession } from './connect-session.js';
|
|
3
3
|
import { NO_DELIVERY_TIMEOUTS, publisherTimeouts, subscriberTimeouts, } from './delivery-timeouts.js';
|
|
4
4
|
import { RelayError } from './errors.js';
|
|
@@ -6,6 +6,22 @@ import { trackSendOptions } from './send-order.js';
|
|
|
6
6
|
import { createSettlingGroups } from './settling-groups.js';
|
|
7
7
|
import { namespaceFields, trackName, trackPropertyPairs } from './validation.js';
|
|
8
8
|
import { createWriteSlot } from './write-slot.js';
|
|
9
|
+
/**
|
|
10
|
+
* A subgroup writer that tells the core of every object the transport took, so the core answers the
|
|
11
|
+
* relay's TRACK_STATUS with the track's largest object (draft-22 §9.20.17).
|
|
12
|
+
*/
|
|
13
|
+
function reportingObjects(subgroup, track) {
|
|
14
|
+
return {
|
|
15
|
+
groupId: subgroup.groupId,
|
|
16
|
+
async writeObject(object, options) {
|
|
17
|
+
await subgroup.writeObject(object, options);
|
|
18
|
+
track.objectPublished({ group: subgroup.groupId, object: object.objectId });
|
|
19
|
+
},
|
|
20
|
+
fin: () => subgroup.fin(),
|
|
21
|
+
handOverFin: () => subgroup.handOverFin(),
|
|
22
|
+
abort: (reason) => subgroup.abort(reason),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
9
25
|
/**
|
|
10
26
|
* Open a dedicated Relay publisher connection. Subscribers use connectRelaySubscriber; this
|
|
11
27
|
* initial publishing API does not share their physical transport. A relay must solicit the
|
|
@@ -88,11 +104,11 @@ export async function connectRelayPublisher(options) {
|
|
|
88
104
|
});
|
|
89
105
|
const sendOptions = trackSendOptions(properties);
|
|
90
106
|
const slot = createWriteSlot({
|
|
91
|
-
openSubgroup: async (trackAlias, groupId) => createSubgroupWriter(await session.openUniStream(trackAlias, sendOptions), {
|
|
107
|
+
openSubgroup: async (trackAlias, groupId) => reportingObjects(createSubgroupWriter(await session.openUniStream(trackAlias, sendOptions), {
|
|
92
108
|
trackAlias,
|
|
93
109
|
groupId,
|
|
94
110
|
hasProperties: true,
|
|
95
|
-
}),
|
|
111
|
+
}), registered),
|
|
96
112
|
settlingGroups,
|
|
97
113
|
namespaceSolicited: () => session.namespaceSolicited,
|
|
98
114
|
assertOpen: lifetime.assertOpen,
|
package/dist/publish.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,GAIrB,MAAM,k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AO,CAAC,kBAAkB;gBACpD,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,QAAQ,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE;gBAChC,cAAc;gBACd,aAAa,EAAE,iBAAiB,CAAC,UAAU,CAAC;gBAC5C,kBAAkB,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,oBAAoB,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,oBAAoB;aACjG,CAAC,CAAC;YACH,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACxB,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;YAC5C,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;QACD,KAAK;YACH,QAAQ,KAAK,CAAC,KAAK,IAAI,EAAE;gBACvB,OAAO,GAAG,IAAI,CAAC;gBACf,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE;oBAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBACxD,0FAA0F;gBAC1F,2FAA2F;gBAC3F,MAAM,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;gBACrD,QAAQ,CAAC,KAAK,EAAE,CAAC;gBACjB,MAAM,MAAM,CAAC;YACf,CAAC,CAAC,EAAE,CAAC;YACL,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type Frame, type FrameOutcome, type FrameWriterOptions } from './frame-writer.js';
|
|
2
|
+
import type { PublishProperty, RelayPublisher } from './publish.js';
|
|
3
|
+
/** Where a {@link ReplaceableTrack} lists its current track: the broadcast's catalog. */
|
|
4
|
+
export interface ReplaceableTrackCatalog {
|
|
5
|
+
/** The service that serves the catalog: a `DocumentService` qualifies. */
|
|
6
|
+
service: {
|
|
7
|
+
/** Replace the catalog document, and send it while the relay is subscribed. */
|
|
8
|
+
update(document: ArrayBufferView): void;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The catalog document that lists `track` as the replaceable track, with the broadcast's other tracks: for MSF,
|
|
12
|
+
* `buildMsfCatalog` with that name. Called at creation and at each replacement.
|
|
13
|
+
*/
|
|
14
|
+
build(track: string): ArrayBufferView;
|
|
15
|
+
}
|
|
16
|
+
/** Options for {@link createReplaceableTrack}. */
|
|
17
|
+
export interface ReplaceableTrackOptions<F extends Frame = Frame> {
|
|
18
|
+
/** The first track's name. */
|
|
19
|
+
track: string;
|
|
20
|
+
/**
|
|
21
|
+
* The name of the track that replacement attempt number `replacement` (1 for the first) registers. Names are unique
|
|
22
|
+
* per publisher connection, including after a track closes, so each must differ from every name used before; an
|
|
23
|
+
* attempt that fails uses its name up, and the next asks for the next. Default `${track}-${replacement + 1}`:
|
|
24
|
+
* `audio-2`, `audio-3`, and so on.
|
|
25
|
+
*/
|
|
26
|
+
name?: (replacement: number) => string;
|
|
27
|
+
/** Every track's properties, as `registerTrack` takes them. */
|
|
28
|
+
trackProperties?: readonly PublishProperty[];
|
|
29
|
+
/** Every track's write timeout, as `registerTrack` takes it. */
|
|
30
|
+
writeTimeoutMs?: number;
|
|
31
|
+
/** Every track's frame writer options. Default `{ grouping: 'frame' }`, the mapping for audio. */
|
|
32
|
+
writer?: FrameWriterOptions<F>;
|
|
33
|
+
/** The catalog to list the current track in. */
|
|
34
|
+
catalog: ReplaceableTrackCatalog;
|
|
35
|
+
/**
|
|
36
|
+
* How long frames written to a replacement wait for its first relay subscription, in milliseconds. A listener
|
|
37
|
+
* subscribes to a replacement only once the new catalog has reached it, about a round trip, and a frame writer
|
|
38
|
+
* skips what it is handed before then: the first words of the new reply. The frames wait, in order, and go out once
|
|
39
|
+
* the relay subscribes; any still waiting when this runs out go to the writer, which skips them. 0 waits for
|
|
40
|
+
* nothing. Default 2000.
|
|
41
|
+
*/
|
|
42
|
+
demandWaitMs?: number;
|
|
43
|
+
}
|
|
44
|
+
/** What {@link ReplaceableTrack.replace} did. */
|
|
45
|
+
export interface TrackReplacement {
|
|
46
|
+
/** The track replaced, now closed. */
|
|
47
|
+
from: string;
|
|
48
|
+
/** The new track, listed in the catalog in its place. */
|
|
49
|
+
to: string;
|
|
50
|
+
/** How many times the track has been replaced, this time included: 1 for the first replacement. */
|
|
51
|
+
replacements: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A track that the publisher can replace mid-stream, for barge-in: a voice agent talked over replaces its reply
|
|
55
|
+
* track, and listeners drop the old reply's audio and play the new track. Create one with
|
|
56
|
+
* {@link createReplaceableTrack}.
|
|
57
|
+
*/
|
|
58
|
+
export interface ReplaceableTrack<F extends Frame = Frame> {
|
|
59
|
+
/** The current track's name. */
|
|
60
|
+
readonly track: string;
|
|
61
|
+
/** How many times the track has been replaced: 0 while the first track plays. */
|
|
62
|
+
readonly replacements: number;
|
|
63
|
+
/**
|
|
64
|
+
* Send one frame on the current track and say what happened, as `FrameWriter.write` does. A frame written to a
|
|
65
|
+
* replacement before the relay has subscribed to it waits (`demandWaitMs`). A frame of a track that is replaced
|
|
66
|
+
* before it went out is `'dropped'`.
|
|
67
|
+
*/
|
|
68
|
+
write(frame: F): Promise<FrameOutcome>;
|
|
69
|
+
/**
|
|
70
|
+
* Replace the track: register the next track, list it in the catalog in the current track's place, then drop
|
|
71
|
+
* what the current track has not sent and close it. Resolves once the old track is closed. Frames written from the
|
|
72
|
+
* call on go to the new track.
|
|
73
|
+
*/
|
|
74
|
+
replace(): Promise<TrackReplacement>;
|
|
75
|
+
/** Drop what has not been sent and close the current track. Idempotent; `write` and `replace` reject after it. */
|
|
76
|
+
close(): Promise<void>;
|
|
77
|
+
/** True once {@link close} ran. */
|
|
78
|
+
readonly closed: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Publish a track that can be replaced by a new one, listed in the catalog in its place (spec/media-layer.md, "Track
|
|
82
|
+
* replacement"). msf-01 §5.3 makes a changed track a new name; a listener that sees the catalog list a new track in
|
|
83
|
+
* place of the one it plays (`@caprid/moq-media`'s `findReplacementTrack`) drops the old track's audio and plays the
|
|
84
|
+
* new one.
|
|
85
|
+
*
|
|
86
|
+
* ```ts
|
|
87
|
+
* const catalog = createDocumentService(publisher.registerTrack({ track: CATALOG_TRACK }));
|
|
88
|
+
* void catalog.serve();
|
|
89
|
+
* const reply = createReplaceableTrack(publisher, {
|
|
90
|
+
* track: AUDIO_TRACK,
|
|
91
|
+
* trackProperties: locTrackProperties(),
|
|
92
|
+
* catalog: { service: catalog, build: (name) => buildMsfCatalog({ namespace, media: [{ role: 'audio', name }] }) },
|
|
93
|
+
* });
|
|
94
|
+
* void reply.write(frame);
|
|
95
|
+
* // Talked over: the reply so far is dropped, and the next one goes out on a new track.
|
|
96
|
+
* await reply.replace();
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function createReplaceableTrack<F extends Frame = Frame>(publisher: Pick<RelayPublisher, 'registerTrack'>, options: ReplaceableTrackOptions<F>): ReplaceableTrack<F>;
|
|
100
|
+
//# sourceMappingURL=replaceable-track.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replaceable-track.d.ts","sourceRoot":"","sources":["../src/replaceable-track.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,EACV,KAAK,YAAY,EAEjB,KAAK,kBAAkB,EACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAoB,MAAM,cAAc,CAAC;AAEtF,yFAAyF;AACzF,MAAM,WAAW,uBAAuB;IACtC,0EAA0E;IAC1E,OAAO,EAAE;QACP,+EAA+E;QAC/E,MAAM,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;KACzC,CAAC;IACF;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,CAAC;CACvC;A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KAAK,EAC5D,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,EAChD,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAClC,gBAAgB,CAAC,CAAC,CAAC,CA0LrB"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { createFrameWriter, } from './frame-writer.js';
|
|
2
|
+
const dropped = { kind: 'dropped' };
|
|
3
|
+
/**
|
|
4
|
+
* Publish a track that can be replaced by a new one, listed in the catalog in its place (spec/media-layer.md, "Track
|
|
5
|
+
* replacement"). msf-01 §5.3 makes a changed track a new name; a listener that sees the catalog list a new track in
|
|
6
|
+
* place of the one it plays (`@caprid/moq-media`'s `findReplacementTrack`) drops the old track's audio and plays the
|
|
7
|
+
* new one.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const catalog = createDocumentService(publisher.registerTrack({ track: CATALOG_TRACK }));
|
|
11
|
+
* void catalog.serve();
|
|
12
|
+
* const reply = createReplaceableTrack(publisher, {
|
|
13
|
+
* track: AUDIO_TRACK,
|
|
14
|
+
* trackProperties: locTrackProperties(),
|
|
15
|
+
* catalog: { service: catalog, build: (name) => buildMsfCatalog({ namespace, media: [{ role: 'audio', name }] }) },
|
|
16
|
+
* });
|
|
17
|
+
* void reply.write(frame);
|
|
18
|
+
* // Talked over: the reply so far is dropped, and the next one goes out on a new track.
|
|
19
|
+
* await reply.replace();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function createReplaceableTrack(publisher, options) {
|
|
23
|
+
if (typeof options !== 'object' || options === null)
|
|
24
|
+
throw new TypeError('options must be an object');
|
|
25
|
+
const { track: first, catalog } = options;
|
|
26
|
+
if (typeof first !== 'string' || first.length === 0)
|
|
27
|
+
throw new TypeError('track must be a non-empty string');
|
|
28
|
+
const nameOf = options.name ?? ((replacement) => `${first}-${replacement + 1}`);
|
|
29
|
+
if (typeof nameOf !== 'function')
|
|
30
|
+
throw new TypeError('name must be a function');
|
|
31
|
+
if (typeof catalog !== 'object' ||
|
|
32
|
+
catalog === null ||
|
|
33
|
+
typeof catalog.build !== 'function' ||
|
|
34
|
+
typeof catalog.service?.update !== 'function') {
|
|
35
|
+
throw new TypeError('catalog must have a service with update() and a build function');
|
|
36
|
+
}
|
|
37
|
+
const demandWaitMs = options.demandWaitMs ?? 2000;
|
|
38
|
+
if (typeof demandWaitMs !== 'number' || !(demandWaitMs >= 0 && demandWaitMs <= 2147483647))
|
|
39
|
+
throw new RangeError('demandWaitMs must be from 0 to 2147483647');
|
|
40
|
+
const writerOptions = { grouping: 'frame', ...options.writer };
|
|
41
|
+
let closed = false;
|
|
42
|
+
let closing;
|
|
43
|
+
// Old tracks still closing, each settled whatever its outcome, so close() can wait for every one.
|
|
44
|
+
const retiring = new Set();
|
|
45
|
+
// Names asked for so far: a failed attempt uses its name up, since the publisher may have taken it.
|
|
46
|
+
let attempts = 0;
|
|
47
|
+
const register = (name, replacements, wait) => {
|
|
48
|
+
const track = publisher.registerTrack({
|
|
49
|
+
track: name,
|
|
50
|
+
...(options.trackProperties ? { trackProperties: options.trackProperties } : {}),
|
|
51
|
+
...(options.writeTimeoutMs !== undefined ? { writeTimeoutMs: options.writeTimeoutMs } : {}),
|
|
52
|
+
});
|
|
53
|
+
let writer;
|
|
54
|
+
try {
|
|
55
|
+
writer = createFrameWriter(track, writerOptions);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
track.close();
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
const current = {
|
|
62
|
+
name,
|
|
63
|
+
replacements,
|
|
64
|
+
track,
|
|
65
|
+
writer,
|
|
66
|
+
waiting: wait && demandWaitMs > 0 && !track.hasDemand ? [] : undefined,
|
|
67
|
+
stopWaiting: () => { },
|
|
68
|
+
pumping: false,
|
|
69
|
+
retired: false,
|
|
70
|
+
};
|
|
71
|
+
if (current.waiting)
|
|
72
|
+
watchDemand(current);
|
|
73
|
+
return current;
|
|
74
|
+
};
|
|
75
|
+
// Release the waiting frames at the relay's first subscription, or when the wait runs out.
|
|
76
|
+
const watchDemand = (current) => {
|
|
77
|
+
const changes = current.track.demandChanges();
|
|
78
|
+
let timer;
|
|
79
|
+
let done = false;
|
|
80
|
+
const release = () => {
|
|
81
|
+
if (done)
|
|
82
|
+
return;
|
|
83
|
+
done = true;
|
|
84
|
+
if (timer !== undefined)
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
void changes.return?.();
|
|
87
|
+
void pump(current);
|
|
88
|
+
};
|
|
89
|
+
current.stopWaiting = () => {
|
|
90
|
+
done = true;
|
|
91
|
+
if (timer !== undefined)
|
|
92
|
+
clearTimeout(timer);
|
|
93
|
+
void changes.return?.();
|
|
94
|
+
};
|
|
95
|
+
timer = setTimeout(release, demandWaitMs);
|
|
96
|
+
void (async () => {
|
|
97
|
+
try {
|
|
98
|
+
for await (const demand of changes) {
|
|
99
|
+
if (done)
|
|
100
|
+
return;
|
|
101
|
+
if (demand)
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// The track ended: the writer reports it for each frame.
|
|
107
|
+
}
|
|
108
|
+
release();
|
|
109
|
+
})();
|
|
110
|
+
};
|
|
111
|
+
// Hand the waiting frames to the writer one at a time, in order, so its backlog never overflows; frames written
|
|
112
|
+
// meanwhile join the end. Then later frames go straight to the writer.
|
|
113
|
+
const pump = async (current) => {
|
|
114
|
+
if (current.pumping)
|
|
115
|
+
return;
|
|
116
|
+
current.pumping = true;
|
|
117
|
+
for (;;) {
|
|
118
|
+
const next = current.waiting?.shift();
|
|
119
|
+
if (!next)
|
|
120
|
+
break;
|
|
121
|
+
if (current.retired) {
|
|
122
|
+
next.resolve(dropped);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
next.resolve(await current.writer.write(next.frame));
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
next.reject(error);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
current.waiting = undefined;
|
|
133
|
+
current.pumping = false;
|
|
134
|
+
};
|
|
135
|
+
const retire = async (old) => {
|
|
136
|
+
old.retired = true;
|
|
137
|
+
old.stopWaiting();
|
|
138
|
+
for (const waiting of old.waiting?.splice(0) ?? [])
|
|
139
|
+
waiting.resolve(dropped);
|
|
140
|
+
try {
|
|
141
|
+
await old.writer.close();
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
old.track.close();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
let current = register(first, 0, false);
|
|
148
|
+
try {
|
|
149
|
+
catalog.service.update(catalog.build(first));
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
current.track.close();
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
const closedError = () => new Error('The replaceable track is closed');
|
|
156
|
+
return {
|
|
157
|
+
get track() {
|
|
158
|
+
return current.name;
|
|
159
|
+
},
|
|
160
|
+
get replacements() {
|
|
161
|
+
return current.replacements;
|
|
162
|
+
},
|
|
163
|
+
get closed() {
|
|
164
|
+
return closed;
|
|
165
|
+
},
|
|
166
|
+
write(frame) {
|
|
167
|
+
if (closed)
|
|
168
|
+
return Promise.reject(closedError());
|
|
169
|
+
const target = current;
|
|
170
|
+
if (target.waiting) {
|
|
171
|
+
return new Promise((resolve, reject) => {
|
|
172
|
+
target.waiting.push({ frame, resolve, reject });
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return target.writer.write(frame);
|
|
176
|
+
},
|
|
177
|
+
replace() {
|
|
178
|
+
if (closed)
|
|
179
|
+
return Promise.reject(closedError());
|
|
180
|
+
const old = current;
|
|
181
|
+
const replacements = old.replacements + 1;
|
|
182
|
+
const name = nameOf(++attempts);
|
|
183
|
+
if (typeof name !== 'string' || name.length === 0)
|
|
184
|
+
return Promise.reject(new TypeError('name() must return a non-empty string'));
|
|
185
|
+
let next;
|
|
186
|
+
try {
|
|
187
|
+
next = register(name, replacements, true);
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
return Promise.reject(error);
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
catalog.service.update(catalog.build(name));
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
next.stopWaiting();
|
|
197
|
+
next.track.close();
|
|
198
|
+
return Promise.reject(error);
|
|
199
|
+
}
|
|
200
|
+
current = next;
|
|
201
|
+
const done = retire(old).then(() => ({ from: old.name, to: name, replacements }));
|
|
202
|
+
const settled = done.then(() => { }, () => { });
|
|
203
|
+
retiring.add(settled);
|
|
204
|
+
void settled.then(() => retiring.delete(settled));
|
|
205
|
+
return done;
|
|
206
|
+
},
|
|
207
|
+
close() {
|
|
208
|
+
// The current track retires at once, so nothing waiting on it goes out; every old track still closing is waited
|
|
209
|
+
// for too. A second call shares the first's promise.
|
|
210
|
+
closing ??= (async () => {
|
|
211
|
+
closed = true;
|
|
212
|
+
await Promise.allSettled([retire(current), ...retiring]);
|
|
213
|
+
})();
|
|
214
|
+
return closing;
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=replaceable-track.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replaceable-track.js","sourceRoot":"","sources":["../src/replaceable-track.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAKlB,MAAM,mBAAmB,CAAC;AAwG3B,MAAM,OAAO,GAAiB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,sBAAsB,CACpC,SAAgD,EAChD,OAAmC;IAEnC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;QAAE,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;IACtG,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,CAA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9C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,WAAW,EAAE,CAAC;gBACnB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;gBACnB,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,GAAG,IAAI,CAAC;YACf,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;YAClF,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CACvB,GAAG,EAAE,GAAE,CAAC,EACR,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;YACF,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACtB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK;YACH,gHAAgH;YAChH,qDAAqD;YACrD,OAAO,KAAK,CAAC,KAAK,IAAI,EAAE;gBACtB,MAAM,GAAG,IAAI,CAAC;gBACd,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;YAC3D,CAAC,CAAC,EAAE,CAAC;YACL,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/room-endpoint.d.ts
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
/** The hosted Relay endpoint, pinned in spec/protocol.json as `relay.defaultEndpoint`. */
|
|
2
|
+
export declare const DEFAULT_ENDPOINT = "https://relay.mux.global";
|
|
3
|
+
/**
|
|
4
|
+
* Check an endpoint by the Endpoint rule in spec/behavior.md and return it parsed. Not a string, or
|
|
5
|
+
* not a URL at all (including an https URL with no host), is a TypeError: the wrong shape. A URL
|
|
6
|
+
* that parses but is not one Relay accepts is a RangeError: a disallowed value.
|
|
7
|
+
*/
|
|
8
|
+
export declare function endpointUrl(endpoint: unknown): URL;
|
|
1
9
|
/**
|
|
2
10
|
* Root an endpoint at a room. The result is the endpoint with each room field appended to its
|
|
3
11
|
* path, after any path it has and without its trailing slashes, and with its query kept, a `jwt`
|
|
4
|
-
* parameter included. A connection to it names namespaces relative to the room
|
|
12
|
+
* parameter included. A connection to it names namespaces relative to the room. Without an
|
|
13
|
+
* endpoint it roots {@link DEFAULT_ENDPOINT}:
|
|
5
14
|
*
|
|
6
15
|
* ```ts
|
|
7
|
-
* roomEndpoint(
|
|
16
|
+
* roomEndpoint(['acme', 'rooms', '42']);
|
|
8
17
|
* // 'https://relay.mux.global/acme/rooms/42'
|
|
18
|
+
* roomEndpoint('https://relay.example', ['acme', 'rooms', '42']);
|
|
19
|
+
* // 'https://relay.example/acme/rooms/42'
|
|
9
20
|
* ```
|
|
10
21
|
*
|
|
11
22
|
* The endpoint follows the connect calls' rules and the room the namespace rules. Nothing is
|
|
@@ -17,5 +28,6 @@
|
|
|
17
28
|
* @throws {RangeError} An endpoint that is not `https`, has a fragment or userinfo, or an empty
|
|
18
29
|
* `jwt`; a room of more than 32 fields; a room field with any other character, or `.` or `..`.
|
|
19
30
|
*/
|
|
31
|
+
export declare function roomEndpoint(room: readonly string[]): string;
|
|
20
32
|
export declare function roomEndpoint(endpoint: string, room: readonly string[]): string;
|
|
21
33
|
//# sourceMappingURL=room-endpoint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-endpoint.d.ts","sourceRoot":"","sources":["../src/room-endpoint.ts"],"names":[],"mappings":"AAeA
|
|
1
|
+
{"version":3,"file":"room-endpoint.d.ts","sourceRoot":"","sources":["../src/room-endpoint.ts"],"names":[],"mappings":"AAeA,0FAA0F;AAC1F,eAAO,MAAM,gBAAgB,6BAA6B,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,GAAG,CAiBlD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;AAC9D,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC"}
|
package/dist/room-endpoint.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* ("Room-rooted endpoints" in spec/behavior.md). Pure: it builds
|
|
2
|
+
* Relay endpoints: the Endpoint rule every connect call checks, and the room-rooted endpoint for a room, the endpoint
|
|
3
|
+
* with the room's fields appended to its path ("Room-rooted endpoints" in spec/behavior.md). Pure: it builds strings
|
|
4
|
+
* and connects nothing.
|
|
4
5
|
*/
|
|
5
|
-
import { endpointUrl } from './connect-session.js';
|
|
6
6
|
import { namespaceFields } from './validation.js';
|
|
7
7
|
/**
|
|
8
8
|
* The characters a room field may hold: what a URL path carries unchanged in every parser and
|
|
@@ -11,26 +11,35 @@ import { namespaceFields } from './validation.js';
|
|
|
11
11
|
* "Endpoint paths").
|
|
12
12
|
*/
|
|
13
13
|
const ROOM_FIELD = /^[A-Za-z0-9\-._~!$&'()+,;=:@]+$/;
|
|
14
|
+
/** The hosted Relay endpoint, pinned in spec/protocol.json as `relay.defaultEndpoint`. */
|
|
15
|
+
export const DEFAULT_ENDPOINT = 'https://relay.mux.global';
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* ```ts
|
|
20
|
-
* roomEndpoint('https://relay.mux.global', ['acme', 'rooms', '42']);
|
|
21
|
-
* // 'https://relay.mux.global/acme/rooms/42'
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* The endpoint follows the connect calls' rules and the room the namespace rules. Nothing is
|
|
25
|
-
* percent-encoded: a room field holds only `A`–`Z`, `a`–`z`, `0`–`9` and `-._~!$&'()+,;=:@`, and is
|
|
26
|
-
* not `.` or `..`. A namespace with any other field is reached from the bare host instead.
|
|
27
|
-
*
|
|
28
|
-
* @throws {TypeError} An endpoint that is not an absolute URL string, or a room that is not a
|
|
29
|
-
* sequence of non-empty string fields.
|
|
30
|
-
* @throws {RangeError} An endpoint that is not `https`, has a fragment or userinfo, or an empty
|
|
31
|
-
* `jwt`; a room of more than 32 fields; a room field with any other character, or `.` or `..`.
|
|
17
|
+
* Check an endpoint by the Endpoint rule in spec/behavior.md and return it parsed. Not a string, or
|
|
18
|
+
* not a URL at all (including an https URL with no host), is a TypeError: the wrong shape. A URL
|
|
19
|
+
* that parses but is not one Relay accepts is a RangeError: a disallowed value.
|
|
32
20
|
*/
|
|
33
|
-
export function
|
|
21
|
+
export function endpointUrl(endpoint) {
|
|
22
|
+
if (typeof endpoint !== 'string')
|
|
23
|
+
throw new TypeError('Relay endpoints must be a URL string');
|
|
24
|
+
let url;
|
|
25
|
+
try {
|
|
26
|
+
url = new URL(endpoint);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new TypeError('Relay endpoints must be a valid absolute URL', { cause: error });
|
|
30
|
+
}
|
|
31
|
+
if (url.protocol !== 'https:')
|
|
32
|
+
throw new RangeError('Relay endpoints must use HTTPS');
|
|
33
|
+
if (url.hash || url.username || url.password)
|
|
34
|
+
throw new RangeError('Relay endpoints cannot contain fragments or userinfo');
|
|
35
|
+
// A present jwt wins over getToken, so an empty one would connect with no credential at all.
|
|
36
|
+
if (url.searchParams.getAll('jwt').some((value) => value.length === 0))
|
|
37
|
+
throw new RangeError('Relay endpoint has an empty jwt query parameter; put a token in it, or remove it and supply getToken');
|
|
38
|
+
return url;
|
|
39
|
+
}
|
|
40
|
+
export function roomEndpoint(...args) {
|
|
41
|
+
// One argument is the room alone; two are the endpoint and the room, as before the default.
|
|
42
|
+
const [endpoint, room] = args.length === 1 ? [DEFAULT_ENDPOINT, args[0]] : args;
|
|
34
43
|
const url = endpointUrl(endpoint);
|
|
35
44
|
const fields = namespaceFields(room);
|
|
36
45
|
fields.forEach((field, index) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-endpoint.js","sourceRoot":"","sources":["../src/room-endpoint.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"room-endpoint.js","sourceRoot":"","sources":["../src/room-endpoint.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,UAAU,GAAG,iCAAiC,CAAC;AAErD,0FAA0F;AAC1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAE3D;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,QAAiB;IAC3C,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;IAC9F,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,SAAS,CAAC,8CAA8C,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACxF,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ;QAAE,MAAM,IAAI,UAAU,CAAC,gCAAgC,CAAC,CAAC;IACtF,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ;QAC1C,MAAM,IAAI,UAAU,CAAC,sDAAsD,CAAC,CAAC;IAC/E,6FAA6F;IAC7F,IAAI,GAAG,CAAC,YAAY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generation is up fails at once with
|
|
6
6
|
* `RECONNECTING`. See spec/behavior.md, "Supervised connections".
|
|
7
7
|
*/
|
|
8
|
-
import type { ConnectRelayOptions } from './connect-session.js';
|
|
8
|
+
import type { ConnectRelayOptions, RelaySessionHooks } from './connect-session.js';
|
|
9
9
|
import { type ConnectRelayPublisherOptions, type RegisterTrackOptions, type RelayPublisher, type RelayTrackWriter } from './publish.js';
|
|
10
10
|
import { type SupervisedStatus, type SupervisionBackoff } from './supervision.js';
|
|
11
11
|
/** Options for `connectSupervisedPublisher`: the shared connection options, the root namespace and the policy. */
|
|
@@ -81,7 +81,7 @@ export interface SupervisedPublisher {
|
|
|
81
81
|
*/
|
|
82
82
|
export declare function connectSupervisedPublisher(options: ConnectSupervisedPublisherOptions): Promise<SupervisedPublisher>;
|
|
83
83
|
/** How a supervisor opens one generation's connection. */
|
|
84
|
-
export type ConnectPublisher = (options: ConnectRelayPublisherOptions) => Promise<RelayPublisher>;
|
|
84
|
+
export type ConnectPublisher = (options: ConnectRelayPublisherOptions & RelaySessionHooks) => Promise<RelayPublisher>;
|
|
85
85
|
/**
|
|
86
86
|
* Open a supervised publisher with `connect` (`connectRelayPublisher` in the browser entry point, the Node one in
|
|
87
87
|
* `@caprid/relay/node`). Resolves once the first generation is up. A first attempt that fails on its arguments or the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervised-publisher.d.ts","sourceRoot":"","sources":["../src/supervised-publisher.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"supervised-publisher.d.ts","sourceRoot":"","sources":["../src/supervised-publisher.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGnF,OAAO,EACL,KAAK,4BAA4B,EAGjC,KAAK,oBAAoB,EAEzB,K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,iCAAiC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAEnH;AAED,0DAA0D;AAC1D,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,4BAA4B,GAAG,iBAAiB,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AAwCtH;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,iCAAiC,GACzC,OAAO,CAAC,mBAAmB,CAAC,CAqY9B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertTimeoutMs } from './connect-session.js';
|
|
1
|
+
import { assertTimeoutMs, reportEndpoint } from './connect-session.js';
|
|
2
2
|
import { RelayError } from './errors.js';
|
|
3
3
|
import { connectRelayPublisher, } from './publish.js';
|
|
4
4
|
import { CLOSURE_GRACE_MS } from './subscription.js';
|
|
@@ -141,6 +141,9 @@ export async function superviseRelayPublisher(connect, options) {
|
|
|
141
141
|
...connection,
|
|
142
142
|
namespace,
|
|
143
143
|
signal: signal ? AbortSignal.any([signal, attemptInProgress.signal]) : attemptInProgress.signal,
|
|
144
|
+
[reportEndpoint]: (endpoint) => {
|
|
145
|
+
connection.url ??= endpoint;
|
|
146
|
+
},
|
|
144
147
|
});
|
|
145
148
|
}
|
|
146
149
|
finally {
|