@moq/net 0.2.6 → 0.2.8

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.
Files changed (170) hide show
  1. package/connection/accept.js +8 -3
  2. package/connection/accept.js.map +1 -1
  3. package/connection/connect.d.ts.map +1 -1
  4. package/connection/connect.js +5 -2
  5. package/connection/connect.js.map +1 -1
  6. package/connection/handshake.d.ts +9 -1
  7. package/connection/handshake.d.ts.map +1 -1
  8. package/connection/handshake.js +18 -14
  9. package/connection/handshake.js.map +1 -1
  10. package/ietf/adapter.js +2 -2
  11. package/ietf/adapter.js.map +1 -1
  12. package/ietf/connection.d.ts +7 -1
  13. package/ietf/connection.d.ts.map +1 -1
  14. package/ietf/connection.js +23 -3
  15. package/ietf/connection.js.map +1 -1
  16. package/ietf/index.d.ts +1 -0
  17. package/ietf/index.d.ts.map +1 -1
  18. package/ietf/index.js +1 -0
  19. package/ietf/index.js.map +1 -1
  20. package/ietf/parameters.d.ts +1 -0
  21. package/ietf/parameters.d.ts.map +1 -1
  22. package/ietf/parameters.js +2 -0
  23. package/ietf/parameters.js.map +1 -1
  24. package/ietf/publisher.d.ts +22 -8
  25. package/ietf/publisher.d.ts.map +1 -1
  26. package/ietf/publisher.js +294 -77
  27. package/ietf/publisher.js.map +1 -1
  28. package/ietf/solicit.d.ts +41 -0
  29. package/ietf/solicit.d.ts.map +1 -0
  30. package/ietf/solicit.js +47 -0
  31. package/ietf/solicit.js.map +1 -0
  32. package/ietf/subscriber.d.ts +4 -0
  33. package/ietf/subscriber.d.ts.map +1 -1
  34. package/ietf/subscriber.js +122 -50
  35. package/ietf/subscriber.js.map +1 -1
  36. package/lite/priority.d.ts +67 -0
  37. package/lite/priority.d.ts.map +1 -0
  38. package/lite/priority.js +114 -0
  39. package/lite/priority.js.map +1 -0
  40. package/lite/publisher.d.ts.map +1 -1
  41. package/lite/publisher.js +73 -18
  42. package/lite/publisher.js.map +1 -1
  43. package/lite/subscriber.d.ts.map +1 -1
  44. package/lite/subscriber.js +5 -4
  45. package/lite/subscriber.js.map +1 -1
  46. package/mock.d.ts +13 -2
  47. package/mock.d.ts.map +1 -1
  48. package/mock.js +22 -4
  49. package/mock.js.map +1 -1
  50. package/package.json +2 -2
  51. package/stream.d.ts +94 -4
  52. package/stream.d.ts.map +1 -1
  53. package/stream.js +100 -8
  54. package/stream.js.map +1 -1
  55. package/track.d.ts +20 -7
  56. package/track.d.ts.map +1 -1
  57. package/track.js +63 -27
  58. package/track.js.map +1 -1
  59. package/announced.test.d.ts +0 -2
  60. package/announced.test.d.ts.map +0 -1
  61. package/announced.test.js +0 -37
  62. package/announced.test.js.map +0 -1
  63. package/broadcast.test.d.ts +0 -2
  64. package/broadcast.test.d.ts.map +0 -1
  65. package/broadcast.test.js +0 -243
  66. package/broadcast.test.js.map +0 -1
  67. package/connection/browser.test.d.ts +0 -2
  68. package/connection/browser.test.d.ts.map +0 -1
  69. package/connection/browser.test.js +0 -29
  70. package/connection/browser.test.js.map +0 -1
  71. package/connection/cert.test.d.ts +0 -2
  72. package/connection/cert.test.d.ts.map +0 -1
  73. package/connection/cert.test.js +0 -26
  74. package/connection/cert.test.js.map +0 -1
  75. package/connection/connect.test.d.ts +0 -2
  76. package/connection/connect.test.d.ts.map +0 -1
  77. package/connection/connect.test.js +0 -118
  78. package/connection/connect.test.js.map +0 -1
  79. package/connection/reload.test.d.ts +0 -2
  80. package/connection/reload.test.d.ts.map +0 -1
  81. package/connection/reload.test.js +0 -160
  82. package/connection/reload.test.js.map +0 -1
  83. package/connection/stats.test.d.ts +0 -2
  84. package/connection/stats.test.d.ts.map +0 -1
  85. package/connection/stats.test.js +0 -120
  86. package/connection/stats.test.js.map +0 -1
  87. package/error.test.d.ts +0 -2
  88. package/error.test.d.ts.map +0 -1
  89. package/error.test.js +0 -89
  90. package/error.test.js.map +0 -1
  91. package/group.test.d.ts +0 -2
  92. package/group.test.d.ts.map +0 -1
  93. package/group.test.js +0 -152
  94. package/group.test.js.map +0 -1
  95. package/ietf/aliases.test.d.ts +0 -2
  96. package/ietf/aliases.test.d.ts.map +0 -1
  97. package/ietf/aliases.test.js +0 -30
  98. package/ietf/aliases.test.js.map +0 -1
  99. package/ietf/ietf.test.d.ts +0 -2
  100. package/ietf/ietf.test.d.ts.map +0 -1
  101. package/ietf/ietf.test.js +0 -983
  102. package/ietf/ietf.test.js.map +0 -1
  103. package/ietf/priority.test.d.ts +0 -2
  104. package/ietf/priority.test.d.ts.map +0 -1
  105. package/ietf/priority.test.js +0 -18
  106. package/ietf/priority.test.js.map +0 -1
  107. package/integration.test.d.ts +0 -2
  108. package/integration.test.d.ts.map +0 -1
  109. package/integration.test.js +0 -1006
  110. package/integration.test.js.map +0 -1
  111. package/lite/announce.test.d.ts +0 -2
  112. package/lite/announce.test.d.ts.map +0 -1
  113. package/lite/announce.test.js +0 -91
  114. package/lite/announce.test.js.map +0 -1
  115. package/lite/datagram.test.d.ts +0 -2
  116. package/lite/datagram.test.d.ts.map +0 -1
  117. package/lite/datagram.test.js +0 -26
  118. package/lite/datagram.test.js.map +0 -1
  119. package/lite/datagram_stream.test.d.ts +0 -2
  120. package/lite/datagram_stream.test.d.ts.map +0 -1
  121. package/lite/datagram_stream.test.js +0 -15
  122. package/lite/datagram_stream.test.js.map +0 -1
  123. package/lite/fetch.test.d.ts +0 -2
  124. package/lite/fetch.test.d.ts.map +0 -1
  125. package/lite/fetch.test.js +0 -41
  126. package/lite/fetch.test.js.map +0 -1
  127. package/lite/publisher.test.d.ts +0 -2
  128. package/lite/publisher.test.d.ts.map +0 -1
  129. package/lite/publisher.test.js +0 -65
  130. package/lite/publisher.test.js.map +0 -1
  131. package/lite/setup.test.d.ts +0 -2
  132. package/lite/setup.test.d.ts.map +0 -1
  133. package/lite/setup.test.js +0 -134
  134. package/lite/setup.test.js.map +0 -1
  135. package/lite/subscribe.test.d.ts +0 -2
  136. package/lite/subscribe.test.d.ts.map +0 -1
  137. package/lite/subscribe.test.js +0 -110
  138. package/lite/subscribe.test.js.map +0 -1
  139. package/lite/subscriber.test.d.ts +0 -2
  140. package/lite/subscriber.test.d.ts.map +0 -1
  141. package/lite/subscriber.test.js +0 -108
  142. package/lite/subscriber.test.js.map +0 -1
  143. package/lite/track.test.d.ts +0 -2
  144. package/lite/track.test.d.ts.map +0 -1
  145. package/lite/track.test.js +0 -55
  146. package/lite/track.test.js.map +0 -1
  147. package/path.test.d.ts +0 -2
  148. package/path.test.d.ts.map +0 -1
  149. package/path.test.js +0 -210
  150. package/path.test.js.map +0 -1
  151. package/stream.test.d.ts +0 -2
  152. package/stream.test.d.ts.map +0 -1
  153. package/stream.test.js +0 -252
  154. package/stream.test.js.map +0 -1
  155. package/time.test.d.ts +0 -2
  156. package/time.test.d.ts.map +0 -1
  157. package/time.test.js +0 -12
  158. package/time.test.js.map +0 -1
  159. package/track.test.d.ts +0 -2
  160. package/track.test.d.ts.map +0 -1
  161. package/track.test.js +0 -212
  162. package/track.test.js.map +0 -1
  163. package/util/timeout.test.d.ts +0 -2
  164. package/util/timeout.test.d.ts.map +0 -1
  165. package/util/timeout.test.js +0 -18
  166. package/util/timeout.test.js.map +0 -1
  167. package/varint.test.d.ts +0 -2
  168. package/varint.test.d.ts.map +0 -1
  169. package/varint.test.js +0 -106
  170. package/varint.test.js.map +0 -1
@@ -1,134 +0,0 @@
1
- /* @ts-self-types="./setup.test.d.ts" */
2
- import { expect, test } from "bun:test";
3
- import { Reader, Writer } from "../stream.js";
4
- import * as Varint from "../varint.js";
5
- import { OriginSchema } from "./origin.js";
6
- import { ProbeLevel, Role, Setup } from "./setup.js";
7
- import { Version } from "./version.js";
8
- // Parameter ids, duplicated from setup.ts so a typo there fails a test rather than
9
- // silently agreeing with itself.
10
- const PARAM_PROBE = 0x1n;
11
- const PARAM_PATH = 0x2n;
12
- const PARAM_ROLE = 0x3n;
13
- const PARAM_ORIGIN = 0x5n;
14
- function concat(chunks) {
15
- const total = chunks.reduce((sum, c) => sum + c.byteLength, 0);
16
- const out = new Uint8Array(total);
17
- let offset = 0;
18
- for (const c of chunks) {
19
- out.set(c, offset);
20
- offset += c.byteLength;
21
- }
22
- return out;
23
- }
24
- async function bytes(f) {
25
- const written = [];
26
- const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
27
- await f(writer);
28
- writer.close();
29
- await writer.closed;
30
- return concat(written);
31
- }
32
- async function roundTrip(msg) {
33
- const reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));
34
- const got = await Setup.decode(reader, Version.DRAFT_05);
35
- expect(await reader.done()).toBe(true);
36
- return got;
37
- }
38
- // Hand-frame a SETUP carrying a single raw parameter, so we can feed the decoder values
39
- // our own encoder would never produce (unknown levels, empty paths).
40
- async function decodeParam(id, value) {
41
- const body = await bytes(async (w) => {
42
- await w.u53(1); // parameter count
43
- await w.u62(id);
44
- await w.u53(value.byteLength);
45
- if (value.byteLength > 0)
46
- await w.write(value);
47
- });
48
- const framed = await bytes(async (w) => {
49
- await w.u53(body.byteLength); // Message size prefix
50
- await w.write(body);
51
- });
52
- return await Setup.decode(new Reader(undefined, framed), Version.DRAFT_05);
53
- }
54
- test("empty SETUP round-trips on draft-05", async () => {
55
- const got = await roundTrip(new Setup());
56
- expect(got.probe).toBe(ProbeLevel.None);
57
- expect(got.path).toBeUndefined();
58
- expect(got.role).toBe(Role.Both);
59
- });
60
- test("each probe level round-trips on draft-05", async () => {
61
- for (const probe of [ProbeLevel.None, ProbeLevel.Report, ProbeLevel.Increase]) {
62
- const got = await roundTrip(new Setup({ probe }));
63
- expect(got.probe).toBe(probe);
64
- expect(got.path).toBeUndefined();
65
- }
66
- });
67
- test("SETUP with path round-trips on draft-05", async () => {
68
- const got = await roundTrip(new Setup({ probe: ProbeLevel.Report, path: "/room/123" }));
69
- expect(got.probe).toBe(ProbeLevel.Report);
70
- expect(got.path).toBe("/room/123");
71
- });
72
- test("each role round-trips on draft-05", async () => {
73
- for (const role of [Role.Both, Role.Publisher, Role.Subscriber]) {
74
- const got = await roundTrip(new Setup({ role }));
75
- expect(got.role).toBe(role);
76
- }
77
- });
78
- test("SETUP carries role alongside probe and path", async () => {
79
- const got = await roundTrip(new Setup({ probe: ProbeLevel.Increase, path: "/room/123", role: Role.Publisher }));
80
- expect(got.probe).toBe(ProbeLevel.Increase);
81
- expect(got.path).toBe("/room/123");
82
- expect(got.role).toBe(Role.Publisher);
83
- });
84
- test("Both is the wire default, so it is omitted rather than encoded", async () => {
85
- // Both must be the absence of the parameter, so a server that predates it decodes a
86
- // Both client back to Both. Assert the empty bag directly: comparing against another
87
- // default-constructed Setup would agree with itself even if we encoded Both.
88
- const both = await bytes((w) => new Setup({ role: Role.Both }).encode(w, Version.DRAFT_05));
89
- const emptyBag = await bytes(async (w) => {
90
- await w.u53(1); // Message size prefix: one byte of body follows
91
- await w.u53(0); // parameter count
92
- });
93
- expect(both).toEqual(emptyBag);
94
- // A directional role is still encoded, so the check above can actually fail.
95
- const publisher = await bytes((w) => new Setup({ role: Role.Publisher }).encode(w, Version.DRAFT_05));
96
- expect(publisher.byteLength).toBeGreaterThan(both.byteLength);
97
- });
98
- test("unknown role falls back to Both", async () => {
99
- // Hand-frame a SETUP carrying an unrecognized role (99). The draft requires a receiver
100
- // that doesn't know the value to treat it as Both, so a newer client can't break us.
101
- const got = await decodeParam(PARAM_ROLE, Varint.encode(99));
102
- expect(got.role).toBe(Role.Both);
103
- });
104
- test("role 0 decodes as Both", async () => {
105
- const got = await decodeParam(PARAM_ROLE, Varint.encode(0));
106
- expect(got.role).toBe(Role.Both);
107
- });
108
- test("unknown probe level saturates to Increase", async () => {
109
- const got = await decodeParam(PARAM_PROBE, Varint.encode(99));
110
- expect(got.probe).toBe(ProbeLevel.Increase);
111
- });
112
- test("SETUP with origin round-trips", async () => {
113
- const origin = OriginSchema.parse(42n);
114
- const got = await roundTrip(new Setup({ origin }));
115
- expect(got.origin).toBe(origin);
116
- });
117
- test("origin 0 decodes as absent", async () => {
118
- // 0 carries no identity (it cannot be excluded), so it decodes as undefined.
119
- const got = await decodeParam(PARAM_ORIGIN, Varint.encode(0));
120
- expect(got.origin).toBeUndefined();
121
- });
122
- test("SETUP is rejected before draft-05", async () => {
123
- await expect(bytes((w) => new Setup().encode(w, Version.DRAFT_04))).rejects.toThrow();
124
- });
125
- test("SETUP decode is rejected before draft-05", async () => {
126
- const framed = await bytes((w) => new Setup().encode(w, Version.DRAFT_05));
127
- await expect(Setup.decode(new Reader(undefined, framed), Version.DRAFT_04)).rejects.toThrow();
128
- });
129
- test("empty path decodes as the root", async () => {
130
- // Valid on the wire and equivalent to omitting the parameter.
131
- const got = await decodeParam(PARAM_PATH, new Uint8Array());
132
- expect(got.path).toBe("");
133
- });
134
- //# sourceMappingURL=setup.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.test.js","sourceRoot":"","sources":["../../src/lite/setup.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,mFAAmF;AACnF,iCAAiC;AACjC,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,YAAY,GAAG,IAAI,CAAC;AAE1B,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,C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C3B,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport * as Varint from \"../varint.ts\";\nimport { OriginSchema } from \"./origin.ts\";\nimport { ProbeLevel, Role, Setup } from \"./setup.ts\";\nimport { Version } from \"./version.ts\";\n\n// Parameter ids, duplicated from setup.ts so a typo there fails a test rather than\n// silently agreeing with itself.\nconst PARAM_PROBE = 0x1n;\nconst PARAM_PATH = 0x2n;\nconst PARAM_ROLE = 0x3n;\nconst PARAM_ORIGIN = 0x5n;\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 bytes(f: (w: Writer) => Promise<void>): 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 f(writer);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\nasync function roundTrip(msg: Setup): Promise<Setup> {\n\tconst reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));\n\tconst got = await Setup.decode(reader, Version.DRAFT_05);\n\texpect(await reader.done()).toBe(true);\n\treturn got;\n}\n\n// Hand-frame a SETUP carrying a single raw parameter, so we can feed the decoder values\n// our own encoder would never produce (unknown levels, empty paths).\nasync function decodeParam(id: bigint, value: Uint8Array): Promise<Setup> {\n\tconst body = await bytes(async (w) => {\n\t\tawait w.u53(1); // parameter count\n\t\tawait w.u62(id);\n\t\tawait w.u53(value.byteLength);\n\t\tif (value.byteLength > 0) await w.write(value);\n\t});\n\n\tconst framed = await bytes(async (w) => {\n\t\tawait w.u53(body.byteLength); // Message size prefix\n\t\tawait w.write(body);\n\t});\n\n\treturn await Setup.decode(new Reader(undefined, framed), Version.DRAFT_05);\n}\n\ntest(\"empty SETUP round-trips on draft-05\", async () => {\n\tconst got = await roundTrip(new Setup());\n\texpect(got.probe).toBe(ProbeLevel.None);\n\texpect(got.path).toBeUndefined();\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"each probe level round-trips on draft-05\", async () => {\n\tfor (const probe of [ProbeLevel.None, ProbeLevel.Report, ProbeLevel.Increase]) {\n\t\tconst got = await roundTrip(new Setup({ probe }));\n\t\texpect(got.probe).toBe(probe);\n\t\texpect(got.path).toBeUndefined();\n\t}\n});\n\ntest(\"SETUP with path round-trips on draft-05\", async () => {\n\tconst got = await roundTrip(new Setup({ probe: ProbeLevel.Report, path: \"/room/123\" }));\n\texpect(got.probe).toBe(ProbeLevel.Report);\n\texpect(got.path).toBe(\"/room/123\");\n});\n\ntest(\"each role round-trips on draft-05\", async () => {\n\tfor (const role of [Role.Both, Role.Publisher, Role.Subscriber]) {\n\t\tconst got = await roundTrip(new Setup({ role }));\n\t\texpect(got.role).toBe(role);\n\t}\n});\n\ntest(\"SETUP carries role alongside probe and path\", async () => {\n\tconst got = await roundTrip(new Setup({ probe: ProbeLevel.Increase, path: \"/room/123\", role: Role.Publisher }));\n\texpect(got.probe).toBe(ProbeLevel.Increase);\n\texpect(got.path).toBe(\"/room/123\");\n\texpect(got.role).toBe(Role.Publisher);\n});\n\ntest(\"Both is the wire default, so it is omitted rather than encoded\", async () => {\n\t// Both must be the absence of the parameter, so a server that predates it decodes a\n\t// Both client back to Both. Assert the empty bag directly: comparing against another\n\t// default-constructed Setup would agree with itself even if we encoded Both.\n\tconst both = await bytes((w) => new Setup({ role: Role.Both }).encode(w, Version.DRAFT_05));\n\tconst emptyBag = await bytes(async (w) => {\n\t\tawait w.u53(1); // Message size prefix: one byte of body follows\n\t\tawait w.u53(0); // parameter count\n\t});\n\texpect(both).toEqual(emptyBag);\n\n\t// A directional role is still encoded, so the check above can actually fail.\n\tconst publisher = await bytes((w) => new Setup({ role: Role.Publisher }).encode(w, Version.DRAFT_05));\n\texpect(publisher.byteLength).toBeGreaterThan(both.byteLength);\n});\n\ntest(\"unknown role falls back to Both\", async () => {\n\t// Hand-frame a SETUP carrying an unrecognized role (99). The draft requires a receiver\n\t// that doesn't know the value to treat it as Both, so a newer client can't break us.\n\tconst got = await decodeParam(PARAM_ROLE, Varint.encode(99));\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"role 0 decodes as Both\", async () => {\n\tconst got = await decodeParam(PARAM_ROLE, Varint.encode(0));\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"unknown probe level saturates to Increase\", async () => {\n\tconst got = await decodeParam(PARAM_PROBE, Varint.encode(99));\n\texpect(got.probe).toBe(ProbeLevel.Increase);\n});\n\ntest(\"SETUP with origin round-trips\", async () => {\n\tconst origin = OriginSchema.parse(42n);\n\tconst got = await roundTrip(new Setup({ origin }));\n\texpect(got.origin).toBe(origin);\n});\n\ntest(\"origin 0 decodes as absent\", async () => {\n\t// 0 carries no identity (it cannot be excluded), so it decodes as undefined.\n\tconst got = await decodeParam(PARAM_ORIGIN, Varint.encode(0));\n\texpect(got.origin).toBeUndefined();\n});\n\ntest(\"SETUP is rejected before draft-05\", async () => {\n\tawait expect(bytes((w) => new Setup().encode(w, Version.DRAFT_04))).rejects.toThrow();\n});\n\ntest(\"SETUP decode is rejected before draft-05\", async () => {\n\tconst framed = await bytes((w) => new Setup().encode(w, Version.DRAFT_05));\n\tawait expect(Setup.decode(new Reader(undefined, framed), Version.DRAFT_04)).rejects.toThrow();\n});\n\ntest(\"empty path decodes as the root\", async () => {\n\t// Valid on the wire and equivalent to omitting the parameter.\n\tconst got = await decodeParam(PARAM_PATH, new Uint8Array());\n\texpect(got.path).toBe(\"\");\n});\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=subscribe.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subscribe.test.d.ts","sourceRoot":"","sources":["../../src/lite/subscribe.test.ts"],"names":[],"mappings":""}
@@ -1,110 +0,0 @@
1
- /* @ts-self-types="./subscribe.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 { decodeSubscribeResponse, encodeSubscribeResponse, Subscribe, SubscribeDrop, SubscribeEnd, SubscribeOk, SubscribeStart, SubscribeUpdate, } from "./subscribe.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, resp) {
18
- const written = [];
19
- const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
20
- await encodeSubscribeResponse(writer, resp, version);
21
- writer.close();
22
- await writer.closed;
23
- return concat(written);
24
- }
25
- async function responseRoundtrip(version, resp) {
26
- const reader = new Reader(undefined, await encode(version, resp));
27
- return decodeSubscribeResponse(reader, version);
28
- }
29
- async function encodeMessage(version, message) {
30
- const written = [];
31
- const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
32
- await message.encode(writer, version);
33
- writer.close();
34
- await writer.closed;
35
- return concat(written);
36
- }
37
- test("SubscribeOk round-trips priority/ordered/groups on draft-04", async () => {
38
- const got = await responseRoundtrip(Version.DRAFT_04, {
39
- ok: new SubscribeOk({ priority: 7, ordered: true, maxLatency: 250, startGroup: 3 }),
40
- });
41
- expect("ok" in got).toBe(true);
42
- if (!("ok" in got))
43
- throw new Error("expected ok");
44
- expect(got.ok.priority).toBe(7);
45
- expect(got.ok.ordered).toBe(true);
46
- expect(got.ok.startGroup).toBe(3);
47
- });
48
- test("Subscribe round-trips every option including startGroup 0", async () => {
49
- const message = new Subscribe({
50
- id: 4n,
51
- broadcast: Path.from("test"),
52
- track: "video",
53
- priority: 7,
54
- ordered: true,
55
- maxLatency: 250,
56
- startGroup: 0,
57
- endGroup: 9,
58
- });
59
- const got = await Subscribe.decode(new Reader(undefined, await encodeMessage(Version.DRAFT_05, message)), Version.DRAFT_05);
60
- expect(got.priority).toBe(7);
61
- expect(got.ordered).toBe(true);
62
- expect(got.maxLatency).toBe(250);
63
- expect(got.startGroup).toBe(0);
64
- expect(got.endGroup).toBe(9);
65
- });
66
- test("SubscribeUpdate round-trips every option including startGroup 0", async () => {
67
- const message = new SubscribeUpdate({
68
- priority: 8,
69
- ordered: true,
70
- maxLatency: 500,
71
- startGroup: 0,
72
- endGroup: 12,
73
- });
74
- const got = await SubscribeUpdate.decode(new Reader(undefined, await encodeMessage(Version.DRAFT_05, message)), Version.DRAFT_05);
75
- expect(got.priority).toBe(8);
76
- expect(got.ordered).toBe(true);
77
- expect(got.maxLatency).toBe(500);
78
- expect(got.startGroup).toBe(0);
79
- expect(got.endGroup).toBe(12);
80
- });
81
- test("SubscribeStart round-trips on draft-05", async () => {
82
- const got = await responseRoundtrip(Version.DRAFT_05, { start: new SubscribeStart(42) });
83
- expect("start" in got).toBe(true);
84
- if (!("start" in got))
85
- throw new Error("expected start");
86
- expect(got.start.group).toBe(42);
87
- });
88
- test("SubscribeEnd round-trips on draft-05", async () => {
89
- const got = await responseRoundtrip(Version.DRAFT_05, { end: new SubscribeEnd(7) });
90
- expect("end" in got).toBe(true);
91
- if (!("end" in got))
92
- throw new Error("expected end");
93
- expect(got.end.group).toBe(7);
94
- });
95
- test("SubscribeDrop is type 0x2 on draft-05 and 0x1 on draft-04", async () => {
96
- const drop = { drop: new SubscribeDrop({ start: 1, end: 3, error: 0 }) };
97
- const wire05 = await encode(Version.DRAFT_05, drop);
98
- expect(wire05[0]).toBe(2);
99
- const wire04 = await encode(Version.DRAFT_04, drop);
100
- expect(wire04[0]).toBe(1);
101
- const got = await responseRoundtrip(Version.DRAFT_05, drop);
102
- expect("drop" in got).toBe(true);
103
- if (!("drop" in got))
104
- throw new Error("expected drop");
105
- expect([got.drop.start, got.drop.end]).toEqual([1, 3]);
106
- });
107
- test("SUBSCRIBE_OK is rejected on draft-05", async () => {
108
- await expect(encode(Version.DRAFT_05, { ok: new SubscribeOk({ priority: 1 }) })).rejects.toThrow();
109
- });
110
- //# sourceMappingURL=subscribe.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subscribe.test.js","sourceRoot":"","sources":["../../src/lite/subscribe.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,EACN,uBAAuB,EACvB,uBAAuB,EACvB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,WAAW,EAEX,cAAc,EACd,eAAe,GACf,MAAM,gBAAgB,CAAC;AACxB,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,IAAuB;IAC9D,MAAM,OAAO,GAAiB,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,IA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AE1B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACpD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAE1B,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC5D,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACvD,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;IACvD,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,IAAI,WAAW,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AACpG,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Path from \"../path.ts\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport {\n\tdecodeSubscribeResponse,\n\tencodeSubscribeResponse,\n\tSubscribe,\n\tSubscribeDrop,\n\tSubscribeEnd,\n\tSubscribeOk,\n\ttype SubscribeResponse,\n\tSubscribeStart,\n\tSubscribeUpdate,\n} from \"./subscribe.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, resp: SubscribeResponse): 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 encodeSubscribeResponse(writer, resp, version);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\nasync function responseRoundtrip(version: Version, resp: SubscribeResponse): Promise<SubscribeResponse> {\n\tconst reader = new Reader(undefined, await encode(version, resp));\n\treturn decodeSubscribeResponse(reader, version);\n}\n\nasync function encodeMessage(\n\tversion: Version,\n\tmessage: { encode(writer: Writer, version: Version): Promise<void> },\n): 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 message.encode(writer, version);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\ntest(\"SubscribeOk round-trips priority/ordered/groups on draft-04\", async () => {\n\tconst got = await responseRoundtrip(Version.DRAFT_04, {\n\t\tok: new SubscribeOk({ priority: 7, ordered: true, maxLatency: 250, startGroup: 3 }),\n\t});\n\texpect(\"ok\" in got).toBe(true);\n\tif (!(\"ok\" in got)) throw new Error(\"expected ok\");\n\texpect(got.ok.priority).toBe(7);\n\texpect(got.ok.ordered).toBe(true);\n\texpect(got.ok.startGroup).toBe(3);\n});\n\ntest(\"Subscribe round-trips every option including startGroup 0\", async () => {\n\tconst message = new Subscribe({\n\t\tid: 4n,\n\t\tbroadcast: Path.from(\"test\"),\n\t\ttrack: \"video\",\n\t\tpriority: 7,\n\t\tordered: true,\n\t\tmaxLatency: 250,\n\t\tstartGroup: 0,\n\t\tendGroup: 9,\n\t});\n\tconst got = await Subscribe.decode(\n\t\tnew Reader(undefined, await encodeMessage(Version.DRAFT_05, message)),\n\t\tVersion.DRAFT_05,\n\t);\n\texpect(got.priority).toBe(7);\n\texpect(got.ordered).toBe(true);\n\texpect(got.maxLatency).toBe(250);\n\texpect(got.startGroup).toBe(0);\n\texpect(got.endGroup).toBe(9);\n});\n\ntest(\"SubscribeUpdate round-trips every option including startGroup 0\", async () => {\n\tconst message = new SubscribeUpdate({\n\t\tpriority: 8,\n\t\tordered: true,\n\t\tmaxLatency: 500,\n\t\tstartGroup: 0,\n\t\tendGroup: 12,\n\t});\n\tconst got = await SubscribeUpdate.decode(\n\t\tnew Reader(undefined, await encodeMessage(Version.DRAFT_05, message)),\n\t\tVersion.DRAFT_05,\n\t);\n\texpect(got.priority).toBe(8);\n\texpect(got.ordered).toBe(true);\n\texpect(got.maxLatency).toBe(500);\n\texpect(got.startGroup).toBe(0);\n\texpect(got.endGroup).toBe(12);\n});\n\ntest(\"SubscribeStart round-trips on draft-05\", async () => {\n\tconst got = await responseRoundtrip(Version.DRAFT_05, { start: new SubscribeStart(42) });\n\texpect(\"start\" in got).toBe(true);\n\tif (!(\"start\" in got)) throw new Error(\"expected start\");\n\texpect(got.start.group).toBe(42);\n});\n\ntest(\"SubscribeEnd round-trips on draft-05\", async () => {\n\tconst got = await responseRoundtrip(Version.DRAFT_05, { end: new SubscribeEnd(7) });\n\texpect(\"end\" in got).toBe(true);\n\tif (!(\"end\" in got)) throw new Error(\"expected end\");\n\texpect(got.end.group).toBe(7);\n});\n\ntest(\"SubscribeDrop is type 0x2 on draft-05 and 0x1 on draft-04\", async () => {\n\tconst drop: SubscribeResponse = { drop: new SubscribeDrop({ start: 1, end: 3, error: 0 }) };\n\n\tconst wire05 = await encode(Version.DRAFT_05, drop);\n\texpect(wire05[0]).toBe(2);\n\n\tconst wire04 = await encode(Version.DRAFT_04, drop);\n\texpect(wire04[0]).toBe(1);\n\n\tconst got = await responseRoundtrip(Version.DRAFT_05, drop);\n\texpect(\"drop\" in got).toBe(true);\n\tif (!(\"drop\" in got)) throw new Error(\"expected drop\");\n\texpect([got.drop.start, got.drop.end]).toEqual([1, 3]);\n});\n\ntest(\"SUBSCRIBE_OK is rejected on draft-05\", async () => {\n\tawait expect(encode(Version.DRAFT_05, { ok: new SubscribeOk({ priority: 1 }) })).rejects.toThrow();\n});\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=subscriber.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subscriber.test.d.ts","sourceRoot":"","sources":["../../src/lite/subscriber.test.ts"],"names":[],"mappings":""}
@@ -1,108 +0,0 @@
1
- /* @ts-self-types="./subscriber.test.d.ts" */
2
- import { expect, spyOn, test } from "bun:test";
3
- import { Signal } from "@moq/signals";
4
- import * as Path from "../path.js";
5
- import { Writer } from "../stream.js";
6
- import { AnnounceOk, encodeAnnounceBroadcast } from "./announce.js";
7
- import { OriginSchema } from "./origin.js";
8
- import { Subscriber } from "./subscriber.js";
9
- import { Version } from "./version.js";
10
- test("closing the subscriber suppresses probe stream warnings", async () => {
11
- let readable;
12
- const quic = {
13
- createBidirectionalStream: async () => ({
14
- readable: new ReadableStream({ start: (controller) => (readable = controller) }),
15
- writable: new WritableStream(),
16
- }),
17
- };
18
- const subscriber = new Subscriber(quic, Version.DRAFT_03, OriginSchema.parse(1n), new Signal({}));
19
- const warn = spyOn(console, "warn").mockImplementation(() => { });
20
- try {
21
- const probe = subscriber.runProbe();
22
- await Promise.resolve();
23
- await Promise.resolve();
24
- subscriber.close();
25
- readable.error(new Error("session closed"));
26
- await probe;
27
- expect(warn).not.toHaveBeenCalled();
28
- }
29
- finally {
30
- warn.mockRestore();
31
- }
32
- });
33
- // Drives a Subscriber's announce stream directly: the harness plays the peer, writing
34
- // forged announce messages into the stream the subscriber opens.
35
- function announceHarness(version, origin = 1n) {
36
- let inbound;
37
- const quic = {
38
- createBidirectionalStream: async () => ({
39
- readable: new ReadableStream({ start: (controller) => (inbound = controller) }),
40
- writable: new WritableStream(),
41
- }),
42
- };
43
- const subscriber = new Subscriber(quic, version, OriginSchema.parse(origin));
44
- const send = async (f) => {
45
- const written = [];
46
- const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
47
- await f(writer);
48
- writer.close();
49
- await writer.closed;
50
- const total = written.reduce((sum, c) => sum + c.byteLength, 0);
51
- const out = new Uint8Array(total);
52
- let offset = 0;
53
- for (const chunk of written) {
54
- out.set(chunk, offset);
55
- offset += chunk.byteLength;
56
- }
57
- inbound.enqueue(out);
58
- };
59
- return { subscriber, send, settle: () => new Promise((resolve) => setTimeout(resolve, 0)) };
60
- }
61
- const PUBLISHER_A = OriginSchema.parse(7n);
62
- const PUBLISHER_B = OriginSchema.parse(8n);
63
- const PUBLISHER_C = OriginSchema.parse(9n);
64
- const PEER = OriginSchema.parse(2n);
65
- test("a restart from the same publisher is a route change, not a republish", async () => {
66
- const { subscriber, send, settle } = announceHarness(Version.DRAFT_06);
67
- const announced = subscriber.announced(Path.empty());
68
- await settle();
69
- await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06));
70
- await send((w) => encodeAnnounceBroadcast(w, { status: "active", suffix: Path.from("room"), hops: [PUBLISHER_A] }, Version.DRAFT_06));
71
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: true });
72
- // Same publisher over a new route. In-flight subscriptions resume across it, so the
73
- // subscriber must not surface anything that would make a consumer re-subscribe.
74
- await send((w) => encodeAnnounceBroadcast(w, { status: "restart", id: 0n, hops: [PUBLISHER_A] }, Version.DRAFT_06));
75
- // A different publisher took the path: nothing carries over, so this one does surface,
76
- // as an end before the start. Reaching it proves the reroute above emitted nothing.
77
- await send((w) => encodeAnnounceBroadcast(w, { status: "restart", id: 0n, hops: [PUBLISHER_B] }, Version.DRAFT_06));
78
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: false });
79
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: true });
80
- // A third publisher takes over. The replacement above has to leave its own publisher on
81
- // record, or this one reads as a first announcement and skips the end.
82
- await send((w) => encodeAnnounceBroadcast(w, { status: "restart", id: 0n, hops: [PUBLISHER_C] }, Version.DRAFT_06));
83
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: false });
84
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: true });
85
- // And the new owner's own reroute is still transparent.
86
- await send((w) => encodeAnnounceBroadcast(w, { status: "restart", id: 0n, hops: [PUBLISHER_C] }, Version.DRAFT_06));
87
- await send((w) => encodeAnnounceBroadcast(w, { status: "endedId", id: 0n }, Version.DRAFT_06));
88
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: false });
89
- announced.close();
90
- subscriber.close();
91
- });
92
- test("a lite-05 duplicate announce follows the same restart rule", async () => {
93
- const { subscriber, send, settle } = announceHarness(Version.DRAFT_05);
94
- const announced = subscriber.announced(Path.empty());
95
- await settle();
96
- await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_05));
97
- const active = (hops) => (w) => encodeAnnounceBroadcast(w, { status: "active", suffix: Path.from("room"), hops }, Version.DRAFT_05);
98
- await send(active([PUBLISHER_A]));
99
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: true });
100
- // On lite-05 a restart travels as a duplicate ANNOUNCE rather than its own message.
101
- await send(active([PUBLISHER_A]));
102
- await send(active([PUBLISHER_B]));
103
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: false });
104
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: true });
105
- announced.close();
106
- subscriber.close();
107
- });
108
- //# sourceMappingURL=subscriber.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subscriber.test.js","sourceRoot":"","sources":["../../src/lite/subscriber.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,IAAI,MAAM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IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAElF,SAAS,CAAC,KAAK,EAAE,CAAC;IAClB,UAAU,CAAC,KAAK,EAAE,CAAC;AACpB,CAAC,CAAC,CAAC","sourcesContent":["import { expect, spyOn, test } from \"bun:test\";\nimport { Signal } from \"@moq/signals\";\nimport type { Probe } from \"../connection/stats.ts\";\nimport * as Path from \"../path.ts\";\nimport { Writer } from \"../stream.ts\";\nimport { AnnounceOk, encodeAnnounceBroadcast } from \"./announce.ts\";\nimport { OriginSchema } from \"./origin.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Version } from \"./version.ts\";\n\ntest(\"closing the subscriber suppresses probe stream warnings\", async () => {\n\tlet readable!: ReadableStreamDefaultController<Uint8Array>;\n\tconst quic = {\n\t\tcreateBidirectionalStream: async () => ({\n\t\t\treadable: new ReadableStream<Uint8Array>({ start: (controller) => (readable = controller) }),\n\t\t\twritable: new WritableStream<Uint8Array>(),\n\t\t}),\n\t} as unknown as WebTransport;\n\tconst subscriber = new Subscriber(quic, Version.DRAFT_03, OriginSchema.parse(1n), new Signal<Probe>({}));\n\tconst warn = spyOn(console, \"warn\").mockImplementation(() => {});\n\n\ttry {\n\t\tconst probe = subscriber.runProbe();\n\n\t\tawait Promise.resolve();\n\t\tawait Promise.resolve();\n\t\tsubscriber.close();\n\t\treadable.error(new Error(\"session closed\"));\n\t\tawait probe;\n\n\t\texpect(warn).not.toHaveBeenCalled();\n\t} finally {\n\t\twarn.mockRestore();\n\t}\n});\n\n// Drives a Subscriber's announce stream directly: the harness plays the peer, writing\n// forged announce messages into the stream the subscriber opens.\nfunction announceHarness(version: Version, origin = 1n) {\n\tlet inbound!: ReadableStreamDefaultController<Uint8Array>;\n\tconst quic = {\n\t\tcreateBidirectionalStream: async () => ({\n\t\t\treadable: new ReadableStream<Uint8Array>({ start: (controller) => (inbound = controller) }),\n\t\t\twritable: new WritableStream<Uint8Array>(),\n\t\t}),\n\t} as unknown as WebTransport;\n\n\tconst subscriber = new Subscriber(quic, version, OriginSchema.parse(origin));\n\n\tconst send = async (f: (w: Writer) => Promise<void>) => {\n\t\tconst written: Uint8Array[] = [];\n\t\tconst writer = new Writer(\n\t\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t\t);\n\t\tawait f(writer);\n\t\twriter.close();\n\t\tawait writer.closed;\n\n\t\tconst total = written.reduce((sum, c) => sum + c.byteLength, 0);\n\t\tconst out = new Uint8Array(total);\n\t\tlet offset = 0;\n\t\tfor (const chunk of written) {\n\t\t\tout.set(chunk, offset);\n\t\t\toffset += chunk.byteLength;\n\t\t}\n\t\tinbound.enqueue(out);\n\t};\n\n\treturn { subscriber, send, settle: () => new Promise((resolve) => setTimeout(resolve, 0)) };\n}\n\nconst PUBLISHER_A = OriginSchema.parse(7n);\nconst PUBLISHER_B = OriginSchema.parse(8n);\nconst PUBLISHER_C = OriginSchema.parse(9n);\nconst PEER = OriginSchema.parse(2n);\n\ntest(\"a restart from the same publisher is a route change, not a republish\", async () => {\n\tconst { subscriber, send, settle } = announceHarness(Version.DRAFT_06);\n\tconst announced = subscriber.announced(Path.empty());\n\tawait settle();\n\n\tawait send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06));\n\tawait send((w) =>\n\t\tencodeAnnounceBroadcast(\n\t\t\tw,\n\t\t\t{ status: \"active\", suffix: Path.from(\"room\"), hops: [PUBLISHER_A] },\n\t\t\tVersion.DRAFT_06,\n\t\t),\n\t);\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: true });\n\n\t// Same publisher over a new route. In-flight subscriptions resume across it, so the\n\t// subscriber must not surface anything that would make a consumer re-subscribe.\n\tawait send((w) => encodeAnnounceBroadcast(w, { status: \"restart\", id: 0n, hops: [PUBLISHER_A] }, Version.DRAFT_06));\n\n\t// A different publisher took the path: nothing carries over, so this one does surface,\n\t// as an end before the start. Reaching it proves the reroute above emitted nothing.\n\tawait send((w) => encodeAnnounceBroadcast(w, { status: \"restart\", id: 0n, hops: [PUBLISHER_B] }, Version.DRAFT_06));\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: false });\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: true });\n\n\t// A third publisher takes over. The replacement above has to leave its own publisher on\n\t// record, or this one reads as a first announcement and skips the end.\n\tawait send((w) => encodeAnnounceBroadcast(w, { status: \"restart\", id: 0n, hops: [PUBLISHER_C] }, Version.DRAFT_06));\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: false });\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: true });\n\n\t// And the new owner's own reroute is still transparent.\n\tawait send((w) => encodeAnnounceBroadcast(w, { status: \"restart\", id: 0n, hops: [PUBLISHER_C] }, Version.DRAFT_06));\n\tawait send((w) => encodeAnnounceBroadcast(w, { status: \"endedId\", id: 0n }, Version.DRAFT_06));\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: false });\n\n\tannounced.close();\n\tsubscriber.close();\n});\n\ntest(\"a lite-05 duplicate announce follows the same restart rule\", async () => {\n\tconst { subscriber, send, settle } = announceHarness(Version.DRAFT_05);\n\tconst announced = subscriber.announced(Path.empty());\n\tawait settle();\n\n\tawait send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_05));\n\tconst active = (hops: ReturnType<typeof OriginSchema.parse>[]) => (w: Writer) =>\n\t\tencodeAnnounceBroadcast(w, { status: \"active\", suffix: Path.from(\"room\"), hops }, Version.DRAFT_05);\n\n\tawait send(active([PUBLISHER_A]));\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: true });\n\n\t// On lite-05 a restart travels as a duplicate ANNOUNCE rather than its own message.\n\tawait send(active([PUBLISHER_A]));\n\tawait send(active([PUBLISHER_B]));\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: false });\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: true });\n\n\tannounced.close();\n\tsubscriber.close();\n});\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=track.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"track.test.d.ts","sourceRoot":"","sources":["../../src/lite/track.test.ts"],"names":[],"mappings":""}
@@ -1,55 +0,0 @@
1
- /* @ts-self-types="./track.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 { infoDefaults } from "../track.js";
6
- import { Track, TrackInfo } from "./track.js";
7
- import { Version } from "./version.js";
8
- function concat(chunks) {
9
- const total = chunks.reduce((sum, c) => sum + c.byteLength, 0);
10
- const out = new Uint8Array(total);
11
- let offset = 0;
12
- for (const c of chunks) {
13
- out.set(c, offset);
14
- offset += c.byteLength;
15
- }
16
- return out;
17
- }
18
- async function bytes(f) {
19
- const written = [];
20
- const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
21
- await f(writer);
22
- writer.close();
23
- await writer.closed;
24
- return concat(written);
25
- }
26
- test("TrackInfo round-trips on draft-05", async () => {
27
- const info = new TrackInfo({
28
- priority: 7,
29
- ordered: false,
30
- latencyMax: 2000,
31
- timescale: 90000,
32
- });
33
- const reader = new Reader(undefined, await bytes((w) => info.encode(w, Version.DRAFT_05)));
34
- const got = await TrackInfo.decode(reader, Version.DRAFT_05);
35
- expect(got.priority).toBe(7);
36
- expect(got.ordered).toBe(false);
37
- expect(got.latencyMax).toBe(2000);
38
- expect(got.timescale).toBe(90000);
39
- });
40
- test("TrackInfo defaults match cross-language wire bytes", async () => {
41
- const info = new TrackInfo(infoDefaults());
42
- expect(await bytes((w) => info.encode(w, Version.DRAFT_05))).toEqual(new Uint8Array([0x06, 0x00, 0x00, 0x53, 0x88, 0x43, 0xe8]));
43
- });
44
- test("Track request round-trips on draft-05", async () => {
45
- const msg = new Track(Path.from("room"), "video");
46
- const reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));
47
- const got = await Track.decode(reader, Version.DRAFT_05);
48
- expect(got.broadcast).toBe(Path.from("room"));
49
- expect(got.track).toBe("video");
50
- });
51
- test("TRACK_INFO is rejected before draft-05", async () => {
52
- const info = new TrackInfo({ timescale: 90000 });
53
- await expect(bytes((w) => info.encode(w, Version.DRAFT_04))).rejects.toThrow();
54
- });
55
- //# sourceMappingURL=track.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"track.test.js","sourceRoot":"","sources":["../../src/lite/track.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,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC9C,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,KAAK,CAAC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C,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AAChF,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Path from \"../path.ts\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport { infoDefaults } from \"../track.ts\";\nimport { Track, TrackInfo } from \"./track.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 bytes(f: (w: Writer) => Promise<void>): 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 f(writer);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\ntest(\"TrackInfo round-trips on draft-05\", async () => {\n\tconst info = new TrackInfo({\n\t\tpriority: 7,\n\t\tordered: false,\n\t\tlatencyMax: 2000,\n\t\ttimescale: 90000,\n\t});\n\tconst reader = new Reader(undefined, await bytes((w) => info.encode(w, Version.DRAFT_05)));\n\tconst got = await TrackInfo.decode(reader, Version.DRAFT_05);\n\texpect(got.priority).toBe(7);\n\texpect(got.ordered).toBe(false);\n\texpect(got.latencyMax).toBe(2000);\n\texpect(got.timescale).toBe(90000);\n});\n\ntest(\"TrackInfo defaults match cross-language wire bytes\", async () => {\n\tconst info = new TrackInfo(infoDefaults());\n\texpect(await bytes((w) => info.encode(w, Version.DRAFT_05))).toEqual(\n\t\tnew Uint8Array([0x06, 0x00, 0x00, 0x53, 0x88, 0x43, 0xe8]),\n\t);\n});\n\ntest(\"Track request round-trips on draft-05\", async () => {\n\tconst msg = new Track(Path.from(\"room\"), \"video\");\n\tconst reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));\n\tconst got = await Track.decode(reader, Version.DRAFT_05);\n\texpect(got.broadcast).toBe(Path.from(\"room\"));\n\texpect(got.track).toBe(\"video\");\n});\n\ntest(\"TRACK_INFO is rejected before draft-05\", async () => {\n\tconst info = new TrackInfo({ timescale: 90000 });\n\tawait expect(bytes((w) => info.encode(w, Version.DRAFT_04))).rejects.toThrow();\n});\n"]}
package/path.test.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=path.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path.test.d.ts","sourceRoot":"","sources":["../src/path.test.ts"],"names":[],"mappings":""}