@moq/net 0.1.9 → 0.2.1
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/announced.d.ts +40 -24
- package/announced.d.ts.map +1 -1
- package/announced.js +74 -40
- package/announced.js.map +1 -1
- package/announced.test.d.ts +2 -0
- package/announced.test.d.ts.map +1 -0
- package/announced.test.js +37 -0
- package/announced.test.js.map +1 -0
- package/broadcast.d.ts +80 -25
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +266 -49
- package/broadcast.js.map +1 -1
- package/broadcast.test.d.ts +2 -0
- package/broadcast.test.d.ts.map +1 -0
- package/broadcast.test.js +219 -0
- package/broadcast.test.js.map +1 -0
- package/connection/accept.d.ts +6 -0
- package/connection/accept.d.ts.map +1 -1
- package/connection/accept.js +30 -10
- package/connection/accept.js.map +1 -1
- package/connection/browser.d.ts +5 -0
- package/connection/browser.d.ts.map +1 -0
- package/connection/browser.js +25 -0
- package/connection/browser.js.map +1 -0
- package/connection/browser.test.d.ts +2 -0
- package/connection/browser.test.d.ts.map +1 -0
- package/connection/browser.test.js +29 -0
- package/connection/browser.test.js.map +1 -0
- package/connection/connect.d.ts +43 -1
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +96 -107
- package/connection/connect.js.map +1 -1
- package/connection/connect.test.d.ts +2 -0
- package/connection/connect.test.d.ts.map +1 -0
- package/connection/connect.test.js +118 -0
- package/connection/connect.test.js.map +1 -0
- package/connection/established.d.ts +29 -15
- package/connection/established.d.ts.map +1 -1
- package/connection/established.js.map +1 -1
- package/connection/index.d.ts +8 -0
- package/connection/index.d.ts.map +1 -1
- package/connection/index.js +6 -0
- package/connection/index.js.map +1 -1
- package/connection/reload.d.ts +43 -7
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +159 -62
- package/connection/reload.js.map +1 -1
- package/connection/reload.test.js +65 -0
- package/connection/reload.test.js.map +1 -1
- package/connection/stats.d.ts +92 -0
- package/connection/stats.d.ts.map +1 -0
- package/connection/stats.js +35 -0
- package/connection/stats.js.map +1 -0
- package/connection/stats.test.d.ts +2 -0
- package/connection/stats.test.d.ts.map +1 -0
- package/connection/stats.test.js +120 -0
- package/connection/stats.test.js.map +1 -0
- package/connection/transport.d.ts +10 -0
- package/connection/transport.d.ts.map +1 -0
- package/connection/transport.js +12 -0
- package/connection/transport.js.map +1 -0
- package/consume.d.ts +26 -0
- package/consume.d.ts.map +1 -0
- package/consume.js +40 -0
- package/consume.js.map +1 -0
- package/datagram.d.ts +23 -0
- package/datagram.d.ts.map +1 -0
- package/datagram.js +3 -0
- package/datagram.js.map +1 -0
- package/error.d.ts +62 -0
- package/error.d.ts.map +1 -0
- package/error.js +92 -0
- package/error.js.map +1 -0
- package/error.test.d.ts +2 -0
- package/error.test.d.ts.map +1 -0
- package/error.test.js +89 -0
- package/error.test.js.map +1 -0
- package/group.d.ts +125 -36
- package/group.d.ts.map +1 -1
- package/group.js +244 -67
- package/group.js.map +1 -1
- package/group.test.js +121 -35
- package/group.test.js.map +1 -1
- package/ietf/adapter.d.ts +2 -2
- package/ietf/adapter.d.ts.map +1 -1
- package/ietf/adapter.js +15 -5
- package/ietf/adapter.js.map +1 -1
- package/ietf/connection.d.ts +19 -6
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +23 -8
- package/ietf/connection.js.map +1 -1
- package/ietf/ietf.test.js +58 -1
- package/ietf/ietf.test.js.map +1 -1
- package/ietf/object.d.ts +12 -4
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +92 -9
- package/ietf/object.js.map +1 -1
- package/ietf/publisher.d.ts +2 -2
- package/ietf/publisher.d.ts.map +1 -1
- package/ietf/publisher.js +12 -12
- package/ietf/publisher.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts +0 -4
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +0 -5
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.d.ts +8 -4
- package/ietf/subscriber.d.ts.map +1 -1
- package/ietf/subscriber.js +171 -93
- package/ietf/subscriber.js.map +1 -1
- package/index.d.ts +10 -5
- package/index.d.ts.map +1 -1
- package/index.js +10 -5
- package/index.js.map +1 -1
- package/integration.test.js +634 -12
- package/integration.test.js.map +1 -1
- package/internal.d.ts +14 -0
- package/internal.d.ts.map +1 -0
- package/internal.js +8 -0
- package/internal.js.map +1 -0
- package/lite/announce.d.ts +55 -13
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +221 -68
- package/lite/announce.js.map +1 -1
- package/lite/announce.test.d.ts +2 -0
- package/lite/announce.test.d.ts.map +1 -0
- package/lite/announce.test.js +71 -0
- package/lite/announce.test.js.map +1 -0
- package/lite/connection.d.ts +45 -19
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +85 -80
- package/lite/connection.js.map +1 -1
- package/lite/datagram.d.ts +23 -0
- package/lite/datagram.d.ts.map +1 -0
- package/lite/datagram.js +57 -0
- package/lite/datagram.js.map +1 -0
- package/lite/datagram.test.d.ts +2 -0
- package/lite/datagram.test.d.ts.map +1 -0
- package/lite/datagram.test.js +26 -0
- package/lite/datagram.test.js.map +1 -0
- package/lite/datagram_stream.d.ts +8 -0
- package/lite/datagram_stream.d.ts.map +1 -0
- package/lite/datagram_stream.js +44 -0
- package/lite/datagram_stream.js.map +1 -0
- package/lite/datagram_stream.test.d.ts +2 -0
- package/lite/datagram_stream.test.d.ts.map +1 -0
- package/lite/datagram_stream.test.js +15 -0
- package/lite/datagram_stream.test.js.map +1 -0
- package/lite/fetch.d.ts.map +1 -1
- package/lite/fetch.js +2 -2
- package/lite/fetch.js.map +1 -1
- package/lite/fetch.test.d.ts +2 -0
- package/lite/fetch.test.d.ts.map +1 -0
- package/lite/fetch.test.js +41 -0
- package/lite/fetch.test.js.map +1 -0
- package/lite/index.d.ts +3 -0
- package/lite/index.d.ts.map +1 -1
- package/lite/index.js +3 -0
- package/lite/index.js.map +1 -1
- package/lite/publisher.d.ts +13 -6
- package/lite/publisher.d.ts.map +1 -1
- package/lite/publisher.js +274 -64
- package/lite/publisher.js.map +1 -1
- package/lite/publisher.test.d.ts +2 -0
- package/lite/publisher.test.d.ts.map +1 -0
- package/lite/publisher.test.js +65 -0
- package/lite/publisher.test.js.map +1 -0
- package/lite/setup.d.ts +72 -6
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +184 -31
- package/lite/setup.js.map +1 -1
- package/lite/setup.test.d.ts +2 -0
- package/lite/setup.test.d.ts.map +1 -0
- package/lite/setup.test.js +122 -0
- package/lite/setup.test.js.map +1 -0
- package/lite/stream.d.ts +12 -3
- package/lite/stream.d.ts.map +1 -1
- package/lite/stream.js +7 -4
- package/lite/stream.js.map +1 -1
- package/lite/subscribe.d.ts +37 -23
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +70 -55
- package/lite/subscribe.js.map +1 -1
- package/lite/subscribe.test.d.ts +2 -0
- package/lite/subscribe.test.d.ts.map +1 -0
- package/lite/subscribe.test.js +68 -0
- package/lite/subscribe.test.js.map +1 -0
- package/lite/subscriber.d.ts +24 -17
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +515 -90
- package/lite/subscriber.js.map +1 -1
- package/lite/subscriber.test.js +2 -2
- package/lite/subscriber.test.js.map +1 -1
- package/lite/track.d.ts +25 -13
- package/lite/track.d.ts.map +1 -1
- package/lite/track.js +60 -35
- package/lite/track.js.map +1 -1
- package/lite/track.test.js +12 -10
- package/lite/track.test.js.map +1 -1
- package/lite/version.d.ts +17 -4
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +88 -17
- package/lite/version.js.map +1 -1
- package/mock.d.ts +42 -3
- package/mock.d.ts.map +1 -1
- package/mock.js +88 -17
- package/mock.js.map +1 -1
- package/package.json +3 -3
- package/path.d.ts +30 -0
- package/path.d.ts.map +1 -1
- package/path.js +49 -0
- package/path.js.map +1 -1
- package/path.test.js +41 -0
- package/path.test.js.map +1 -1
- package/stream.d.ts.map +1 -1
- package/stream.js +25 -4
- package/stream.js.map +1 -1
- package/stream.test.js +42 -0
- package/stream.test.js.map +1 -1
- package/time.d.ts +109 -86
- package/time.d.ts.map +1 -1
- package/time.js +80 -30
- package/time.js.map +1 -1
- package/time.test.d.ts +2 -0
- package/time.test.d.ts.map +1 -0
- package/time.test.js +12 -0
- package/time.test.js.map +1 -0
- package/track.d.ts +225 -45
- package/track.d.ts.map +1 -1
- package/track.js +505 -93
- package/track.js.map +1 -1
- package/track.test.js +138 -29
- package/track.test.js.map +1 -1
- package/util/timeout.d.ts +5 -0
- package/util/timeout.d.ts.map +1 -0
- package/util/timeout.js +18 -0
- package/util/timeout.js.map +1 -0
- package/util/timeout.test.d.ts +2 -0
- package/util/timeout.test.d.ts.map +1 -0
- package/util/timeout.test.js +18 -0
- package/util/timeout.test.js.map +1 -0
- package/varint.d.ts +6 -0
- package/varint.d.ts.map +1 -1
- package/varint.js +6 -2
- package/varint.js.map +1 -1
- package/zod.d.ts +4 -4
- package/zod.d.ts.map +1 -1
- package/zod.js.map +1 -1
- package/bandwidth.d.ts +0 -11
- package/bandwidth.d.ts.map +0 -1
- package/bandwidth.js +0 -7
- package/bandwidth.js.map +0 -1
- package/util/error.d.ts +0 -3
- package/util/error.d.ts.map +0 -1
- package/util/error.js +0 -9
- package/util/error.js.map +0 -1
- package/util/index.d.ts +0 -2
- package/util/index.d.ts.map +0 -1
- package/util/index.js +0 -3
- package/util/index.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.test.d.ts","sourceRoot":"","sources":["../../src/lite/fetch.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* @ts-self-types="./fetch.test.d.ts" */
|
|
2
|
+
import { expect, test } from "bun:test";
|
|
3
|
+
import * as Path from "../path.js";
|
|
4
|
+
import { Reader, Writer } from "../stream.js";
|
|
5
|
+
import { Fetch } from "./fetch.js";
|
|
6
|
+
import { Version } from "./version.js";
|
|
7
|
+
function concat(chunks) {
|
|
8
|
+
const total = chunks.reduce((sum, c) => sum + c.byteLength, 0);
|
|
9
|
+
const out = new Uint8Array(total);
|
|
10
|
+
let offset = 0;
|
|
11
|
+
for (const c of chunks) {
|
|
12
|
+
out.set(c, offset);
|
|
13
|
+
offset += c.byteLength;
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
async function encode(version, fetch) {
|
|
18
|
+
const written = [];
|
|
19
|
+
const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
|
|
20
|
+
await fetch.encode(writer, version);
|
|
21
|
+
writer.close();
|
|
22
|
+
await writer.closed;
|
|
23
|
+
return concat(written);
|
|
24
|
+
}
|
|
25
|
+
async function roundtrip(version, fetch) {
|
|
26
|
+
const reader = new Reader(undefined, await encode(version, fetch));
|
|
27
|
+
return Fetch.decode(reader, version);
|
|
28
|
+
}
|
|
29
|
+
function sample() {
|
|
30
|
+
return new Fetch(Path.from("room/1"), "video", 3, 42);
|
|
31
|
+
}
|
|
32
|
+
test("Fetch round-trips on draft-03/04/05", async () => {
|
|
33
|
+
for (const version of [Version.DRAFT_03, Version.DRAFT_04, Version.DRAFT_05]) {
|
|
34
|
+
const got = await roundtrip(version, sample());
|
|
35
|
+
expect(got.broadcast).toBe(Path.from("room/1"));
|
|
36
|
+
expect(got.track).toBe("video");
|
|
37
|
+
expect(got.priority).toBe(3);
|
|
38
|
+
expect(got.group).toBe(42);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=fetch.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.test.js","sourceRoot":"","sources":["../../src/lite/fetch.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,SAAS,MAAM,CAAC,MAAoB;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACxB,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACnB,MAAM,IAAI,CAAC,CAAC,UAAU,CAAC;IACxB,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,KAAK,UAAU,MAAM,CAAC,OAAgB,EAAE,KAAY;IACnD,MAAM,OAAO,GAAiB,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,MAAM,CACxB,IAAI,cAAc,CAAa,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAC9F,CAAC;IACF,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,MAAM,CAAC,KAAK,EAAE,CAAC;IACf,MAAM,MAAM,CAAC,MAAM,CAAC;IACpB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;AACxB,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,OAAgB,EAAE,KAAY;IACtD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,SAAS,EAAE,MAAM,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IACnE,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,MAAM;IACd,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AACvD,CAAC;AAED,IAAI,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;IACtD,KAAK,MAAM,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9E,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/C,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAChD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7B,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC;AACF,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Path from \"../path.ts\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport { Fetch } from \"./fetch.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n\tconst total = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const c of chunks) {\n\t\tout.set(c, offset);\n\t\toffset += c.byteLength;\n\t}\n\treturn out;\n}\n\nasync function encode(version: Version, fetch: Fetch): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait fetch.encode(writer, version);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\nasync function roundtrip(version: Version, fetch: Fetch): Promise<Fetch> {\n\tconst reader = new Reader(undefined, await encode(version, fetch));\n\treturn Fetch.decode(reader, version);\n}\n\nfunction sample(): Fetch {\n\treturn new Fetch(Path.from(\"room/1\"), \"video\", 3, 42);\n}\n\ntest(\"Fetch round-trips on draft-03/04/05\", async () => {\n\tfor (const version of [Version.DRAFT_03, Version.DRAFT_04, Version.DRAFT_05]) {\n\t\tconst got = await roundtrip(version, sample());\n\t\texpect(got.broadcast).toBe(Path.from(\"room/1\"));\n\t\texpect(got.track).toBe(\"video\");\n\t\texpect(got.priority).toBe(3);\n\t\texpect(got.group).toBe(42);\n\t}\n});\n"]}
|
package/lite/index.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
export * from "./announce";
|
|
2
2
|
export * from "./connection";
|
|
3
|
+
export * from "./datagram";
|
|
3
4
|
export * from "./fetch";
|
|
4
5
|
export * from "./goaway";
|
|
5
6
|
export * from "./group";
|
|
6
7
|
export * from "./probe";
|
|
7
8
|
export * from "./session";
|
|
9
|
+
export * from "./setup";
|
|
8
10
|
export * from "./stream";
|
|
9
11
|
export * from "./subscribe";
|
|
12
|
+
export * from "./track";
|
|
10
13
|
export * from "./version";
|
|
11
14
|
//# sourceMappingURL=index.d.ts.map
|
package/lite/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lite/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lite/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
package/lite/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/* @ts-self-types="./index.d.ts" */
|
|
2
2
|
export * from "./announce.js";
|
|
3
3
|
export * from "./connection.js";
|
|
4
|
+
export * from "./datagram.js";
|
|
4
5
|
export * from "./fetch.js";
|
|
5
6
|
export * from "./goaway.js";
|
|
6
7
|
export * from "./group.js";
|
|
7
8
|
export * from "./probe.js";
|
|
8
9
|
export * from "./session.js";
|
|
10
|
+
export * from "./setup.js";
|
|
9
11
|
export * from "./stream.js";
|
|
10
12
|
export * from "./subscribe.js";
|
|
13
|
+
export * from "./track.js";
|
|
11
14
|
export * from "./version.js";
|
|
12
15
|
//# sourceMappingURL=index.js.map
|
package/lite/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lite/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./announce.ts\";\nexport * from \"./connection.ts\";\nexport * from \"./fetch.ts\";\nexport * from \"./goaway.ts\";\nexport * from \"./group.ts\";\nexport * from \"./probe.ts\";\nexport * from \"./session.ts\";\nexport * from \"./stream.ts\";\nexport * from \"./subscribe.ts\";\nexport * from \"./version.ts\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lite/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./announce.ts\";\nexport * from \"./connection.ts\";\nexport * from \"./datagram.ts\";\nexport * from \"./fetch.ts\";\nexport * from \"./goaway.ts\";\nexport * from \"./group.ts\";\nexport * from \"./probe.ts\";\nexport * from \"./session.ts\";\nexport * from \"./setup.ts\";\nexport * from \"./stream.ts\";\nexport * from \"./subscribe.ts\";\nexport * from \"./track.ts\";\nexport * from \"./version.ts\";\n"]}
|
package/lite/publisher.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type * as broadcast from "../broadcast";
|
|
2
2
|
import * as Path from "../path";
|
|
3
3
|
import { type Stream } from "../stream";
|
|
4
|
-
import { type
|
|
4
|
+
import { type AnnounceRequest } from "./announce";
|
|
5
|
+
import type { Fetch } from "./fetch";
|
|
5
6
|
import type { Origin } from "./origin";
|
|
6
7
|
import { type Subscribe } from "./subscribe";
|
|
7
|
-
import type
|
|
8
|
+
import { type Track as TrackMessage } from "./track";
|
|
8
9
|
import { Version } from "./version";
|
|
9
10
|
/**
|
|
10
11
|
* Handles publishing broadcasts and managing their lifecycle.
|
|
@@ -28,7 +29,7 @@ export declare class Publisher {
|
|
|
28
29
|
* Publishes a broadcast with any associated tracks.
|
|
29
30
|
* @param name - The broadcast to publish
|
|
30
31
|
*/
|
|
31
|
-
publish(path: Path.Valid, broadcast:
|
|
32
|
+
publish(path: Path.Valid, broadcast: broadcast.Producer): void;
|
|
32
33
|
/**
|
|
33
34
|
* Handles an announce interest message.
|
|
34
35
|
* @param msg - The announce interest message
|
|
@@ -36,7 +37,7 @@ export declare class Publisher {
|
|
|
36
37
|
*
|
|
37
38
|
* @internal
|
|
38
39
|
*/
|
|
39
|
-
runAnnounce(msg:
|
|
40
|
+
runAnnounce(msg: AnnounceRequest, stream: Stream): Promise<void>;
|
|
40
41
|
/**
|
|
41
42
|
* Handles a subscribe message.
|
|
42
43
|
* @param msg - The subscribe message
|
|
@@ -46,7 +47,13 @@ export declare class Publisher {
|
|
|
46
47
|
*/
|
|
47
48
|
runSubscribe(msg: Subscribe, stream: Stream): Promise<void>;
|
|
48
49
|
/**
|
|
49
|
-
*
|
|
50
|
+
* Handles a FETCH stream by serving one group as bare frame records (lite-05+).
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
runFetch(msg: Fetch, stream: Stream): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Answers a TRACK stream (0x6) with a single TRACK_INFO, then FINs.
|
|
50
57
|
*
|
|
51
58
|
* @internal
|
|
52
59
|
*/
|
package/lite/publisher.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publisher.d.ts","sourceRoot":"","sources":["../../src/lite/publisher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"publisher.d.ts","sourceRoot":"","sources":["../../src/lite/publisher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAGlD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,MAAM,EAAU,MAAM,cAAc,CAAC;AAGnD,OAAO,EAA4B,KAAK,eAAe,EAA2B,MAAM,eAAe,CAAC;AAGxG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAEN,KAAK,SAAS,EAKd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAiC,KAAK,KAAK,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AACvF,OAAO,EAA8C,OAAO,EAAE,MAAM,cAAc,CAAC;AAyBnF;;;;GAIG;AACH,qBAAa,SAAS;;IAErB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAM1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAoBxB;;;;;;;OAOG;IACH,YAAY,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAU/D;IAED;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,QAAQ,QAYtD;IAED;;;;;;OAMG;IACG,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,iBA2GrD;IAED;;;;;;OAMG;IACG,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,iBAwEhD;IAED;;;;OAIG;IACG,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBA8BxC;IAuDD;;;;OAIG;IACG,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,iBAUnD;IAyID;;;;;OAKG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,iBAmD5B;IAED,KAAK,SAWJ;CACD"}
|
package/lite/publisher.js
CHANGED
|
@@ -1,17 +1,37 @@
|
|
|
1
1
|
/* @ts-self-types="./publisher.d.ts" */
|
|
2
2
|
import { Signal } from "@moq/signals";
|
|
3
|
+
import { error, reason } from "../error.js";
|
|
3
4
|
import * as Path from "../path.js";
|
|
4
5
|
import { Writer } from "../stream.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { Timescale } from "../time.js";
|
|
7
|
+
import { AnnounceInit, AnnounceOk, encodeAnnounceBroadcast } from "./announce.js";
|
|
8
|
+
import { Datagram as DatagramMessage } from "./datagram.js";
|
|
9
|
+
import * as DatagramStream from "./datagram_stream.js";
|
|
7
10
|
import { Group as GroupMessage } from "./group.js";
|
|
8
11
|
import { Probe } from "./probe.js";
|
|
9
|
-
import { encodeSubscribeResponse, SubscribeEnd, SubscribeOk, SubscribeUpdate } from "./subscribe.js";
|
|
10
|
-
import { TrackInfo } from "./track.js";
|
|
11
|
-
import {
|
|
12
|
+
import { encodeSubscribeResponse, SubscribeEnd, SubscribeOk, SubscribeStart, SubscribeUpdate, } from "./subscribe.js";
|
|
13
|
+
import { TrackInfo as TrackInfoMessage } from "./track.js";
|
|
14
|
+
import { hasAnnounceId, hasAnnounceOk, hasDatagrams, Version } from "./version.js";
|
|
12
15
|
const PROBE_INTERVAL = 100; // ms
|
|
13
16
|
const PROBE_MAX_AGE = 10_000; // ms
|
|
14
17
|
const PROBE_MAX_DELTA = 0.25;
|
|
18
|
+
/** Map a signed delta to an unsigned zigzag varint value (mirrors Rust `VarInt::from_zigzag`). */
|
|
19
|
+
function zigzag(delta) {
|
|
20
|
+
return delta >= 0n ? delta << 1n : (-delta << 1n) - 1n;
|
|
21
|
+
}
|
|
22
|
+
// The TRACK stream, implicit SUBSCRIBE acceptance, and SUBSCRIBE_START/END are
|
|
23
|
+
// all lite-05+.
|
|
24
|
+
function supportsTrackStream(version) {
|
|
25
|
+
switch (version) {
|
|
26
|
+
case Version.DRAFT_01:
|
|
27
|
+
case Version.DRAFT_02:
|
|
28
|
+
case Version.DRAFT_03:
|
|
29
|
+
case Version.DRAFT_04:
|
|
30
|
+
return false;
|
|
31
|
+
default:
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
15
35
|
/**
|
|
16
36
|
* Handles publishing broadcasts and managing their lifecycle.
|
|
17
37
|
*
|
|
@@ -26,9 +46,19 @@ export class Publisher {
|
|
|
26
46
|
// own announcements.
|
|
27
47
|
origin;
|
|
28
48
|
#quic;
|
|
49
|
+
// The one writer for the outbound datagram stream (getWriter locks it), acquired once at
|
|
50
|
+
// construction when this version + transport carry datagrams, released in close(). Its
|
|
51
|
+
// presence is the gate: undefined means datagrams aren't served on this connection. All
|
|
52
|
+
// subscriptions share it, since a second getWriter on the same stream would throw.
|
|
53
|
+
#datagramWriter;
|
|
29
54
|
// Our published broadcasts.
|
|
30
55
|
// It's a signal so we can live update any announce streams.
|
|
31
56
|
#broadcasts = new Signal(new Map());
|
|
57
|
+
// TRACK_INFO is immutable per track, so resolve it from the application once
|
|
58
|
+
// (via a throwaway subscribe whose info() resolves when the app calls accept)
|
|
59
|
+
// and reuse it for every later TRACK request of the same track. Keyed by
|
|
60
|
+
// `broadcast\0track`. A rejected lookup is evicted so a retry can re-probe.
|
|
61
|
+
#trackInfo = new Map();
|
|
32
62
|
/**
|
|
33
63
|
* Creates a new Publisher instance.
|
|
34
64
|
* @param quic - The WebTransport session to use
|
|
@@ -41,6 +71,11 @@ export class Publisher {
|
|
|
41
71
|
this.#quic = quic;
|
|
42
72
|
this.version = version;
|
|
43
73
|
this.origin = origin;
|
|
74
|
+
// Grab the datagram writer up front when the transport carries datagrams (no group
|
|
75
|
+
// fallback, so it stays undefined otherwise). One writer for all subscriptions.
|
|
76
|
+
if (hasDatagrams(version)) {
|
|
77
|
+
this.#datagramWriter = DatagramStream.datagramWriter(quic);
|
|
78
|
+
}
|
|
44
79
|
}
|
|
45
80
|
/**
|
|
46
81
|
* Publishes a broadcast with any associated tracks.
|
|
@@ -53,7 +88,7 @@ export class Publisher {
|
|
|
53
88
|
broadcasts.set(path, broadcast);
|
|
54
89
|
});
|
|
55
90
|
// Remove the broadcast from the lookup when it's closed.
|
|
56
|
-
void broadcast.closed.
|
|
91
|
+
void broadcast.closed.then(() => {
|
|
57
92
|
this.#broadcasts.mutate((broadcasts) => {
|
|
58
93
|
broadcasts?.delete(path);
|
|
59
94
|
});
|
|
@@ -80,6 +115,10 @@ export class Publisher {
|
|
|
80
115
|
console.debug(`announce: broadcast=${name} active=true`);
|
|
81
116
|
active.add(suffix);
|
|
82
117
|
}
|
|
118
|
+
// Lite06+: announce ids. Every active we send implicitly assigns the next
|
|
119
|
+
// per-stream ordinal; ended references the id instead of repeating the path.
|
|
120
|
+
let nextAnnounceId = 0n;
|
|
121
|
+
const announceIds = new Map();
|
|
83
122
|
switch (this.version) {
|
|
84
123
|
case Version.DRAFT_01:
|
|
85
124
|
case Version.DRAFT_02: {
|
|
@@ -87,13 +126,26 @@ export class Publisher {
|
|
|
87
126
|
await init.encode(stream.writer, this.version);
|
|
88
127
|
break;
|
|
89
128
|
}
|
|
90
|
-
default:
|
|
91
|
-
|
|
129
|
+
default: {
|
|
130
|
+
if (!hasAnnounceOk(this.version)) {
|
|
131
|
+
// Draft03/04: send individual Announce messages, stamping our origin as a hop.
|
|
132
|
+
for (const suffix of active) {
|
|
133
|
+
await encodeAnnounceBroadcast(stream.writer, { status: "active", suffix, hops: [this.origin] }, this.version);
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
// Report our origin id once via AnnounceOk and the count of initial announces
|
|
138
|
+
// that follow; the subscriber stamps our origin onto each hop chain, so we omit it.
|
|
139
|
+
const ok = new AnnounceOk(this.origin, active.size);
|
|
140
|
+
await ok.encode(stream.writer, this.version);
|
|
92
141
|
for (const suffix of active) {
|
|
93
|
-
|
|
94
|
-
|
|
142
|
+
if (hasAnnounceId(this.version)) {
|
|
143
|
+
announceIds.set(suffix, nextAnnounceId++);
|
|
144
|
+
}
|
|
145
|
+
await encodeAnnounceBroadcast(stream.writer, { status: "active", suffix, hops: [] }, this.version);
|
|
95
146
|
}
|
|
96
147
|
break;
|
|
148
|
+
}
|
|
97
149
|
}
|
|
98
150
|
// Wait for updates to the broadcasts.
|
|
99
151
|
for (;;) {
|
|
@@ -116,18 +168,30 @@ export class Publisher {
|
|
|
116
168
|
continue; // Not our prefix.
|
|
117
169
|
newActive.add(suffix);
|
|
118
170
|
}
|
|
119
|
-
// Announce any new broadcasts.
|
|
171
|
+
// Announce any new broadcasts. Lite05+ reports our origin once via AnnounceOk, so
|
|
172
|
+
// the subscriber stamps it onto each hop chain; older versions stamp it here.
|
|
120
173
|
for (const added of newActive.difference(active)) {
|
|
121
174
|
console.debug(`announce: broadcast=${added} active=true`);
|
|
122
|
-
const
|
|
123
|
-
|
|
175
|
+
const hops = hasAnnounceOk(this.version) ? [] : [this.origin];
|
|
176
|
+
if (hasAnnounceId(this.version)) {
|
|
177
|
+
announceIds.set(added, nextAnnounceId++);
|
|
178
|
+
}
|
|
179
|
+
await encodeAnnounceBroadcast(stream.writer, { status: "active", suffix: added, hops }, this.version);
|
|
124
180
|
}
|
|
125
|
-
// Announce any removed broadcasts.
|
|
126
|
-
//
|
|
181
|
+
// Announce any removed broadcasts. Lite06+ retracts by announce id;
|
|
182
|
+
// older versions repeat the path (ended announces don't need hops).
|
|
127
183
|
for (const removed of active.difference(newActive)) {
|
|
128
184
|
console.debug(`announce: broadcast=${removed} active=false`);
|
|
129
|
-
|
|
130
|
-
|
|
185
|
+
if (hasAnnounceId(this.version)) {
|
|
186
|
+
const id = announceIds.get(removed);
|
|
187
|
+
announceIds.delete(removed);
|
|
188
|
+
if (id === undefined)
|
|
189
|
+
continue; // never announced
|
|
190
|
+
await encodeAnnounceBroadcast(stream.writer, { status: "endedId", id }, this.version);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
await encodeAnnounceBroadcast(stream.writer, { status: "ended", suffix: removed }, this.version);
|
|
194
|
+
}
|
|
131
195
|
}
|
|
132
196
|
// NOTE: This is kind of a hack that won't work with a rapid UNANNOUNCE/ANNOUNCE cycle.
|
|
133
197
|
// However, our client doesn't do that anyway.
|
|
@@ -148,16 +212,38 @@ export class Publisher {
|
|
|
148
212
|
stream.writer.reset(new Error("not found"));
|
|
149
213
|
return;
|
|
150
214
|
}
|
|
151
|
-
const track = broadcast.subscribe(msg.track, msg.priority);
|
|
215
|
+
const track = broadcast.subscribe(msg.track, { priority: msg.priority });
|
|
216
|
+
// The best-effort datagram loop, started once serving begins. It parks when the
|
|
217
|
+
// track finishes (recvDatagram returns undefined), so #runTrack alone ends the
|
|
218
|
+
// subscription; awaited during teardown so it doesn't outlive the subscription.
|
|
219
|
+
let datagrams;
|
|
152
220
|
try {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
221
|
+
let timescale = Timescale.MILLI;
|
|
222
|
+
if (supportsTrackStream(this.version)) {
|
|
223
|
+
// Lite-05+ accepts implicitly: no SUBSCRIBE_OK (the immutable
|
|
224
|
+
// properties live in TRACK_INFO), and the resolved range arrives as
|
|
225
|
+
// SUBSCRIBE_START / SUBSCRIBE_END emitted from #runTrack.
|
|
226
|
+
//
|
|
227
|
+
// The timescale is an immutable property, so serving MUST use exactly
|
|
228
|
+
// what TRACK_INFO advertised. It comes from the producer's accept(), so
|
|
229
|
+
// they always agree. Awaiting info() also surfaces a rejected track
|
|
230
|
+
// (accept never called, track closed) as an error here, which resets the
|
|
231
|
+
// stream.
|
|
232
|
+
const info = await track.info();
|
|
233
|
+
timescale = info.timescale;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// Older drafts acknowledge with SUBSCRIBE_OK and stream frames verbatim.
|
|
237
|
+
const ok = new SubscribeOk({ priority: msg.priority });
|
|
238
|
+
await encodeSubscribeResponse(stream.writer, { ok }, this.version);
|
|
239
|
+
}
|
|
159
240
|
console.debug(`publish ok: broadcast=${msg.broadcast} track=${track.name}`);
|
|
160
|
-
const serving = this.#runTrack(msg.id, msg.broadcast, track, stream.writer);
|
|
241
|
+
const serving = this.#runTrack(msg.id, msg.broadcast, track, stream.writer, timescale);
|
|
242
|
+
// Serve datagrams concurrently with groups whenever the transport carries them
|
|
243
|
+
// (the writer exists iff so). No group fallback: otherwise they simply aren't sent.
|
|
244
|
+
if (this.#datagramWriter) {
|
|
245
|
+
datagrams = this.#runDatagrams(msg.id, track, timescale);
|
|
246
|
+
}
|
|
161
247
|
for (;;) {
|
|
162
248
|
const decode = SubscribeUpdate.decodeMaybe(stream.reader, this.version);
|
|
163
249
|
const result = await Promise.any([serving, decode]);
|
|
@@ -165,34 +251,55 @@ export class Publisher {
|
|
|
165
251
|
break;
|
|
166
252
|
if (result instanceof SubscribeUpdate) {
|
|
167
253
|
console.debug(`subscribe update: broadcast=${msg.broadcast} track=${track.name} priority=${result.priority}`);
|
|
168
|
-
track.
|
|
254
|
+
track.update({ priority: result.priority });
|
|
169
255
|
}
|
|
170
256
|
}
|
|
171
257
|
console.debug(`publish done: broadcast=${msg.broadcast} track=${track.name}`);
|
|
172
258
|
stream.close();
|
|
173
259
|
track.close();
|
|
260
|
+
// track.close ends the datagram loop; wait so it doesn't leak past teardown.
|
|
261
|
+
await datagrams;
|
|
174
262
|
}
|
|
175
263
|
catch (err) {
|
|
176
264
|
const e = error(err);
|
|
177
|
-
console.warn(`publish error: broadcast=${msg.broadcast} track=${track.name} error=${e
|
|
265
|
+
console.warn(`publish error: broadcast=${msg.broadcast} track=${track.name} error=${reason(e)}`);
|
|
178
266
|
track.close(e);
|
|
179
267
|
stream.abort(e);
|
|
268
|
+
await datagrams;
|
|
180
269
|
}
|
|
181
270
|
}
|
|
182
271
|
/**
|
|
183
|
-
*
|
|
272
|
+
* Handles a FETCH stream by serving one group as bare frame records (lite-05+).
|
|
184
273
|
*
|
|
185
274
|
* @internal
|
|
186
275
|
*/
|
|
187
|
-
async
|
|
276
|
+
async runFetch(msg, stream) {
|
|
277
|
+
if (!supportsTrackStream(this.version)) {
|
|
278
|
+
stream.writer.reset(new Error("fetch requires moq-lite-05 or newer"));
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
188
281
|
const broadcast = this.#broadcasts.peek()?.get(msg.broadcast);
|
|
189
282
|
if (!broadcast) {
|
|
190
|
-
|
|
283
|
+
console.debug(`fetch unknown: broadcast=${msg.broadcast}`);
|
|
284
|
+
stream.writer.reset(new Error("not found"));
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
let group;
|
|
288
|
+
try {
|
|
289
|
+
// The timescale is immutable, so serve exactly what TRACK_INFO advertised.
|
|
290
|
+
const info = await this.#resolveTrackInfo(msg.broadcast, msg.track);
|
|
291
|
+
group = await broadcast.track(msg.track).fetchGroup(msg.group, { priority: msg.priority });
|
|
292
|
+
await this.#runFetchGroup(group, stream.writer, Timescale(info.timescale));
|
|
293
|
+
console.debug(`fetch done: broadcast=${msg.broadcast} track=${msg.track} group=${msg.group}`);
|
|
294
|
+
stream.close();
|
|
295
|
+
group.close();
|
|
296
|
+
}
|
|
297
|
+
catch (err) {
|
|
298
|
+
const e = error(err);
|
|
299
|
+
console.warn(`fetch error: broadcast=${msg.broadcast} track=${msg.track} group=${msg.group} error=${reason(e)}`);
|
|
300
|
+
group?.close(e);
|
|
301
|
+
stream.abort(e);
|
|
191
302
|
}
|
|
192
|
-
// The publisher properties aren't tracked in the browser model yet; report
|
|
193
|
-
// defaults with a millisecond timescale matching the wall-clock frame timestamps.
|
|
194
|
-
const info = new TrackInfo({ timescale: 1000 });
|
|
195
|
-
await info.encode(stream.writer, this.version);
|
|
196
303
|
}
|
|
197
304
|
/**
|
|
198
305
|
* Runs a track and sends its data to the stream.
|
|
@@ -203,31 +310,32 @@ export class Publisher {
|
|
|
203
310
|
*
|
|
204
311
|
* @internal
|
|
205
312
|
*/
|
|
206
|
-
async #runTrack(sub, broadcast, track, stream) {
|
|
313
|
+
async #runTrack(sub, broadcast, track, stream, timescale) {
|
|
314
|
+
// Lite-05+ resolves the range on the subscribe stream: SUBSCRIBE_START once the
|
|
315
|
+
// first group is known, SUBSCRIBE_END when the track finishes.
|
|
316
|
+
const emitRange = supportsTrackStream(this.version);
|
|
317
|
+
let startSent = false;
|
|
318
|
+
// The exclusive end of the delivered range. recvGroup is arrival-ordered rather than
|
|
319
|
+
// sequence-ordered, so this tracks the max and not the last group seen. 0 is already
|
|
320
|
+
// the encoding for a track that produced no groups.
|
|
321
|
+
let end = 0;
|
|
207
322
|
try {
|
|
208
|
-
let lastSequence;
|
|
209
|
-
let trackEnded = false;
|
|
210
323
|
for (;;) {
|
|
211
324
|
const next = track.recvGroup();
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
stream.closed.then(() => "closed"),
|
|
215
|
-
]);
|
|
216
|
-
if (res === "closed") {
|
|
325
|
+
const group = await Promise.race([next, stream.closed]);
|
|
326
|
+
if (!group) {
|
|
217
327
|
next.then((group) => group?.close()).catch(() => { });
|
|
218
328
|
break;
|
|
219
329
|
}
|
|
220
|
-
if (!
|
|
221
|
-
|
|
222
|
-
|
|
330
|
+
if (emitRange && !startSent) {
|
|
331
|
+
startSent = true;
|
|
332
|
+
await encodeSubscribeResponse(stream, { start: new SubscribeStart(group.sequence) }, this.version);
|
|
223
333
|
}
|
|
224
|
-
|
|
225
|
-
void this.#runGroup(sub,
|
|
334
|
+
end = Math.max(end, group.sequence + 1);
|
|
335
|
+
void this.#runGroup(sub, group, timescale);
|
|
226
336
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const end = new SubscribeEnd({ group: lastSequence ?? 0 });
|
|
230
|
-
await encodeSubscribeResponse(stream, { end }, this.version);
|
|
337
|
+
if (emitRange) {
|
|
338
|
+
await encodeSubscribeResponse(stream, { end: new SubscribeEnd(end) }, this.version);
|
|
231
339
|
}
|
|
232
340
|
console.debug(`publish close: broadcast=${broadcast} track=${track.name}`);
|
|
233
341
|
track.close();
|
|
@@ -235,11 +343,94 @@ export class Publisher {
|
|
|
235
343
|
}
|
|
236
344
|
catch (err) {
|
|
237
345
|
const e = error(err);
|
|
238
|
-
console.warn(`publish error: broadcast=${broadcast} track=${track.name} error=${e
|
|
346
|
+
console.warn(`publish error: broadcast=${broadcast} track=${track.name} error=${reason(e)}`);
|
|
239
347
|
track.close(e);
|
|
240
348
|
stream.reset(e);
|
|
241
349
|
}
|
|
242
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* Answers a TRACK stream (0x6) with a single TRACK_INFO, then FINs.
|
|
353
|
+
*
|
|
354
|
+
* @internal
|
|
355
|
+
*/
|
|
356
|
+
async runTrackInfo(msg, stream) {
|
|
357
|
+
try {
|
|
358
|
+
const info = await this.#resolveTrackInfo(msg.broadcast, msg.track);
|
|
359
|
+
await info.encode(stream.writer, this.version);
|
|
360
|
+
console.debug(`track info: broadcast=${msg.broadcast} track=${msg.track}`);
|
|
361
|
+
stream.close();
|
|
362
|
+
}
|
|
363
|
+
catch (err) {
|
|
364
|
+
console.debug(`track unknown: broadcast=${msg.broadcast} track=${msg.track}`);
|
|
365
|
+
stream.writer.reset(error(err));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// Resolve (and cache) a track's immutable TRACK_INFO by asking the application.
|
|
369
|
+
// `broadcast.track(name).info()` triggers a TrackRequest the app answers with
|
|
370
|
+
// accept(TrackInfo); only the immutable properties are needed (not the groups).
|
|
371
|
+
// Cached because they're fixed for the track's lifetime. Rejects if the broadcast
|
|
372
|
+
// or track is unavailable.
|
|
373
|
+
#resolveTrackInfo(broadcast, track) {
|
|
374
|
+
const key = `${broadcast}\0${track}`;
|
|
375
|
+
const cached = this.#trackInfo.get(key);
|
|
376
|
+
if (cached)
|
|
377
|
+
return cached;
|
|
378
|
+
const pending = (async () => {
|
|
379
|
+
const published = this.#broadcasts.peek()?.get(broadcast);
|
|
380
|
+
if (!published)
|
|
381
|
+
throw new Error("not found");
|
|
382
|
+
const info = await published.track(track).info();
|
|
383
|
+
return new TrackInfoMessage({
|
|
384
|
+
priority: info.priority,
|
|
385
|
+
ordered: info.ordered,
|
|
386
|
+
// Publisher Max Latency: the publisher's retention bound, advertised so
|
|
387
|
+
// relays re-serve with the same window.
|
|
388
|
+
latencyMax: info.latencyMax,
|
|
389
|
+
// Lite05 mandates per-frame timestamps. Advertise the track's timescale;
|
|
390
|
+
// `#runGroup` emits each frame converted to it.
|
|
391
|
+
timescale: info.timescale,
|
|
392
|
+
});
|
|
393
|
+
})();
|
|
394
|
+
// Don't poison the cache on failure: a later request may succeed.
|
|
395
|
+
pending.catch(() => this.#trackInfo.delete(key));
|
|
396
|
+
this.#trackInfo.set(key, pending);
|
|
397
|
+
return pending;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Forwards a track's datagrams best-effort over QUIC datagrams (lite-05 §6.4), parallel to
|
|
401
|
+
* its groups. Each datagram is dropped (there is no group fallback) if the encoded body
|
|
402
|
+
* doesn't fit the transport's datagram limit or the send fails. Returns once the track
|
|
403
|
+
* finishes; a failure never tears down the subscription.
|
|
404
|
+
*
|
|
405
|
+
* @internal
|
|
406
|
+
*/
|
|
407
|
+
async #runDatagrams(sub, track, timescale) {
|
|
408
|
+
const writer = this.#datagramWriter;
|
|
409
|
+
if (!writer)
|
|
410
|
+
return; // Only reached with a writer (see the #datagramWriter gate).
|
|
411
|
+
const maxSize = DatagramStream.maxDatagramSize(this.#quic);
|
|
412
|
+
try {
|
|
413
|
+
for (;;) {
|
|
414
|
+
const datagram = await track.recvDatagram();
|
|
415
|
+
if (!datagram)
|
|
416
|
+
return; // Track finished; #runTrack tears the subscription down.
|
|
417
|
+
// Convert the timestamp to the track's advertised timescale, matching #runGroup.
|
|
418
|
+
const ts = Math.round(datagram.timestamp.as(timescale));
|
|
419
|
+
const body = new DatagramMessage(sub, datagram.sequence, ts, datagram.payload).encode();
|
|
420
|
+
// No group fallback: drop anything that doesn't fit a single datagram.
|
|
421
|
+
if (body.byteLength > maxSize) {
|
|
422
|
+
console.debug(`dropping oversize datagram: sub=${sub} size=${body.byteLength} max=${maxSize}`);
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
await writer.ready;
|
|
426
|
+
await writer.write(body);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
catch (err) {
|
|
430
|
+
// Best-effort: a datagram send failure stops sending but never fails the subscription.
|
|
431
|
+
console.debug(`datagram send stopped: sub=${sub} error=${reason(err)}`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
243
434
|
/**
|
|
244
435
|
* Runs a group and sends its frames to the stream.
|
|
245
436
|
* @param sub - The subscription ID
|
|
@@ -247,28 +438,44 @@ export class Publisher {
|
|
|
247
438
|
*
|
|
248
439
|
* @internal
|
|
249
440
|
*/
|
|
250
|
-
|
|
441
|
+
// Serialize a fetched group's frames onto the FETCH stream as bare records: each a
|
|
442
|
+
// zigzag-delta timestamp (at the track's advertised timescale) followed by size + bytes.
|
|
443
|
+
async #runFetchGroup(group, stream, timescale) {
|
|
444
|
+
let prevTs = 0n;
|
|
445
|
+
for (;;) {
|
|
446
|
+
const frame = await Promise.race([group.readFrame(), stream.closed]);
|
|
447
|
+
if (!frame)
|
|
448
|
+
break;
|
|
449
|
+
const ts = BigInt(Math.round(frame.timestamp.as(timescale)));
|
|
450
|
+
await stream.u62(zigzag(ts - prevTs));
|
|
451
|
+
prevTs = ts;
|
|
452
|
+
await stream.u53(frame.payload.byteLength);
|
|
453
|
+
await stream.write(frame.payload);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
async #runGroup(sub, group, timescale) {
|
|
251
457
|
const msg = new GroupMessage(sub, group.sequence);
|
|
252
458
|
try {
|
|
253
459
|
const stream = await Writer.open(this.#quic);
|
|
254
|
-
await stream.
|
|
460
|
+
await stream.u53(0); // stream type
|
|
255
461
|
await msg.encode(stream);
|
|
462
|
+
// Lite05+ prefixes every frame with a zigzag-delta timestamp at the track's
|
|
463
|
+
// advertised timescale; older drafts omit it.
|
|
464
|
+
const timestamps = supportsTrackStream(this.version);
|
|
465
|
+
let prevTs = 0n;
|
|
256
466
|
try {
|
|
257
|
-
// moq-lite-05+ stamps each frame with a wall-clock millisecond timestamp, sent
|
|
258
|
-
// as a zigzag delta from the previous frame (the first frame is a delta from 0).
|
|
259
|
-
let prevTimestamp = 0n;
|
|
260
467
|
for (;;) {
|
|
261
468
|
const frame = await Promise.race([group.readFrame(), stream.closed]);
|
|
262
469
|
if (!frame)
|
|
263
470
|
break;
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
471
|
+
if (timestamps) {
|
|
472
|
+
// Convert each frame to the track's advertised timescale.
|
|
473
|
+
const ts = BigInt(Math.round(frame.timestamp.as(timescale)));
|
|
474
|
+
await stream.u62(zigzag(ts - prevTs));
|
|
475
|
+
prevTs = ts;
|
|
269
476
|
}
|
|
270
|
-
await stream.u53(frame.byteLength);
|
|
271
|
-
await stream.write(frame);
|
|
477
|
+
await stream.u53(frame.payload.byteLength);
|
|
478
|
+
await stream.write(frame.payload);
|
|
272
479
|
}
|
|
273
480
|
stream.close();
|
|
274
481
|
group.close();
|
|
@@ -345,6 +552,9 @@ export class Publisher {
|
|
|
345
552
|
}
|
|
346
553
|
return undefined;
|
|
347
554
|
});
|
|
555
|
+
// Release the datagram writer's lock so the stream can be torn down.
|
|
556
|
+
this.#datagramWriter?.releaseLock();
|
|
557
|
+
this.#datagramWriter = undefined;
|
|
348
558
|
}
|
|
349
559
|
}
|
|
350
560
|
//# sourceMappingURL=publisher.js.map
|