@caprid/relay 0.0.0 → 0.1.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/LICENSE +202 -0
- package/README.md +160 -1
- package/dist/connect-session.d.ts +125 -0
- package/dist/connect-session.d.ts.map +1 -0
- package/dist/connect-session.js +300 -0
- package/dist/connect-session.js.map +1 -0
- package/dist/connect.d.ts +143 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +129 -0
- package/dist/connect.js.map +1 -0
- package/dist/delivery-timeouts.d.ts +37 -0
- package/dist/delivery-timeouts.d.ts.map +1 -0
- package/dist/delivery-timeouts.js +48 -0
- package/dist/delivery-timeouts.js.map +1 -0
- package/dist/document-service.d.ts +58 -0
- package/dist/document-service.d.ts.map +1 -0
- package/dist/document-service.js +166 -0
- package/dist/document-service.js.map +1 -0
- package/dist/errors.d.ts +71 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +99 -0
- package/dist/errors.js.map +1 -0
- package/dist/frame-reader.d.ts +81 -0
- package/dist/frame-reader.d.ts.map +1 -0
- package/dist/frame-reader.js +110 -0
- package/dist/frame-reader.js.map +1 -0
- package/dist/frame-writer.d.ts +109 -0
- package/dist/frame-writer.d.ts.map +1 -0
- package/dist/frame-writer.js +409 -0
- package/dist/frame-writer.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/media-track-properties.d.ts +59 -0
- package/dist/media-track-properties.d.ts.map +1 -0
- package/dist/media-track-properties.js +120 -0
- package/dist/media-track-properties.js.map +1 -0
- package/dist/media.d.ts +28 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +28 -0
- package/dist/media.js.map +1 -0
- package/dist/namespace-events.d.ts +44 -0
- package/dist/namespace-events.d.ts.map +1 -0
- package/dist/namespace-events.js +107 -0
- package/dist/namespace-events.js.map +1 -0
- package/dist/node.d.ts +75 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +114 -0
- package/dist/node.js.map +1 -0
- package/dist/payload.d.ts +8 -0
- package/dist/payload.d.ts.map +1 -0
- package/dist/payload.js +23 -0
- package/dist/payload.js.map +1 -0
- package/dist/publish.d.ts +209 -0
- package/dist/publish.d.ts.map +1 -0
- package/dist/publish.js +123 -0
- package/dist/publish.js.map +1 -0
- package/dist/room-endpoint.d.ts +21 -0
- package/dist/room-endpoint.d.ts.map +1 -0
- package/dist/room-endpoint.js +47 -0
- package/dist/room-endpoint.js.map +1 -0
- package/dist/send-order.d.ts +14 -0
- package/dist/send-order.d.ts.map +1 -0
- package/dist/send-order.js +11 -0
- package/dist/send-order.js.map +1 -0
- package/dist/settling-groups.d.ts +35 -0
- package/dist/settling-groups.d.ts.map +1 -0
- package/dist/settling-groups.js +73 -0
- package/dist/settling-groups.js.map +1 -0
- package/dist/subscription-events.d.ts +51 -0
- package/dist/subscription-events.d.ts.map +1 -0
- package/dist/subscription-events.js +125 -0
- package/dist/subscription-events.js.map +1 -0
- package/dist/subscription.d.ts +207 -0
- package/dist/subscription.d.ts.map +1 -0
- package/dist/subscription.js +283 -0
- package/dist/subscription.js.map +1 -0
- package/dist/supervised-publisher.d.ts +92 -0
- package/dist/supervised-publisher.d.ts.map +1 -0
- package/dist/supervised-publisher.js +839 -0
- package/dist/supervised-publisher.js.map +1 -0
- package/dist/supervised-subscriber.d.ts +201 -0
- package/dist/supervised-subscriber.d.ts.map +1 -0
- package/dist/supervised-subscriber.js +1420 -0
- package/dist/supervised-subscriber.js.map +1 -0
- package/dist/supervision.d.ts +78 -0
- package/dist/supervision.d.ts.map +1 -0
- package/dist/supervision.js +149 -0
- package/dist/supervision.js.map +1 -0
- package/dist/switchable.d.ts +164 -0
- package/dist/switchable.d.ts.map +1 -0
- package/dist/switchable.js +327 -0
- package/dist/switchable.js.map +1 -0
- package/dist/validation.d.ts +64 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +137 -0
- package/dist/validation.js.map +1 -0
- package/dist/write-slot.d.ts +87 -0
- package/dist/write-slot.d.ts.map +1 -0
- package/dist/write-slot.js +519 -0
- package/dist/write-slot.js.map +1 -0
- package/package.json +82 -4
package/dist/node.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@caprid/relay/node`: the SDK for Node. It exports everything `@caprid/relay` does, and its connect functions default
|
|
3
|
+
* `createTransport` to `@caprid/relay-quic`, the native QUIC transport adapter, an optional peer dependency installed next
|
|
4
|
+
* to this package. It uses that adapter even when a global `WebTransport` exists, and warns once when the global
|
|
5
|
+
* could replace it.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { connectRelayPublisher } from '@caprid/relay/node';
|
|
9
|
+
*
|
|
10
|
+
* const publisher = await connectRelayPublisher({ url, namespace, getToken });
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
import { connectRelaySubscriber as connectSubscriber, } from './connect.js';
|
|
16
|
+
import { resolveTransport } from './connect-session.js';
|
|
17
|
+
import { RelayError } from './errors.js';
|
|
18
|
+
import { connectRelayPublisher as connectPublisher, } from './publish.js';
|
|
19
|
+
import { superviseRelayPublisher, } from './supervised-publisher.js';
|
|
20
|
+
import { superviseRelaySubscriber, } from './supervised-subscriber.js';
|
|
21
|
+
export * from './index.js';
|
|
22
|
+
let loading;
|
|
23
|
+
let warned = false;
|
|
24
|
+
/**
|
|
25
|
+
* Load `@caprid/relay-quic` and its native addon on first use; concurrent first calls share the one load. Either one
|
|
26
|
+
* missing is `TRANSPORT_UNAVAILABLE`; a failure is not kept, so a later call tries again.
|
|
27
|
+
*/
|
|
28
|
+
function loadAdapter() {
|
|
29
|
+
loading ??= (async () => {
|
|
30
|
+
try {
|
|
31
|
+
const { nativeQuicTransport } = await import('@caprid/relay-quic');
|
|
32
|
+
// With no options the only thing that can fail is loading the addon.
|
|
33
|
+
return { nativeQuicTransport, shared: nativeQuicTransport() };
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
loading = undefined;
|
|
37
|
+
throw new RelayError('TRANSPORT_UNAVAILABLE', '@caprid/relay/node needs @caprid/relay-quic and its native binary for this platform; install it next to ' +
|
|
38
|
+
'@caprid/relay (see its README)', 'connecting', { cause: error });
|
|
39
|
+
}
|
|
40
|
+
})();
|
|
41
|
+
return loading;
|
|
42
|
+
}
|
|
43
|
+
/** Whether this runtime has a global `WebTransport` the core's default factory would use: one that negotiates protocols. */
|
|
44
|
+
function hasNativeWebTransport() {
|
|
45
|
+
return typeof WebTransport !== 'undefined' && 'protocol' in WebTransport.prototype;
|
|
46
|
+
}
|
|
47
|
+
/** Once per process, a deprecation warning when Node's own `WebTransport` could replace this entry point. */
|
|
48
|
+
function warnIfNativeWebTransport() {
|
|
49
|
+
if (warned || !hasNativeWebTransport())
|
|
50
|
+
return;
|
|
51
|
+
warned = true;
|
|
52
|
+
// Through Node's warning channel, not the console: `--no-deprecation` silences it, and the code can be filtered.
|
|
53
|
+
const { process } = globalThis;
|
|
54
|
+
process?.emitWarning?.('native WebTransport detected; you can drop this import and use @caprid/relay instead of @caprid/relay/node', { type: 'DeprecationWarning', code: 'CAPRID_RELAY_NODE_NATIVE_WEBTRANSPORT' });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The role's options for the root connect function: the caller's own `createTransport`, or the adapter, loaded inside
|
|
58
|
+
* the connection's deadline and signal, after its arguments are checked.
|
|
59
|
+
*/
|
|
60
|
+
function withTransport(options) {
|
|
61
|
+
warnIfNativeWebTransport();
|
|
62
|
+
const { ca, serverCertificateHashes, ...rest } = options;
|
|
63
|
+
const trusted = ca !== undefined || serverCertificateHashes !== undefined;
|
|
64
|
+
if (rest.createTransport !== undefined) {
|
|
65
|
+
if (trusted) {
|
|
66
|
+
throw new TypeError('pass ca and serverCertificateHashes to nativeQuicTransport, not beside createTransport');
|
|
67
|
+
}
|
|
68
|
+
return rest;
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
...rest,
|
|
72
|
+
[resolveTransport]: async () => {
|
|
73
|
+
const { nativeQuicTransport, shared } = await loadAdapter();
|
|
74
|
+
if (!trusted)
|
|
75
|
+
return shared;
|
|
76
|
+
// Invalid trust options throw here, as they do from nativeQuicTransport itself.
|
|
77
|
+
return nativeQuicTransport({
|
|
78
|
+
...(ca === undefined ? {} : { ca }),
|
|
79
|
+
...(serverCertificateHashes === undefined ? {} : { serverCertificateHashes }),
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Open a Relay connection for subscribing to tracks, as `@caprid/relay`'s `connectRelaySubscriber` does, over native QUIC
|
|
86
|
+
* through `@caprid/relay-quic` unless `createTransport` is given. The caller owns connection shutdown; an open connection
|
|
87
|
+
* keeps the process alive until it closes.
|
|
88
|
+
*/
|
|
89
|
+
export async function connectRelaySubscriber(options) {
|
|
90
|
+
return connectSubscriber(withTransport(options));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Open a Relay connection that publishes one namespace, as `@caprid/relay`'s `connectRelayPublisher` does, over native
|
|
94
|
+
* QUIC through `@caprid/relay-quic` unless `createTransport` is given. An open connection keeps the process alive until
|
|
95
|
+
* it closes.
|
|
96
|
+
*/
|
|
97
|
+
export async function connectRelayPublisher(options) {
|
|
98
|
+
return connectPublisher(withTransport(options));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Open a subscriber that reconnects, as `@caprid/relay`'s `connectSupervisedSubscriber` does, with every connection over
|
|
102
|
+
* native QUIC through `@caprid/relay-quic` unless `createTransport` is given.
|
|
103
|
+
*/
|
|
104
|
+
export async function connectSupervisedSubscriber(options) {
|
|
105
|
+
return superviseRelaySubscriber(connectSubscriber, withTransport(options));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Open a publisher that reconnects, as `@caprid/relay`'s `connectSupervisedPublisher` does, with every generation over
|
|
109
|
+
* native QUIC through `@caprid/relay-quic` unless `createTransport` is given.
|
|
110
|
+
*/
|
|
111
|
+
export async function connectSupervisedPublisher(options) {
|
|
112
|
+
return superviseRelayPublisher(connectPublisher, withTransport(options));
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAGL,sBAAsB,IAAI,iBAAiB,GAG5C,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAEL,qBAAqB,IAAI,gBAAgB,GAE1C,MAAM,cAAc,CAAC;AAEtB,OAAO,EAGL,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAGL,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAEpC,cAAc,YAAY,CAAC;AA+C3B,IAAI,OAAqC,CAAC;AAC1C,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB;;;GAGG;AACH,SAAS,WAAW;IAClB,OAAO,KAAK,CAAC,KAAK,IAAI,EAAE;QACtB,IAAI,CAAC;YACH,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;YACnE,qEAAqE;YACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,mBAAmB,EAAE,EAAE,CAAC;QAChE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,GAAG,SAAS,CAAC;YACpB,MAAM,IAAI,UAAU,CAClB,uBAAuB,EACvB,0GAA0G;gBACxG,gCAAgC,EAClC,YAAY,EACZ,EAAE,KAAK,EAAE,KAAK,EAAE,CAC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CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;gBACnC,GAAG,CAAC,uBAAuB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,uBAAuB,EAAE,CAAC;aAC9E,CAAC,CAAC;QACL,CAAC;KACG,CAAC;AACT,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAwD;IAExD,OAAO,iBAAiB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAuD;IAEvD,OAAO,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AAClD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,OAA6D;IAE7D,OAAO,wBAAwB,CAAC,iBAAiB,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAA4D;IAE5D,OAAO,uBAAuB,CAAC,gBAAgB,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MoqtObject } from '@caprid/moq-core';
|
|
2
|
+
export declare function encodeText(text: string): Uint8Array;
|
|
3
|
+
export declare function encodeJSON(value: unknown): Uint8Array;
|
|
4
|
+
/** Decode one complete object as UTF-8. Malformed UTF-8 throws a TypeError. */
|
|
5
|
+
export declare function readText(object: Pick<MoqtObject, 'payload'>): string;
|
|
6
|
+
/** Parse one UTF-8 JSON object payload. The result is not schema-validated. */
|
|
7
|
+
export declare function readJSON(object: Pick<MoqtObject, 'payload'>): unknown;
|
|
8
|
+
//# sourceMappingURL=payload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../src/payload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMnD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAGnD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAIrD;AAED,+EAA+E;AAC/E,wBAAgB,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,MAAM,CAEpE;AAED,+EAA+E;AAC/E,wBAAgB,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,OAAO,CAErE"}
|
package/dist/payload.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const encoder = new TextEncoder();
|
|
2
|
+
// Preserve a leading U+FEFF, and reject malformed UTF-8 instead of replacing bytes.
|
|
3
|
+
const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
4
|
+
export function encodeText(text) {
|
|
5
|
+
if (typeof text !== 'string')
|
|
6
|
+
throw new TypeError('Text must be a string');
|
|
7
|
+
return encoder.encode(text);
|
|
8
|
+
}
|
|
9
|
+
export function encodeJSON(value) {
|
|
10
|
+
const text = JSON.stringify(value);
|
|
11
|
+
if (text === undefined)
|
|
12
|
+
throw new TypeError('Value cannot be serialized as JSON');
|
|
13
|
+
return encodeText(text);
|
|
14
|
+
}
|
|
15
|
+
/** Decode one complete object as UTF-8. Malformed UTF-8 throws a TypeError. */
|
|
16
|
+
export function readText(object) {
|
|
17
|
+
return decoder.decode(object.payload);
|
|
18
|
+
}
|
|
19
|
+
/** Parse one UTF-8 JSON object payload. The result is not schema-validated. */
|
|
20
|
+
export function readJSON(object) {
|
|
21
|
+
return JSON.parse(readText(object));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=payload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.js","sourceRoot":"","sources":["../src/payload.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,oFAAoF;AACpF,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAE3E,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,MAAM,IAAI,SAAS,CAAC,uBAAuB,CAAC,CAAC;IAC3E,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,IAAI,KAAK,SAAS;QAAE,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;IAClF,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,QAAQ,CAAC,MAAmC;IAC1D,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,QAAQ,CAAC,MAAmC;IAC1D,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { type ObjectStatus } from '@caprid/moq-core';
|
|
2
|
+
import { type ConnectRelayOptions } from './connect-session.js';
|
|
3
|
+
/**
|
|
4
|
+
* Options for connectRelayPublisher: the shared connection options plus the namespace. There is no
|
|
5
|
+
* request deadline; each track's writeTimeoutMs bounds waiting for demand and writing.
|
|
6
|
+
*/
|
|
7
|
+
export interface ConnectRelayPublisherOptions extends ConnectRelayOptions {
|
|
8
|
+
/** One namespace per publisher connection. Register any number of tracks within it. */
|
|
9
|
+
namespace: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* One MOQT property (a key-value pair) on a registered track or a written object, encoded as
|
|
13
|
+
* supplied. Invalid properties are a TypeError naming the property index. A byte value over 65535
|
|
14
|
+
* bytes is a RangeError, and so is a list past its bound: on a track, more than 65525 encoded bytes
|
|
15
|
+
* (the room SUBSCRIBE_OK leaves), more than 64 pairs, or a 0x0E above 255 or 0x22 other than 1 or 2;
|
|
16
|
+
* on an object, more than 64 KiB encoded (the relay's limit). Both are raised before a track is
|
|
17
|
+
* registered or a write starts.
|
|
18
|
+
*/
|
|
19
|
+
export interface PublishProperty {
|
|
20
|
+
/** Non-negative safe integer: even types encode an integer, odd types encode bytes. */
|
|
21
|
+
type: number;
|
|
22
|
+
/** A non-negative safe integer for an even type; an `ArrayBufferView`, copied as its raw bytes, for an odd type. */
|
|
23
|
+
value: number | ArrayBufferView;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What {@link RelayPublisher.registerTrack} needs. The namespace is the publisher connection's;
|
|
27
|
+
* the generic core's type of the same name spells it out as a field one level down.
|
|
28
|
+
*/
|
|
29
|
+
export interface RegisterTrackOptions {
|
|
30
|
+
/** Track name, unique within this publisher connection, including after its writer closes. */
|
|
31
|
+
track: string;
|
|
32
|
+
/**
|
|
33
|
+
* Track metadata sent to the relay. The SDK adds no default timescale; the relay may
|
|
34
|
+
* add, drop, or rewrite properties before delivery to subscribers. With moq-relay 0.17.0 every
|
|
35
|
+
* SUBSCRIBE_OK carries the relay's track properties, not these, and a Timescale (`0x08`) here is
|
|
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
|
|
38
|
+
* bytes, hold at most 64 pairs (the relay's limit) and keep `0x0E` at most 255 and `0x22` at 1
|
|
39
|
+
* or 2 (draft-22); otherwise the relay would refuse every subscriber, so `registerTrack` throws a
|
|
40
|
+
* RangeError instead.
|
|
41
|
+
*
|
|
42
|
+
* An OBJECT_DELIVERY_TIMEOUT (`0x02`) or SUBGROUP_DELIVERY_TIMEOUT (`0x06`) here, in milliseconds,
|
|
43
|
+
* is the publisher's delivery timeout (draft-22 §5.2), which the first object of a group can
|
|
44
|
+
* override for that group. An object still short of the transport when the object timeout
|
|
45
|
+
* expires fails its write with `DELIVERY_TIMEOUT`; a completed group the relay has not
|
|
46
|
+
* acknowledged when the subgroup timeout expires is reset, and nothing is reported. 0 means no
|
|
47
|
+
* timeout.
|
|
48
|
+
*/
|
|
49
|
+
trackProperties?: readonly PublishProperty[];
|
|
50
|
+
/** Deadline for relay demand and stream writes. Default 10 seconds, maximum 2147483647. */
|
|
51
|
+
writeTimeoutMs?: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* One open group from {@link RelayTrackWriter.openGroup}: a single subgroup stream the application
|
|
55
|
+
* writes objects to in order, then FINs with `close()` or resets with `abort()`. It holds the track's
|
|
56
|
+
* write slot until then, so the track's `write()` and another `openGroup()` fail with `WRITE_PENDING` meanwhile.
|
|
57
|
+
*/
|
|
58
|
+
export interface RelayGroupWriter {
|
|
59
|
+
/** The group's ID. Group IDs start at 0 on each track and increase by one per group the track opens. */
|
|
60
|
+
readonly groupId: number;
|
|
61
|
+
/** How many objects this group has written; the next `write()` uses it as the object ID. */
|
|
62
|
+
readonly objectCount: number;
|
|
63
|
+
/** True once `close()` completed, or the group was aborted, failed, or lost its track or connection. */
|
|
64
|
+
readonly closed: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Append one object, starting at ID 0. Each write has its own writeTimeoutMs deadline, and a
|
|
67
|
+
* delivery timeout can end it sooner with `DELIVERY_TIMEOUT`, which resets the whole group.
|
|
68
|
+
* Properties are encoded as supplied; the relay may transform them before delivery. A `0x02` or
|
|
69
|
+
* `0x06` property on object 0 sets the group's delivery timeouts; on a later object it is ignored.
|
|
70
|
+
*/
|
|
71
|
+
write(payload: ArrayBufferView, options?: {
|
|
72
|
+
properties?: readonly PublishProperty[];
|
|
73
|
+
status?: ObjectStatus;
|
|
74
|
+
}): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* FIN the group within writeTimeoutMs. Resolves once the FIN is handed to the transport, not once
|
|
77
|
+
* the relay acknowledges it. Idempotent after successful completion.
|
|
78
|
+
*/
|
|
79
|
+
close(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Reset this group and free the track for the next random-access point. After a clean `close()`
|
|
82
|
+
* this has no effect: the FIN already ended the stream (draft-22 §11.3.2).
|
|
83
|
+
*/
|
|
84
|
+
abort(reason?: unknown): void;
|
|
85
|
+
/** Encode UTF-8 text and write one object with the same options and semantics as write(). */
|
|
86
|
+
writeText(text: string, options?: {
|
|
87
|
+
properties?: readonly PublishProperty[];
|
|
88
|
+
status?: ObjectStatus;
|
|
89
|
+
}): Promise<void>;
|
|
90
|
+
/** Serialize with JSON.stringify and write one object. Serialization errors leave the writer usable. */
|
|
91
|
+
writeJSON(value: unknown, options?: {
|
|
92
|
+
properties?: readonly PublishProperty[];
|
|
93
|
+
status?: ObjectStatus;
|
|
94
|
+
}): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* One registered track on a publisher connection, from {@link RelayPublisher.registerTrack}.
|
|
98
|
+
* Registration sends nothing; `write()` and `openGroup()` send, after waiting for relay demand.
|
|
99
|
+
* The behaviour behind this interface is the track's write slot (see CONTEXT.md and the
|
|
100
|
+
* "Write phases and interruptions" table in spec/behavior.md).
|
|
101
|
+
*/
|
|
102
|
+
export interface RelayTrackWriter {
|
|
103
|
+
/**
|
|
104
|
+
* Whether the relay currently has an upstream subscription for this track, so a write would
|
|
105
|
+
* proceed at once. Demand is the relay's own subscription, shared by every downstream viewer
|
|
106
|
+
* and ended when the relay chooses: it is neither a viewer count nor a liveness signal. Always false once the track is closed.
|
|
107
|
+
*/
|
|
108
|
+
readonly hasDemand: boolean;
|
|
109
|
+
/** True once the application closed the track or the publisher connection ended. */
|
|
110
|
+
readonly closed: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* The current demand state first, then one value per relay subscription change: `true` when the
|
|
113
|
+
* relay subscribes or replaces its subscription (so `true` can repeat), `false` when its
|
|
114
|
+
* subscription ends. Ends when the track ends. This is how a catalog re-sends its document on
|
|
115
|
+
* every relay subscription. Values are per relay subscription, never per downstream viewer.
|
|
116
|
+
*/
|
|
117
|
+
demandChanges(): AsyncIterableIterator<boolean>;
|
|
118
|
+
/**
|
|
119
|
+
* Open a group and hold the track's single write slot until it closes or aborts. Waits for relay
|
|
120
|
+
* demand, for room under the connection's settling-group limit and for the stream, within
|
|
121
|
+
* writeTimeoutMs.
|
|
122
|
+
*
|
|
123
|
+
* With `payload`, the group opens with it as object 0 and resolves once the transport takes it
|
|
124
|
+
* (`objectCount` is 1). Its delivery timeout counts from this call, so every wait before the stream
|
|
125
|
+
* opens counts (draft-22 §5.2), and a `0x02` or `0x06` property in `properties` sets the group's
|
|
126
|
+
* delivery timeouts. If it expires the call fails with `DELIVERY_TIMEOUT` and the group is reset.
|
|
127
|
+
* Without `payload` there is no object to time, so only writeTimeoutMs bounds the wait; `properties`
|
|
128
|
+
* without `payload` is a TypeError.
|
|
129
|
+
*/
|
|
130
|
+
openGroup(options?: {
|
|
131
|
+
payload?: ArrayBufferView;
|
|
132
|
+
properties?: readonly PublishProperty[];
|
|
133
|
+
signal?: AbortSignal;
|
|
134
|
+
}): Promise<RelayGroupWriter>;
|
|
135
|
+
/**
|
|
136
|
+
* Send one independent object/group. Waits for relay demand (see hasDemand). Resolves when the
|
|
137
|
+
* transport accepts the complete group, not when a downstream viewer acknowledges it.
|
|
138
|
+
* Only one write may be pending; await it before writing again. Any ArrayBufferView is
|
|
139
|
+
* copied as its raw bytes; anything else is a TypeError that leaves the track usable.
|
|
140
|
+
* Properties are encoded as supplied; the relay may transform them before delivery.
|
|
141
|
+
* Failure resets this group and leaves the track usable while the connection is open.
|
|
142
|
+
* Data may already have reached the relay; choose the next object explicitly (no automatic retry).
|
|
143
|
+
*/
|
|
144
|
+
write(payload: ArrayBufferView, options?: {
|
|
145
|
+
properties?: readonly PublishProperty[];
|
|
146
|
+
signal?: AbortSignal;
|
|
147
|
+
}): Promise<void>;
|
|
148
|
+
/** End the track and cancel an outstanding write. The publisher connection stays open. */
|
|
149
|
+
close(): void;
|
|
150
|
+
/** Encode UTF-8 text and write one object with the same options and semantics as write(). */
|
|
151
|
+
writeText(text: string, options?: {
|
|
152
|
+
properties?: readonly PublishProperty[];
|
|
153
|
+
signal?: AbortSignal;
|
|
154
|
+
}): Promise<void>;
|
|
155
|
+
/** Serialize with JSON.stringify and write one object. Serialization errors leave the writer usable. */
|
|
156
|
+
writeJSON(value: unknown, options?: {
|
|
157
|
+
properties?: readonly PublishProperty[];
|
|
158
|
+
signal?: AbortSignal;
|
|
159
|
+
}): Promise<void>;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* A connection that can only publish, serving one namespace. Create one with
|
|
163
|
+
* {@link connectRelayPublisher}. Subscribing uses a separate connection; see `connectRelaySubscriber`.
|
|
164
|
+
*/
|
|
165
|
+
export interface RelayPublisher {
|
|
166
|
+
/**
|
|
167
|
+
* Register a track this publisher will serve and return its writer. Nothing is sent: the relay
|
|
168
|
+
* learns of the track when a subscriber asks for it, and bytes move when the writer's `write()`
|
|
169
|
+
* or `openGroup()` runs, after waiting for that relay demand. No capture starts and no media
|
|
170
|
+
* catalog is published. Track names are unique per publisher connection, including after their
|
|
171
|
+
* writer closes.
|
|
172
|
+
*/
|
|
173
|
+
registerTrack(options: RegisterTrackOptions): RelayTrackWriter;
|
|
174
|
+
/**
|
|
175
|
+
* Settles once the namespace announce has reached the wire on a solicitation that covers it,
|
|
176
|
+
* which is no earlier than the first registered track. It is the strongest fact the publisher
|
|
177
|
+
* has: the relay acknowledges an announce with nothing and routes subscribes for the namespace
|
|
178
|
+
* about a round trip later, so a subscribe that races it is rejected (request error 16
|
|
179
|
+
* `unroutable` on moq-relay 0.15.8 and later; see spec/behavior.md). It stays pending while no
|
|
180
|
+
* solicitation covers the namespace, where the first write reports `NAMESPACE_NOT_SOLICITED`, and
|
|
181
|
+
* the connection's closure terminates it if that comes first: the closure's error, or a `CLOSED`
|
|
182
|
+
* RelayError after a clean shutdown. Pre-handled, so nobody has to await it.
|
|
183
|
+
*/
|
|
184
|
+
readonly announced: Promise<void>;
|
|
185
|
+
/** Ends when the connection shuts down. Errors are returned as data; this never rejects. */
|
|
186
|
+
readonly closed: Promise<{
|
|
187
|
+
/** The failure that ended the connection; absent after a clean shutdown. */
|
|
188
|
+
error?: unknown;
|
|
189
|
+
}>;
|
|
190
|
+
/**
|
|
191
|
+
* When the relay will end this connection for its credential's expiry: the `RelayCredential`'s `expiresAt`, or the
|
|
192
|
+
* JWT's `exp` claim, read without verifying it. `undefined` when neither is known. The relay closes the session then
|
|
193
|
+
* with `UNAUTHORIZED` in phase `connection`; open a replacement before it. Supervised connections do.
|
|
194
|
+
*/
|
|
195
|
+
readonly expiresAt: Date | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* End all tracks, retract the namespace, and wait for transport shutdown. First waits, for up to
|
|
198
|
+
* the largest writeTimeoutMs among the tracks, for completed groups the relay has not yet
|
|
199
|
+
* acknowledged; any still unacknowledged after that may be lost. Idempotent.
|
|
200
|
+
*/
|
|
201
|
+
close(): Promise<void>;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Open a dedicated Relay publisher connection. Subscribers use connectRelaySubscriber; this
|
|
205
|
+
* initial publishing API does not share their physical transport. A relay must solicit the
|
|
206
|
+
* namespace and subscribe upstream before data can flow.
|
|
207
|
+
*/
|
|
208
|
+
export declare function connectRelayPublisher(options: ConnectRelayPublisherOptions): Promise<RelayPublisher>;
|
|
209
|
+
//# sourceMappingURL=publish.d.ts.map
|
|
@@ -0,0 +1 @@
|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CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpH,wGAAwG;IACxG,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,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,CAoH1G"}
|
package/dist/publish.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { createMoqtPublishSession, createSubgroupWriter } from '@caprid/moq-core';
|
|
2
|
+
import { assertTimeoutMs, openRelaySession } from './connect-session.js';
|
|
3
|
+
import { NO_DELIVERY_TIMEOUTS, publisherTimeouts, subscriberTimeouts, } from './delivery-timeouts.js';
|
|
4
|
+
import { RelayError } from './errors.js';
|
|
5
|
+
import { trackSendOptions } from './send-order.js';
|
|
6
|
+
import { createSettlingGroups } from './settling-groups.js';
|
|
7
|
+
import { namespaceFields, trackName, trackPropertyPairs } from './validation.js';
|
|
8
|
+
import { createWriteSlot } from './write-slot.js';
|
|
9
|
+
/**
|
|
10
|
+
* Open a dedicated Relay publisher connection. Subscribers use connectRelaySubscriber; this
|
|
11
|
+
* initial publishing API does not share their physical transport. A relay must solicit the
|
|
12
|
+
* namespace and subscribe upstream before data can flow.
|
|
13
|
+
*/
|
|
14
|
+
export async function connectRelayPublisher(options) {
|
|
15
|
+
// Arguments before anything else: an invalid namespace never reaches the token provider or the
|
|
16
|
+
// transport factory.
|
|
17
|
+
const namespace = namespaceFields(options.namespace);
|
|
18
|
+
// One write slot per registered track; the session's binding callback and the connection's end
|
|
19
|
+
// reach the slots through here.
|
|
20
|
+
const tracks = new Map();
|
|
21
|
+
// Each relay subscription's delivery timeouts (§5.2), by its request ID, which the core also uses as
|
|
22
|
+
// its track alias: SUBSCRIBE's parameters, as REQUEST_UPDATE changes them.
|
|
23
|
+
const subscriptionTimeouts = new Map();
|
|
24
|
+
// Groups whose FIN the transport took but the relay has not acknowledged, shared by every track.
|
|
25
|
+
const settlingGroups = createSettlingGroups();
|
|
26
|
+
// What closing waits for them: the largest write deadline among the tracks.
|
|
27
|
+
let drainMs = 0;
|
|
28
|
+
// Settled by the session's onAnnounced callback; a closure that comes first terminates it.
|
|
29
|
+
let announce = () => { };
|
|
30
|
+
let abandonAnnounce = () => { };
|
|
31
|
+
const announced = new Promise((resolve, reject) => {
|
|
32
|
+
announce = resolve;
|
|
33
|
+
abandonAnnounce = reject;
|
|
34
|
+
});
|
|
35
|
+
// Nobody may await readiness; a rejection must not surface as an unhandled rejection.
|
|
36
|
+
void announced.catch(() => { });
|
|
37
|
+
const lifetime = await openRelaySession(options, (transport, callbacks, setupOptions) => createMoqtPublishSession(transport, {
|
|
38
|
+
implementationName: '@caprid/relay publisher',
|
|
39
|
+
setupOptions,
|
|
40
|
+
callbacks: {
|
|
41
|
+
...callbacks,
|
|
42
|
+
onAnnounced: () => announce(),
|
|
43
|
+
onSubscribe: ({ requestId, parameters }) => subscriptionTimeouts.set(requestId, subscriberTimeouts(parameters)),
|
|
44
|
+
onRequestUpdate: ({ requestId, parameters }) => {
|
|
45
|
+
const previous = subscriptionTimeouts.get(requestId);
|
|
46
|
+
if (previous)
|
|
47
|
+
subscriptionTimeouts.set(requestId, subscriberTimeouts(parameters, previous));
|
|
48
|
+
},
|
|
49
|
+
onSubscribeEnd: ({ requestId }) => subscriptionTimeouts.delete(requestId),
|
|
50
|
+
onTrackBinding: ({ trackName, trackAlias }) => tracks.get(trackName)?.bind(trackAlias),
|
|
51
|
+
onAnnounceEnded: ({ error }) => callbacks.onClosed?.({
|
|
52
|
+
error: new RelayError('NAMESPACE_ENDED', 'Relay withdrew the namespace', 'connection', { cause: error }),
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
}));
|
|
56
|
+
const { session } = lifetime;
|
|
57
|
+
let closing = false;
|
|
58
|
+
let shutdown;
|
|
59
|
+
session.announce(namespace);
|
|
60
|
+
void lifetime.closed.then(({ error }) => {
|
|
61
|
+
closing = true;
|
|
62
|
+
// Only a clean shutdown (no error at all) becomes CLOSED; a closure reason of `null` is preserved.
|
|
63
|
+
abandonAnnounce(error === undefined
|
|
64
|
+
? new RelayError('CLOSED', 'Relay publisher closed before its namespace was announced', 'connection')
|
|
65
|
+
: error);
|
|
66
|
+
for (const slot of tracks.values())
|
|
67
|
+
slot.disconnect(error);
|
|
68
|
+
});
|
|
69
|
+
const closed = lifetime.transportClosed.then(() => lifetime.closed, () => lifetime.closed);
|
|
70
|
+
return {
|
|
71
|
+
announced,
|
|
72
|
+
closed,
|
|
73
|
+
expiresAt: lifetime.expiresAt === undefined ? undefined : new Date(lifetime.expiresAt.getTime()),
|
|
74
|
+
registerTrack({ track, trackProperties, writeTimeoutMs = 10_000 }) {
|
|
75
|
+
// Arguments first, then connection state, then the registry.
|
|
76
|
+
const name = trackName(track);
|
|
77
|
+
const properties = trackPropertyPairs(trackProperties);
|
|
78
|
+
assertTimeoutMs('writeTimeoutMs', writeTimeoutMs);
|
|
79
|
+
lifetime.assertOpen();
|
|
80
|
+
if (closing)
|
|
81
|
+
throw new RelayError('CLOSED', 'Relay publisher is closed', 'connection');
|
|
82
|
+
if (tracks.has(name))
|
|
83
|
+
throw new RangeError('Track name is already registered on this publisher connection');
|
|
84
|
+
const registered = session.registerTrack({
|
|
85
|
+
trackNamespace: namespace,
|
|
86
|
+
trackName: name,
|
|
87
|
+
trackProperties: properties,
|
|
88
|
+
});
|
|
89
|
+
const sendOptions = trackSendOptions(properties);
|
|
90
|
+
const slot = createWriteSlot({
|
|
91
|
+
openSubgroup: async (trackAlias, groupId) => createSubgroupWriter(await session.openUniStream(trackAlias, sendOptions), {
|
|
92
|
+
trackAlias,
|
|
93
|
+
groupId,
|
|
94
|
+
hasProperties: true,
|
|
95
|
+
}),
|
|
96
|
+
settlingGroups,
|
|
97
|
+
namespaceSolicited: () => session.namespaceSolicited,
|
|
98
|
+
assertOpen: lifetime.assertOpen,
|
|
99
|
+
endTrack: () => registered.end(),
|
|
100
|
+
writeTimeoutMs,
|
|
101
|
+
trackTimeouts: publisherTimeouts(properties),
|
|
102
|
+
subscriberTimeouts: (trackAlias) => subscriptionTimeouts.get(trackAlias) ?? NO_DELIVERY_TIMEOUTS,
|
|
103
|
+
});
|
|
104
|
+
tracks.set(track, slot);
|
|
105
|
+
drainMs = Math.max(drainMs, writeTimeoutMs);
|
|
106
|
+
return slot.writer;
|
|
107
|
+
},
|
|
108
|
+
close() {
|
|
109
|
+
shutdown ??= (async () => {
|
|
110
|
+
closing = true;
|
|
111
|
+
for (const slot of tracks.values())
|
|
112
|
+
slot.writer.close();
|
|
113
|
+
// Chromium resets every stream still awaiting its acknowledgment when the session closes,
|
|
114
|
+
// so give the last groups up to one write deadline to settle; after that they may be lost.
|
|
115
|
+
await settlingGroups.drain(drainMs, lifetime.closed);
|
|
116
|
+
lifetime.close();
|
|
117
|
+
await closed;
|
|
118
|
+
})();
|
|
119
|
+
return shutdown;
|
|
120
|
+
},
|
|
121
|
+
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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,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Root an endpoint at a room. The result is the endpoint with each room field appended to its
|
|
3
|
+
* 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:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* roomEndpoint('https://relay.mux.global', ['acme', 'rooms', '42']);
|
|
8
|
+
* // 'https://relay.mux.global/acme/rooms/42'
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* The endpoint follows the connect calls' rules and the room the namespace rules. Nothing is
|
|
12
|
+
* percent-encoded: a room field holds only `A`–`Z`, `a`–`z`, `0`–`9` and `-._~!$&'()+,;=:@`, and is
|
|
13
|
+
* not `.` or `..`. A namespace with any other field is reached from the bare host instead.
|
|
14
|
+
*
|
|
15
|
+
* @throws {TypeError} An endpoint that is not an absolute URL string, or a room that is not a
|
|
16
|
+
* sequence of non-empty string fields.
|
|
17
|
+
* @throws {RangeError} An endpoint that is not `https`, has a fragment or userinfo, or an empty
|
|
18
|
+
* `jwt`; a room of more than 32 fields; a room field with any other character, or `.` or `..`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function roomEndpoint(endpoint: string, room: readonly string[]): string;
|
|
21
|
+
//# sourceMappingURL=room-endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-endpoint.d.ts","sourceRoot":"","sources":["../src/room-endpoint.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAiB9E"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The room-rooted endpoint for a room: the endpoint with the room's fields appended to its path
|
|
3
|
+
* ("Room-rooted endpoints" in spec/behavior.md). Pure: it builds a string and connects nothing.
|
|
4
|
+
*/
|
|
5
|
+
import { endpointUrl } from './connect-session.js';
|
|
6
|
+
import { namespaceFields } from './validation.js';
|
|
7
|
+
/**
|
|
8
|
+
* The characters a room field may hold: what a URL path carries unchanged in every parser and
|
|
9
|
+
* moq-relay reads back as the same field. The relay does not percent-decode the path, so a field
|
|
10
|
+
* that would need encoding cannot be rooted at, and `*` fails the connection (spec/relay-interop.md,
|
|
11
|
+
* "Endpoint paths").
|
|
12
|
+
*/
|
|
13
|
+
const ROOM_FIELD = /^[A-Za-z0-9\-._~!$&'()+,;=:@]+$/;
|
|
14
|
+
/**
|
|
15
|
+
* Root an endpoint at a room. The result is the endpoint with each room field appended to its
|
|
16
|
+
* path, after any path it has and without its trailing slashes, and with its query kept, a `jwt`
|
|
17
|
+
* parameter included. A connection to it names namespaces relative to the room:
|
|
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 `..`.
|
|
32
|
+
*/
|
|
33
|
+
export function roomEndpoint(endpoint, room) {
|
|
34
|
+
const url = endpointUrl(endpoint);
|
|
35
|
+
const fields = namespaceFields(room);
|
|
36
|
+
fields.forEach((field, index) => {
|
|
37
|
+
if (!ROOM_FIELD.test(field))
|
|
38
|
+
throw new RangeError(`Room field ${index} (${JSON.stringify(field)}) has a character a room-rooted endpoint cannot carry: ` +
|
|
39
|
+
"only A-Z, a-z, 0-9 and -._~!$&'()+,;=:@ reach the relay as the same field. " +
|
|
40
|
+
'Reach this namespace from the bare host instead');
|
|
41
|
+
if (field === '.' || field === '..')
|
|
42
|
+
throw new RangeError(`Room field ${index} is "${field}", which a URL folds into the path; reach this namespace from the bare host instead`);
|
|
43
|
+
});
|
|
44
|
+
url.pathname = `${url.pathname.replace(/\/+$/, '')}/${fields.join('/')}`;
|
|
45
|
+
return url.href;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=room-endpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-endpoint.js","sourceRoot":"","sources":["../src/room-endpoint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,UAAU,GAAG,iCAAiC,CAAC;AAErD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,IAAuB;IACpE,MAAM,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC9B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;YACzB,MAAM,IAAI,UAAU,CAClB,cAAc,KAAK,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,yDAAyD;gBACpG,6EAA6E;gBAC7E,iDAAiD,CACpD,CAAC;QACJ,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI;YACjC,MAAM,IAAI,UAAU,CAClB,cAAc,KAAK,QAAQ,KAAK,qFAAqF,CACtH,CAAC;IACN,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,QAAQ,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACzE,OAAO,GAAG,CAAC,IAAI,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A track's data streams' WebTransport send order, from its Default Publisher Priority (0x0E), so the publisher's own
|
|
3
|
+
* transport sends a more urgent track first when the uplink is congested (spec/behavior.md, "Send order").
|
|
4
|
+
*
|
|
5
|
+
* Draft-22's priority is lower-is-more-urgent from 0 to 255 (§5.1); WebTransport's send order is higher-first, with 0
|
|
6
|
+
* for every stream opened without one, the control and request streams among them. A declared priority p maps to
|
|
7
|
+
* `-1 - p`, from -1 to -256: below those streams, which a congested media track must never hold up, and in the
|
|
8
|
+
* draft's order among themselves. A track without the property gets no send order, so it goes with the control
|
|
9
|
+
* streams: a catalog or a timeline ahead of the media it describes.
|
|
10
|
+
*/
|
|
11
|
+
import type { KeyValuePair, MoqtSendStreamOptions } from '@caprid/moq-core';
|
|
12
|
+
/** The send options for each data stream of a track with these properties; the first integer 0x0E counts. */
|
|
13
|
+
export declare function trackSendOptions(properties: readonly KeyValuePair[]): MoqtSendStreamOptions | undefined;
|
|
14
|
+
//# sourceMappingURL=send-order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-order.d.ts","sourceRoot":"","sources":["../src/send-order.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAG5E,6GAA6G;AAC7G,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,SAAS,YAAY,EAAE,GAAG,qBAAqB,GAAG,SAAS,CAOvG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_PUBLISHER_PRIORITY } from './validation.js';
|
|
2
|
+
/** The send options for each data stream of a track with these properties; the first integer 0x0E counts. */
|
|
3
|
+
export function trackSendOptions(properties) {
|
|
4
|
+
for (const property of properties) {
|
|
5
|
+
if (property.type === DEFAULT_PUBLISHER_PRIORITY && typeof property.value === 'number') {
|
|
6
|
+
return { sendOrder: -1 - property.value };
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=send-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-order.js","sourceRoot":"","sources":["../src/send-order.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE7D,6GAA6G;AAC7G,MAAM,UAAU,gBAAgB,CAAC,UAAmC;IAClE,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE,CAAC;QAClC,IAAI,QAAQ,CAAC,IAAI,KAAK,0BAA0B,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvF,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|