@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
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A publisher connection's settling groups (see CONTEXT.md): groups whose operation completed once
|
|
3
|
+
* the transport took their FIN, but whose FIN the relay has not acknowledged yet.
|
|
4
|
+
*
|
|
5
|
+
* Chromium refuses `createUnidirectionalStream()` once stream credit runs out instead of waiting
|
|
6
|
+
* for it, and settling groups are what can pile up on a connection: open streams are already
|
|
7
|
+
* bounded by one per track. So before an operation opens its stream it waits while the connection
|
|
8
|
+
* has {@link SETTLING_GROUP_LIMIT} settling groups, first come first served; it holds nothing while
|
|
9
|
+
* its stream is open, and its group joins the set once its FIN is handed over. The count can
|
|
10
|
+
* briefly exceed the limit by the number of groups open at that moment.
|
|
11
|
+
*
|
|
12
|
+
* A settling group that fails later (STOP_SENDING, a reset, session teardown) leaves the set like
|
|
13
|
+
* one that settles cleanly, and nobody hears of it: the cause surfaces as demand, a rebind, or the
|
|
14
|
+
* connection's `closed`. `publisher.close()` drains the set before it closes the transport, because
|
|
15
|
+
* Chromium resets every stream still awaiting its acknowledgment when the session goes.
|
|
16
|
+
*/
|
|
17
|
+
/** Settling groups per publisher connection before new streams wait. Internal, not an option. */
|
|
18
|
+
export declare const SETTLING_GROUP_LIMIT = 64;
|
|
19
|
+
export interface SettlingGroups {
|
|
20
|
+
/** Whether a new stream may open now: the connection is below the limit. */
|
|
21
|
+
hasRoom(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Wait until the connection is below the limit. Rejects with the reason of `interrupted` if that
|
|
24
|
+
* rejects first.
|
|
25
|
+
*/
|
|
26
|
+
waitForRoom(interrupted: Promise<never>): Promise<void>;
|
|
27
|
+
/** A group's FIN was handed over: count it until `settled` settles, either way. */
|
|
28
|
+
add(settled: Promise<void>): void;
|
|
29
|
+
/** Wait for every settling group, for at most `timeoutMs` or until `stop` settles. Never rejects. */
|
|
30
|
+
drain(timeoutMs: number, stop: Promise<unknown>): Promise<void>;
|
|
31
|
+
/** How many groups are settling now. */
|
|
32
|
+
readonly size: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function createSettlingGroups(limit?: number): SettlingGroups;
|
|
35
|
+
//# sourceMappingURL=settling-groups.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settling-groups.d.ts","sourceRoot":"","sources":["../src/settling-groups.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,iGAAiG;AACjG,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,OAAO,IAAI,OAAO,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,mFAAmF;IACnF,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAClC,qGAAqG;IACrG,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,oBAAoB,CAAC,KAAK,SAAuB,GAAG,cAAc,CAwDjF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A publisher connection's settling groups (see CONTEXT.md): groups whose operation completed once
|
|
3
|
+
* the transport took their FIN, but whose FIN the relay has not acknowledged yet.
|
|
4
|
+
*
|
|
5
|
+
* Chromium refuses `createUnidirectionalStream()` once stream credit runs out instead of waiting
|
|
6
|
+
* for it, and settling groups are what can pile up on a connection: open streams are already
|
|
7
|
+
* bounded by one per track. So before an operation opens its stream it waits while the connection
|
|
8
|
+
* has {@link SETTLING_GROUP_LIMIT} settling groups, first come first served; it holds nothing while
|
|
9
|
+
* its stream is open, and its group joins the set once its FIN is handed over. The count can
|
|
10
|
+
* briefly exceed the limit by the number of groups open at that moment.
|
|
11
|
+
*
|
|
12
|
+
* A settling group that fails later (STOP_SENDING, a reset, session teardown) leaves the set like
|
|
13
|
+
* one that settles cleanly, and nobody hears of it: the cause surfaces as demand, a rebind, or the
|
|
14
|
+
* connection's `closed`. `publisher.close()` drains the set before it closes the transport, because
|
|
15
|
+
* Chromium resets every stream still awaiting its acknowledgment when the session goes.
|
|
16
|
+
*/
|
|
17
|
+
/** Settling groups per publisher connection before new streams wait. Internal, not an option. */
|
|
18
|
+
export const SETTLING_GROUP_LIMIT = 64;
|
|
19
|
+
export function createSettlingGroups(limit = SETTLING_GROUP_LIMIT) {
|
|
20
|
+
const settling = new Set();
|
|
21
|
+
const waiting = [];
|
|
22
|
+
// Every waiter goes on, in arrival order, once the connection is below the limit again.
|
|
23
|
+
const wake = () => {
|
|
24
|
+
while (waiting.length > 0 && settling.size < limit)
|
|
25
|
+
waiting.shift()?.();
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
hasRoom: () => settling.size < limit,
|
|
29
|
+
waitForRoom(interrupted) {
|
|
30
|
+
if (settling.size < limit)
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
waiting.push(resolve);
|
|
34
|
+
interrupted.catch((error) => {
|
|
35
|
+
const index = waiting.indexOf(resolve);
|
|
36
|
+
if (index === -1)
|
|
37
|
+
return;
|
|
38
|
+
waiting.splice(index, 1);
|
|
39
|
+
reject(error);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
add(settled) {
|
|
44
|
+
const tracked = settled.then(() => { }, () => { });
|
|
45
|
+
settling.add(tracked);
|
|
46
|
+
void tracked.then(() => {
|
|
47
|
+
settling.delete(tracked);
|
|
48
|
+
wake();
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
async drain(timeoutMs, stop) {
|
|
52
|
+
if (settling.size === 0)
|
|
53
|
+
return;
|
|
54
|
+
let timer;
|
|
55
|
+
try {
|
|
56
|
+
await Promise.race([
|
|
57
|
+
Promise.all(settling),
|
|
58
|
+
new Promise((resolve) => {
|
|
59
|
+
timer = setTimeout(resolve, timeoutMs);
|
|
60
|
+
}),
|
|
61
|
+
stop.then(() => { }, () => { }),
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
get size() {
|
|
69
|
+
return settling.size;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=settling-groups.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settling-groups.js","sourceRoot":"","sources":["../src/settling-groups.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,iGAAiG;AACjG,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAkBvC,MAAM,UAAU,oBAAoB,CAAC,KAAK,GAAG,oBAAoB;IAC/D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAiB,CAAC;IAC1C,MAAM,OAAO,GAAmB,EAAE,CAAC;IAEnC,wFAAwF;IACxF,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,CAAC,IAAI,GAAG,KAAK;YAAE,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,CAAC;IAC1E,CAAC,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,GAAG,KAAK;QACpC,WAAW,CAAC,WAAW;YACrB,IAAI,QAAQ,CAAC,IAAI,GAAG,KAAK;gBAAE,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C,EACR,GAAG,EAAE,GAAE,CAAC,CACT;iBACF,CAAC,CAAC;YACL,CAAC;oBAAS,CAAC;gBACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;QACD,IAAI,IAAI;YACN,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bounded events iterator: a single consumer that queues events with a capacity and owns one
|
|
3
|
+
* request, never the connection. `subscribeEvents` binds it to a subscription (see
|
|
4
|
+
* `subscription.ts`) and turns the subscription's ending into the three subscription error classes;
|
|
5
|
+
* `namespaceEvents` binds it to a namespace request (see `namespace-events.ts`).
|
|
6
|
+
*/
|
|
7
|
+
import { type ProductSubscription, type SubscriptionConsumer, type SubscriptionEvent } from './subscription.js';
|
|
8
|
+
export { SubscriptionConnectionClosedError, type SubscriptionEvent, SubscriptionOverflowError, SubscriptionRequestError, } from './subscription.js';
|
|
9
|
+
/** Options for `subscribeEvents`: the iterator's queue bound and its own cancellation. */
|
|
10
|
+
export interface SubscriptionEventOptions {
|
|
11
|
+
/** Maximum queued events (including lifecycle events). Positive integer; default 64. */
|
|
12
|
+
capacity?: number;
|
|
13
|
+
/** Cancels only this subscription. */
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
/** Single-consumer iterator owning one subscription, never the shared connection. */
|
|
17
|
+
export interface SubscriptionEvents extends AsyncIterableIterator<SubscriptionEvent> {
|
|
18
|
+
/** Discard queued events and settle pending reads as EOF. Idempotent. */
|
|
19
|
+
close(): void;
|
|
20
|
+
/** Called by `for await` on `break` or a throw: discards queued events, cancels the subscription, resolves done. */
|
|
21
|
+
return(): Promise<IteratorResult<SubscriptionEvent>>;
|
|
22
|
+
}
|
|
23
|
+
export declare function createSubscriptionEvents(subscribe: (consumer: SubscriptionConsumer) => ProductSubscription, options?: SubscriptionEventOptions): SubscriptionEvents;
|
|
24
|
+
/** Where a producer delivers into a bounded iterator. */
|
|
25
|
+
export interface BoundedEventSink<E> {
|
|
26
|
+
/** One event; past the capacity the iterator ends with `SubscriptionOverflowError`. */
|
|
27
|
+
event(event: E): void;
|
|
28
|
+
/**
|
|
29
|
+
* The producer ended: `undefined` finishes the iterator cleanly, anything else is thrown from `next()`. Either way
|
|
30
|
+
* the queue is discarded.
|
|
31
|
+
*/
|
|
32
|
+
ended(error?: unknown): void;
|
|
33
|
+
/** The producer finished cleanly: queued events are still read, then the iterator is done. */
|
|
34
|
+
complete(): void;
|
|
35
|
+
}
|
|
36
|
+
/** The single-consumer iterator both events forms share: an owned request, a queue bound and a signal. */
|
|
37
|
+
export interface BoundedEvents<E> extends AsyncIterableIterator<E> {
|
|
38
|
+
/** Discard queued events and settle pending reads as EOF. Idempotent. */
|
|
39
|
+
close(): void;
|
|
40
|
+
/** Called by `for await` on `break` or a throw: discards queued events, cancels the request, resolves done. */
|
|
41
|
+
return(): Promise<IteratorResult<E>>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The bounded iterator over one owned request. `start` opens the request and returns its cancel; an
|
|
45
|
+
* ending this iterator starts (close, return, abort, overflow) cancels it, and the echo of that
|
|
46
|
+
* cancel through the sink is ignored.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createBoundedEvents<E>(start: (sink: BoundedEventSink<E>) => {
|
|
49
|
+
cancel(reason?: unknown): void;
|
|
50
|
+
}, { capacity, signal }?: SubscriptionEventOptions): BoundedEvents<E>;
|
|
51
|
+
//# sourceMappingURL=subscription-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription-events.d.ts","sourceRoot":"","sources":["../src/subscription-events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,KAAK,mBAAmB,EAExB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EAGvB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,iCAAi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AAa,EAAE,MAAM,EAAE,GAAE,wBAA6B,GACvD,aAAa,CAAC,CAAC,CAAC,CAiFlB"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bounded events iterator: a single consumer that queues events with a capacity and owns one
|
|
3
|
+
* request, never the connection. `subscribeEvents` binds it to a subscription (see
|
|
4
|
+
* `subscription.ts`) and turns the subscription's ending into the three subscription error classes;
|
|
5
|
+
* `namespaceEvents` binds it to a namespace request (see `namespace-events.ts`).
|
|
6
|
+
*/
|
|
7
|
+
import { SubscriptionConnectionClosedError, SubscriptionOverflowError, SubscriptionRequestError, } from './subscription.js';
|
|
8
|
+
export { SubscriptionConnectionClosedError, SubscriptionOverflowError, SubscriptionRequestError, } from './subscription.js';
|
|
9
|
+
export function createSubscriptionEvents(subscribe, options = {}) {
|
|
10
|
+
return createBoundedEvents((sink) => subscribe({
|
|
11
|
+
event: (event) => sink.event(event),
|
|
12
|
+
ended(end) {
|
|
13
|
+
if (end.cause === 'request-error')
|
|
14
|
+
sink.ended(new SubscriptionRequestError(end.error));
|
|
15
|
+
else if (end.cause === 'connection-closed')
|
|
16
|
+
sink.ended(new SubscriptionConnectionClosedError(end.error));
|
|
17
|
+
else
|
|
18
|
+
sink.ended(end.error);
|
|
19
|
+
},
|
|
20
|
+
}), options);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The bounded iterator over one owned request. `start` opens the request and returns its cancel; an
|
|
24
|
+
* ending this iterator starts (close, return, abort, overflow) cancels it, and the echo of that
|
|
25
|
+
* cancel through the sink is ignored.
|
|
26
|
+
*/
|
|
27
|
+
export function createBoundedEvents(start, { capacity = 64, signal } = {}) {
|
|
28
|
+
if (typeof capacity !== 'number')
|
|
29
|
+
throw new TypeError('capacity must be a number');
|
|
30
|
+
if (!Number.isSafeInteger(capacity) || capacity <= 0)
|
|
31
|
+
throw new RangeError('capacity must be a positive integer');
|
|
32
|
+
let queue = [];
|
|
33
|
+
let pending;
|
|
34
|
+
let ended = false;
|
|
35
|
+
let failure;
|
|
36
|
+
let request;
|
|
37
|
+
const finish = (error) => {
|
|
38
|
+
if (ended)
|
|
39
|
+
return;
|
|
40
|
+
ended = true;
|
|
41
|
+
failure = error;
|
|
42
|
+
queue = [];
|
|
43
|
+
signal?.removeEventListener('abort', abort);
|
|
44
|
+
request?.cancel(error);
|
|
45
|
+
const read = pending;
|
|
46
|
+
pending = undefined;
|
|
47
|
+
if (error !== undefined)
|
|
48
|
+
read?.reject(error);
|
|
49
|
+
else
|
|
50
|
+
read?.resolve({ done: true, value: undefined });
|
|
51
|
+
};
|
|
52
|
+
const abort = () => finish(signal?.reason ?? new DOMException('Subscription aborted', 'AbortError'));
|
|
53
|
+
const sink = {
|
|
54
|
+
event(event) {
|
|
55
|
+
if (ended)
|
|
56
|
+
return;
|
|
57
|
+
if (pending) {
|
|
58
|
+
const read = pending;
|
|
59
|
+
pending = undefined;
|
|
60
|
+
read.resolve({ done: false, value: event });
|
|
61
|
+
}
|
|
62
|
+
else if (queue.length === capacity)
|
|
63
|
+
finish(new SubscriptionOverflowError());
|
|
64
|
+
else
|
|
65
|
+
queue.push(event);
|
|
66
|
+
},
|
|
67
|
+
ended(error) {
|
|
68
|
+
// An ending this iterator started (close, return, abort, overflow) echoes back here.
|
|
69
|
+
if (ended)
|
|
70
|
+
return;
|
|
71
|
+
finish(error);
|
|
72
|
+
},
|
|
73
|
+
complete() {
|
|
74
|
+
if (ended)
|
|
75
|
+
return;
|
|
76
|
+
// A pending read only exists while the queue is empty, so finishing settles it as done.
|
|
77
|
+
const rest = queue;
|
|
78
|
+
finish();
|
|
79
|
+
queue = rest;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
if (signal?.aborted)
|
|
83
|
+
abort();
|
|
84
|
+
else {
|
|
85
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
86
|
+
try {
|
|
87
|
+
request = start(sink);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
finish(error);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
// Events can overflow the queue before start() returns. The ending recorded then had no
|
|
94
|
+
// request to cancel, so cancel it now; the echo of that cancel is ignored above.
|
|
95
|
+
if (ended)
|
|
96
|
+
request.cancel(failure);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
[Symbol.asyncIterator]() {
|
|
100
|
+
return this;
|
|
101
|
+
},
|
|
102
|
+
next() {
|
|
103
|
+
if (pending)
|
|
104
|
+
return Promise.reject(new Error('Only one pending subscription read is supported'));
|
|
105
|
+
// Events left by a clean completion are read before the end.
|
|
106
|
+
if (queue.length > 0)
|
|
107
|
+
return Promise.resolve({ done: false, value: queue.shift() });
|
|
108
|
+
if (ended)
|
|
109
|
+
return failure === undefined ? Promise.resolve({ done: true, value: undefined }) : Promise.reject(failure);
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
pending = { resolve, reject };
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
close: () => {
|
|
115
|
+
finish();
|
|
116
|
+
queue = [];
|
|
117
|
+
},
|
|
118
|
+
async return() {
|
|
119
|
+
finish();
|
|
120
|
+
queue = [];
|
|
121
|
+
return { done: true, value: undefined };
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=subscription-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription-events.js","sourceRoot":"","sources":["../src/subscription-events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAEL,iCAAiC,EAGjC,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,iCAAiC,EAEjC,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAkB3B,MAAM,UAAU,wBAAwB,CACtC,SAAkE,EAClE,UAAoC,EAAE;IAEtC,OAAO,mBAAmB,CACxB,CAAC,IAAI,EAA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M;YACV,MAAM,EAAE,CAAC;YACT,KAAK,GAAG,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The application's subscription (see CONTEXT.md): one SUBSCRIBE request from creation to its
|
|
3
|
+
* terminal state, as distinct from demand, the relay's own subscription to a publisher.
|
|
4
|
+
*
|
|
5
|
+
* The module owns the core handle, the connection's closure observation and the terminal state, and
|
|
6
|
+
* translates the core's callbacks into product events once. Its consumers are the callback form
|
|
7
|
+
* (`RelaySubscriber.subscribe` with handlers) and the bounded events iterator; both attach through
|
|
8
|
+
* {@link SubscriptionConsumer} and see the same events and the same ending. Its public face is
|
|
9
|
+
* {@link RelaySubscription}: the core handle plus `subscribed` and `ended`, the readiness and
|
|
10
|
+
* termination awaitables. The pre-acceptance `update()` queue lives here too.
|
|
11
|
+
*/
|
|
12
|
+
import { type Goaway, type MessageParameters, type MoqtObject, type MoqtProtocolId, type PublishDone, type RequestError, type SubscribeOk, type Subscription, type SubscriptionHandlers } from '@caprid/moq-core';
|
|
13
|
+
import { RelayError } from './errors.js';
|
|
14
|
+
/** Delivery order is callback arrival order, with no ordering guarantee across streams. */
|
|
15
|
+
export type SubscriptionEvent = {
|
|
16
|
+
/** The relay accepted the subscription (SUBSCRIBE_OK). */
|
|
17
|
+
type: 'subscribed';
|
|
18
|
+
/** The acceptance info `onSubscribed` receives. */
|
|
19
|
+
value: SubscribeOk;
|
|
20
|
+
} | {
|
|
21
|
+
/** One object arrived, including an object that carries only a protocol status. */
|
|
22
|
+
type: 'object';
|
|
23
|
+
/** The object; its payload is uninterpreted bytes. */
|
|
24
|
+
value: MoqtObject;
|
|
25
|
+
} | {
|
|
26
|
+
/** The publisher finished with the track (PUBLISH_DONE). Not an ending: trailing objects can follow. */
|
|
27
|
+
type: 'publisherDone';
|
|
28
|
+
/** The done's status, stream count and reason. */
|
|
29
|
+
value: PublishDone;
|
|
30
|
+
} | {
|
|
31
|
+
/** A subgroup stream finished cleanly (FIN); only that subgroup ended. */
|
|
32
|
+
type: 'subgroupEnd';
|
|
33
|
+
/** Which subgroup ended. */
|
|
34
|
+
value: {
|
|
35
|
+
/** The group the subgroup belongs to. */
|
|
36
|
+
groupId: number;
|
|
37
|
+
/** The subgroup that ended. */
|
|
38
|
+
subgroupId: number;
|
|
39
|
+
/** Whether the subgroup's header marked it as holding the group's largest object. */
|
|
40
|
+
endOfGroup: boolean;
|
|
41
|
+
};
|
|
42
|
+
} | {
|
|
43
|
+
/** A subgroup stream was reset; objects from it may be missing. Delivery continues. */
|
|
44
|
+
type: 'subgroupReset';
|
|
45
|
+
/** Which group the reset stream carried, and why it failed. */
|
|
46
|
+
value: {
|
|
47
|
+
/** The group the reset subgroup belongs to. */
|
|
48
|
+
groupId: number;
|
|
49
|
+
/** The transport's stream error, as the runtime reported it. */
|
|
50
|
+
error: unknown;
|
|
51
|
+
};
|
|
52
|
+
} | {
|
|
53
|
+
/** The publisher changed subscription state on its own (PUBLISH_STATE_NOTIFY). */
|
|
54
|
+
type: 'stateNotify';
|
|
55
|
+
/** Only the parameters that changed. */
|
|
56
|
+
value: MessageParameters;
|
|
57
|
+
} | {
|
|
58
|
+
/** The relay sent GOAWAY on this request. Informational; the SDK does not retry. */
|
|
59
|
+
type: 'goaway';
|
|
60
|
+
/** The relay's suggested new session URI (may be empty) and timeout. */
|
|
61
|
+
value: Goaway;
|
|
62
|
+
} | {
|
|
63
|
+
/** The relay acknowledged an `update()` (REQUEST_OK). */
|
|
64
|
+
type: 'updateOk';
|
|
65
|
+
/** Always `undefined`; the acknowledgment carries nothing. */
|
|
66
|
+
value: undefined;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* The lifecycle name for how a subscription ended: `rejected` when the relay answered the request
|
|
70
|
+
* with REQUEST_ERROR before accepting it (including the request timeout), `terminated` when an
|
|
71
|
+
* accepted subscription can no longer deliver (the connection ended, or a REQUEST_ERROR arrived
|
|
72
|
+
* after acceptance, which is how a refused `update()` is answered, issue #94) or when the connection
|
|
73
|
+
* ended before any answer, and `cancelled` when the application cancelled it.
|
|
74
|
+
*/
|
|
75
|
+
export type SubscriptionEndKind = 'rejected' | 'terminated' | 'cancelled';
|
|
76
|
+
/**
|
|
77
|
+
* How a subscription ended. `kind` is the lifecycle name; `cause` is what happened on the wire or
|
|
78
|
+
* locally; `accepted` says whether SUBSCRIBE_OK had arrived; `error` is the REQUEST_ERROR, the
|
|
79
|
+
* connection's failure (undefined after a clean shutdown), or the cancel reason.
|
|
80
|
+
*/
|
|
81
|
+
export type SubscriptionEnd = {
|
|
82
|
+
/** `rejected` before SUBSCRIBE_OK, `terminated` after it. */
|
|
83
|
+
kind: 'rejected' | 'terminated';
|
|
84
|
+
/** The relay answered with REQUEST_ERROR, or the request timed out or its stream failed. */
|
|
85
|
+
cause: 'request-error';
|
|
86
|
+
/** Whether SUBSCRIBE_OK had arrived. */
|
|
87
|
+
accepted: boolean;
|
|
88
|
+
/** The REQUEST_ERROR, with its numeric code and reason. */
|
|
89
|
+
error: RequestError;
|
|
90
|
+
} | {
|
|
91
|
+
/** Always `terminated`, including when the connection ended before any answer. */
|
|
92
|
+
kind: 'terminated';
|
|
93
|
+
/** The connection ended, cleanly or not. */
|
|
94
|
+
cause: 'connection-closed';
|
|
95
|
+
/** Whether SUBSCRIBE_OK had arrived. */
|
|
96
|
+
accepted: boolean;
|
|
97
|
+
/** The connection's failure, or `undefined` after a clean shutdown. */
|
|
98
|
+
error: unknown;
|
|
99
|
+
} | {
|
|
100
|
+
/** The subscription was cancelled locally. */
|
|
101
|
+
kind: 'cancelled';
|
|
102
|
+
/** `cancel()` ran, called directly or by an events iterator that closed, aborted or overflowed. */
|
|
103
|
+
cause: 'cancelled';
|
|
104
|
+
/** Whether SUBSCRIBE_OK had arrived. */
|
|
105
|
+
accepted: boolean;
|
|
106
|
+
/** The cancel reason, or `undefined` when none was given. */
|
|
107
|
+
error: unknown;
|
|
108
|
+
};
|
|
109
|
+
/** The handle `RelaySubscriber.subscribe()` returns: the core handle plus readiness and termination. */
|
|
110
|
+
export interface RelaySubscription extends Subscription {
|
|
111
|
+
/**
|
|
112
|
+
* Settles when the relay answers. Resolves with the acceptance info `onSubscribed` receives.
|
|
113
|
+
* Rejects with {@link SubscriptionRequestError} when the relay rejected the request or it timed
|
|
114
|
+
* out, {@link SubscriptionConnectionClosedError} when the connection ended first, or the reason
|
|
115
|
+
* given to `cancel()` (a `CLOSED` RelayError when none was given). Never rejects after acceptance.
|
|
116
|
+
*/
|
|
117
|
+
readonly subscribed: Promise<SubscribeOk>;
|
|
118
|
+
/**
|
|
119
|
+
* Settles once, when the subscription can no longer deliver, with how it ended. Never rejects.
|
|
120
|
+
* Publisher completion (`onPublisherDone`) is not an ending: trailing objects can still arrive,
|
|
121
|
+
* and the request stays open until `cancel()` or the connection ends. Neither awaitable implies
|
|
122
|
+
* exactly-once or gap-free delivery.
|
|
123
|
+
*/
|
|
124
|
+
readonly ended: Promise<SubscriptionEnd>;
|
|
125
|
+
}
|
|
126
|
+
/** One consumer of a subscription: the handler object or an events iterator. */
|
|
127
|
+
export interface SubscriptionConsumer {
|
|
128
|
+
/** One product event, delivered synchronously as the core delivers it. */
|
|
129
|
+
event(event: SubscriptionEvent): void;
|
|
130
|
+
/** The subscription ended; no event follows. Delivered once. */
|
|
131
|
+
ended(end: SubscriptionEnd): void;
|
|
132
|
+
}
|
|
133
|
+
/** What the subscription borrows from the connection. */
|
|
134
|
+
export interface SubscriptionDependencies {
|
|
135
|
+
/** The core session's subscribe, already bound to the track options. */
|
|
136
|
+
subscribe(handlers: SubscriptionHandlers): Subscription;
|
|
137
|
+
/** The connection's negotiated MOQT version, which `update()` encodes for. */
|
|
138
|
+
protocol: MoqtProtocolId;
|
|
139
|
+
/**
|
|
140
|
+
* Observe the connection's closure in the turn it happens, ahead of the request failures the
|
|
141
|
+
* core synthesizes while tearing down. The returned function removes the observer.
|
|
142
|
+
*/
|
|
143
|
+
observeClosed(observer: (error?: unknown) => void): () => void;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* How long a pre-acceptance stream failure waits for the transport to report closure before it is
|
|
147
|
+
* recorded as a rejection. Chromium reports closure well under a millisecond after it fails the
|
|
148
|
+
* stream (issue #102); this only bounds the wait on a connection that stays up.
|
|
149
|
+
*/
|
|
150
|
+
export declare const CLOSURE_GRACE_MS = 250;
|
|
151
|
+
/** The product subscription as its consumers see it: the public handle plus the attach point. */
|
|
152
|
+
export interface ProductSubscription extends RelaySubscription {
|
|
153
|
+
/** Attach a consumer; one attached after the end is told the end at once. Returns the detach. */
|
|
154
|
+
attach(consumer: SubscriptionConsumer): () => void;
|
|
155
|
+
/** Whether SUBSCRIBE_OK has arrived. */
|
|
156
|
+
readonly accepted: boolean;
|
|
157
|
+
/** How the subscription ended, once it has. */
|
|
158
|
+
readonly end: SubscriptionEnd | undefined;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* An events iterator's queue was full when another event arrived. Code `SUBSCRIPTION_OVERFLOW`, phase
|
|
162
|
+
* `subscription`. The iterator discards its queue and cancels its subscription; it does not drop the
|
|
163
|
+
* event and continue.
|
|
164
|
+
*/
|
|
165
|
+
export declare class SubscriptionOverflowError extends RelayError {
|
|
166
|
+
/** `'SubscriptionOverflowError'`. */
|
|
167
|
+
readonly name = "SubscriptionOverflowError";
|
|
168
|
+
constructor();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The relay answered the subscription with REQUEST_ERROR, or the request timed out or failed before
|
|
172
|
+
* acceptance. Code `SUBSCRIPTION_REQUEST_FAILED`, phase `subscription`; `message` is the REQUEST_ERROR's reason phrase.
|
|
173
|
+
*/
|
|
174
|
+
export declare class SubscriptionRequestError extends RelayError {
|
|
175
|
+
/** `'SubscriptionRequestError'`. */
|
|
176
|
+
readonly name = "SubscriptionRequestError";
|
|
177
|
+
/** The MOQT REQUEST_ERROR as the callback form's `onError` receives it, with its numeric code. */
|
|
178
|
+
readonly requestError: RequestError;
|
|
179
|
+
/** @param requestError The REQUEST_ERROR to wrap. */
|
|
180
|
+
constructor(requestError: RequestError);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The connection ended while the subscription was open, including a clean local close. Code `CLOSED`,
|
|
184
|
+
* phase `connection`; `cause` is the connection's failure when there was one. Never a claim that
|
|
185
|
+
* delivery drained.
|
|
186
|
+
*/
|
|
187
|
+
export declare class SubscriptionConnectionClosedError extends RelayError {
|
|
188
|
+
/** `'SubscriptionConnectionClosedError'`. */
|
|
189
|
+
readonly name = "SubscriptionConnectionClosedError";
|
|
190
|
+
/** @param cause The connection's failure, if any. */
|
|
191
|
+
constructor(cause?: unknown);
|
|
192
|
+
}
|
|
193
|
+
/** The error `subscribed` rejects with for an ending that came before acceptance. */
|
|
194
|
+
export declare function endError(end: SubscriptionEnd): unknown;
|
|
195
|
+
/**
|
|
196
|
+
* Snapshot one product callback and hold it to the synchronous callback policy: an async function
|
|
197
|
+
* is refused before any request is sent, and a returned promise is observed and diagnosed once,
|
|
198
|
+
* never awaited by delivery. Mirrors the core's own guard, which now only sees this module's lambdas.
|
|
199
|
+
*/
|
|
200
|
+
export declare function synchronousCallback(name: string, callback: (...args: never[]) => unknown, receiver: unknown): (...args: unknown[]) => void;
|
|
201
|
+
/**
|
|
202
|
+
* How many `update()` calls may wait for SUBSCRIBE_OK. REQUEST_UPDATE is legal only on an accepted
|
|
203
|
+
* subscription (draft-ietf-moq-transport-22 §3.1), so earlier updates queue here in order.
|
|
204
|
+
*/
|
|
205
|
+
export declare const UPDATE_QUEUE_BOUND = 8;
|
|
206
|
+
export declare function createSubscription(deps: SubscriptionDependencies, initial?: readonly SubscriptionConsumer[]): ProductSubscription;
|
|
207
|
+
//# sourceMappingURL=subscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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