@moqtap/codec 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/dist/auth-redaction-DsdLq4Qs.d.cts +102 -0
  3. package/dist/auth-redaction-DsdLq4Qs.d.ts +102 -0
  4. package/dist/{chunk-RYKQXBG6.cjs → chunk-27K5BUAG.cjs} +481 -517
  5. package/dist/{chunk-WCPENYNE.js → chunk-3RNQMGKA.js} +359 -390
  6. package/dist/{chunk-TSUZ6GJV.js → chunk-5AWIXOLB.js} +438 -469
  7. package/dist/{chunk-4XLYCT5Q.cjs → chunk-5IMHJIAZ.cjs} +52 -2
  8. package/dist/{chunk-KTNERCTZ.cjs → chunk-5JGZCKJO.cjs} +488 -518
  9. package/dist/{chunk-WCTMPDUX.cjs → chunk-73K4OSAN.cjs} +401 -432
  10. package/dist/{chunk-N2V7Z37J.js → chunk-7VQKRGRD.js} +19 -3
  11. package/dist/{chunk-BIBMDTU5.cjs → chunk-A3UCQOIB.cjs} +486 -517
  12. package/dist/{chunk-K2B3OVFK.js → chunk-A7PDMVXM.js} +24 -3
  13. package/dist/{chunk-VZHL2U2N.cjs → chunk-A7VQO6YC.cjs} +54 -38
  14. package/dist/{chunk-AQ445VV7.cjs → chunk-ACQHZLRZ.cjs} +66 -46
  15. package/dist/{chunk-L5DRACXS.js → chunk-BBICOMW6.js} +25 -3
  16. package/dist/{chunk-T4VWPKDG.cjs → chunk-BNIUVOCJ.cjs} +529 -599
  17. package/dist/{chunk-UKKDOOUO.cjs → chunk-CNC6ANS4.cjs} +58 -37
  18. package/dist/{chunk-OZRK73NQ.js → chunk-FDLQSWHK.js} +433 -469
  19. package/dist/{chunk-IJAF6PAY.js → chunk-FFNOE4UR.js} +19 -3
  20. package/dist/{chunk-CZNW3R5E.cjs → chunk-GMENT63T.cjs} +54 -38
  21. package/dist/{chunk-XCRCAUGI.cjs → chunk-HM7BLRVP.cjs} +291 -297
  22. package/dist/{chunk-XHAP2YST.js → chunk-HZONHFNO.js} +19 -3
  23. package/dist/{chunk-SDJTSMOW.cjs → chunk-ILYABWDK.cjs} +60 -38
  24. package/dist/{chunk-IDV2JYJ6.cjs → chunk-KRSFTZVO.cjs} +56 -40
  25. package/dist/{chunk-RIIA4ALQ.cjs → chunk-KSPH6KMH.cjs} +54 -38
  26. package/dist/{chunk-OUNN4IQB.cjs → chunk-KTY4LAUV.cjs} +482 -497
  27. package/dist/{chunk-RZTLQAKF.js → chunk-OJNLJT5D.js} +0 -1
  28. package/dist/{chunk-FT3HDNIB.js → chunk-PJK2ZS3I.js} +467 -537
  29. package/dist/{chunk-G53WYUXL.js → chunk-PSMZKHOC.js} +441 -456
  30. package/dist/{chunk-7RE6KSIY.cjs → chunk-Q5JQGHWY.cjs} +0 -1
  31. package/dist/{chunk-BX2N7TZM.js → chunk-SQTUQY5E.js} +31 -11
  32. package/dist/{chunk-CF5DDD3Q.js → chunk-WCRLAKDW.js} +239 -245
  33. package/dist/{chunk-KYVTM5VI.js → chunk-WL2YUEXH.js} +19 -3
  34. package/dist/{chunk-KGDVC4O6.js → chunk-YCNIVZS7.js} +439 -469
  35. package/dist/{chunk-KLPWJU6W.js → chunk-YRZQVNZO.js} +50 -0
  36. package/dist/{codec-CFWu5KVT.d.cts → codec-76xzrLTL.d.cts} +21 -2
  37. package/dist/{codec-gl4_QEva.d.ts → codec-8p40WdLg.d.ts} +20 -1
  38. package/dist/{codec-Dl_QIXMz.d.ts → codec-BN2Bu0KI.d.ts} +20 -1
  39. package/dist/{codec-Bux_Q40X.d.ts → codec-Bb6GKTrv.d.ts} +21 -2
  40. package/dist/{codec-EvybrBuY.d.cts → codec-BgpfHoAd.d.cts} +20 -1
  41. package/dist/{codec-alVA27Uc.d.ts → codec-BkheTXO7.d.ts} +20 -1
  42. package/dist/{codec-Czejcmxr.d.cts → codec-BwVDkokh.d.cts} +21 -2
  43. package/dist/{codec-BrTi4K7r.d.cts → codec-C5s1eBJX.d.cts} +21 -2
  44. package/dist/codec-CM5yd6n3.d.ts +38 -0
  45. package/dist/{codec-CWnf8mn_.d.cts → codec-Cb8HC3XV.d.cts} +21 -2
  46. package/dist/codec-Clu_skx8.d.cts +38 -0
  47. package/dist/{codec-DzkdW4kO.d.cts → codec-CpOpemR8.d.cts} +20 -1
  48. package/dist/{codec-CXCjya_G.d.cts → codec-Cshdl9Tt.d.cts} +20 -1
  49. package/dist/{codec-f7vxeVIS.d.cts → codec-DELe00w_.d.cts} +21 -2
  50. package/dist/{codec-DNmiG2e0.d.cts → codec-DHzKAUCa.d.cts} +20 -1
  51. package/dist/{codec--CVeqGQv.d.ts → codec-DdVBtvx7.d.ts} +20 -1
  52. package/dist/{codec-CBdOIfMY.d.ts → codec-DlxGuYMv.d.ts} +21 -2
  53. package/dist/{codec-BNy5syCU.d.ts → codec-DxtgPxJS.d.ts} +20 -1
  54. package/dist/{codec-guzqtfMk.d.cts → codec-GAY4lybi.d.cts} +20 -1
  55. package/dist/{codec-Cfo_z5ET.d.cts → codec-I8u2pfS4.d.cts} +20 -1
  56. package/dist/{codec-BxQTybUX.d.cts → codec-XLrnreeu.d.cts} +21 -2
  57. package/dist/{codec-DOmAmFkI.d.ts → codec-c0YEwwWn.d.ts} +20 -1
  58. package/dist/{codec-DaXjRrOV.d.ts → codec-ejDu-va6.d.ts} +21 -2
  59. package/dist/{codec-C3mdsGx3.d.ts → codec-kaBUzdpV.d.ts} +21 -2
  60. package/dist/{codec-CwZ6OCPP.d.ts → codec-mVYqkIUF.d.ts} +21 -2
  61. package/dist/{codec-08ZOr5wI.d.ts → codec-qSbO5nOa.d.ts} +21 -2
  62. package/dist/{codec-Cm3D261p.d.ts → codec-yYKGOipj.d.ts} +20 -1
  63. package/dist/{codec-Bd60SGKH.d.cts → codec-zfzg9uiy.d.cts} +20 -1
  64. package/dist/draft07.cjs +48 -4
  65. package/dist/draft07.d.cts +42 -2
  66. package/dist/draft07.d.ts +42 -2
  67. package/dist/draft07.js +49 -5
  68. package/dist/draft08.cjs +76 -3
  69. package/dist/draft08.d.cts +70 -2
  70. package/dist/draft08.d.ts +70 -2
  71. package/dist/draft08.js +77 -4
  72. package/dist/draft09.cjs +76 -3
  73. package/dist/draft09.d.cts +70 -2
  74. package/dist/draft09.d.ts +70 -2
  75. package/dist/draft09.js +77 -4
  76. package/dist/draft10.cjs +76 -3
  77. package/dist/draft10.d.cts +70 -2
  78. package/dist/draft10.d.ts +70 -2
  79. package/dist/draft10.js +77 -4
  80. package/dist/draft11.cjs +104 -3
  81. package/dist/draft11.d.cts +98 -2
  82. package/dist/draft11.d.ts +98 -2
  83. package/dist/draft11.js +105 -4
  84. package/dist/draft12.cjs +113 -3
  85. package/dist/draft12.d.cts +107 -2
  86. package/dist/draft12.d.ts +107 -2
  87. package/dist/draft12.js +114 -4
  88. package/dist/draft13.cjs +105 -3
  89. package/dist/draft13.d.cts +99 -2
  90. package/dist/draft13.d.ts +99 -2
  91. package/dist/draft13.js +106 -4
  92. package/dist/draft14.cjs +107 -3
  93. package/dist/draft14.d.cts +101 -28
  94. package/dist/draft14.d.ts +101 -28
  95. package/dist/draft14.js +108 -4
  96. package/dist/draft15-session.d.cts +1 -1
  97. package/dist/draft15-session.d.ts +1 -1
  98. package/dist/draft15.cjs +69 -3
  99. package/dist/draft15.d.cts +65 -22
  100. package/dist/draft15.d.ts +65 -22
  101. package/dist/draft15.js +70 -4
  102. package/dist/draft16-session.cjs +2 -2
  103. package/dist/draft16-session.d.cts +1 -1
  104. package/dist/draft16-session.d.ts +1 -1
  105. package/dist/draft16-session.js +1 -1
  106. package/dist/draft16.cjs +76 -8
  107. package/dist/draft16.d.cts +67 -13
  108. package/dist/draft16.d.ts +67 -13
  109. package/dist/draft16.js +73 -5
  110. package/dist/draft17-session.d.cts +1 -1
  111. package/dist/draft17-session.d.ts +1 -1
  112. package/dist/draft17.cjs +77 -3
  113. package/dist/draft17.d.cts +73 -4
  114. package/dist/draft17.d.ts +73 -4
  115. package/dist/draft17.js +78 -4
  116. package/dist/draft18-session.d.cts +1 -1
  117. package/dist/draft18-session.d.ts +1 -1
  118. package/dist/draft18.cjs +8 -3
  119. package/dist/draft18.d.cts +4 -3
  120. package/dist/draft18.d.ts +4 -3
  121. package/dist/draft18.js +9 -4
  122. package/dist/draft19-session.d.cts +1 -1
  123. package/dist/draft19-session.d.ts +1 -1
  124. package/dist/draft19.cjs +11 -4
  125. package/dist/draft19.d.cts +4 -3
  126. package/dist/draft19.d.ts +4 -3
  127. package/dist/draft19.js +12 -5
  128. package/dist/draft20-session.d.cts +1 -1
  129. package/dist/draft20-session.d.ts +1 -1
  130. package/dist/draft20.cjs +8 -3
  131. package/dist/draft20.d.cts +4 -3
  132. package/dist/draft20.d.ts +4 -3
  133. package/dist/draft20.js +9 -4
  134. package/dist/index.cjs +30 -30
  135. package/dist/index.d.cts +21 -20
  136. package/dist/index.d.ts +21 -20
  137. package/dist/index.js +15 -15
  138. package/dist/session.cjs +2 -2
  139. package/dist/session.d.cts +6 -6
  140. package/dist/session.d.ts +6 -6
  141. package/dist/session.js +1 -1
  142. package/dist/{types-C1rxh-id.d.cts → types-Btp416jt.d.cts} +8 -0
  143. package/dist/{types-C1rxh-id.d.ts → types-Btp416jt.d.ts} +8 -0
  144. package/dist/{types-CZTzbIzQ.d.cts → types-BxTL1NXw.d.cts} +7 -0
  145. package/dist/{types-CZTzbIzQ.d.ts → types-BxTL1NXw.d.ts} +7 -0
  146. package/dist/{types-pShrs3fN.d.cts → types-CuibHYcf.d.cts} +7 -0
  147. package/dist/{types-pShrs3fN.d.ts → types-CuibHYcf.d.ts} +7 -0
  148. package/dist/{types-CY-QWxd-.d.cts → types-CwN7AEoL.d.cts} +13 -1
  149. package/dist/{types-CY-QWxd-.d.ts → types-CwN7AEoL.d.ts} +13 -1
  150. package/dist/{types-D4bmW8rY.d.cts → types-DAnalt5K.d.cts} +7 -0
  151. package/dist/{types-D4bmW8rY.d.ts → types-DAnalt5K.d.ts} +7 -0
  152. package/dist/{types-Bg86GGVZ.d.cts → types-DxXNP32l.d.cts} +8 -0
  153. package/dist/{types-Bg86GGVZ.d.ts → types-DxXNP32l.d.ts} +8 -0
  154. package/package.json +3 -3
  155. package/src/core/auth-redaction.ts +192 -0
  156. package/src/drafts/draft07/codec.ts +40 -0
  157. package/src/drafts/draft07/error-codes.ts +44 -0
  158. package/src/drafts/draft07/index.ts +15 -0
  159. package/src/drafts/draft08/codec.ts +40 -0
  160. package/src/drafts/draft08/error-codes.ts +76 -0
  161. package/src/drafts/draft08/index.ts +21 -0
  162. package/src/drafts/draft09/codec.ts +40 -0
  163. package/src/drafts/draft09/error-codes.ts +76 -0
  164. package/src/drafts/draft09/index.ts +21 -0
  165. package/src/drafts/draft10/codec.ts +40 -0
  166. package/src/drafts/draft10/error-codes.ts +76 -0
  167. package/src/drafts/draft10/index.ts +21 -0
  168. package/src/drafts/draft11/codec.ts +60 -0
  169. package/src/drafts/draft11/error-codes.ts +106 -0
  170. package/src/drafts/draft11/index.ts +23 -0
  171. package/src/drafts/draft12/codec.ts +61 -0
  172. package/src/drafts/draft12/error-codes.ts +116 -0
  173. package/src/drafts/draft12/index.ts +25 -0
  174. package/src/drafts/draft13/codec.ts +69 -11
  175. package/src/drafts/draft13/error-codes.ts +107 -0
  176. package/src/drafts/draft13/index.ts +23 -0
  177. package/src/drafts/draft13/types.ts +1 -1
  178. package/src/drafts/draft14/codec.ts +65 -4
  179. package/src/drafts/draft14/data-streams.ts +331 -259
  180. package/src/drafts/draft14/error-codes.ts +109 -0
  181. package/src/drafts/draft14/index.ts +23 -0
  182. package/src/drafts/draft15/codec.ts +65 -8
  183. package/src/drafts/draft15/data-streams.ts +489 -444
  184. package/src/drafts/draft15/error-codes.ts +66 -0
  185. package/src/drafts/draft15/index.ts +15 -0
  186. package/src/drafts/draft15/types.ts +7 -0
  187. package/src/drafts/draft16/codec.ts +146 -52
  188. package/src/drafts/draft16/data-streams.ts +513 -442
  189. package/src/drafts/draft16/error-codes.ts +68 -0
  190. package/src/drafts/draft16/index.ts +15 -0
  191. package/src/drafts/draft16/messages.ts +4 -4
  192. package/src/drafts/draft16/session-fsm.ts +0 -1
  193. package/src/drafts/draft16/types.ts +22 -8
  194. package/src/drafts/draft17/codec.ts +73 -12
  195. package/src/drafts/draft17/data-streams.ts +567 -488
  196. package/src/drafts/draft17/index.ts +15 -0
  197. package/src/drafts/draft17/types.ts +7 -0
  198. package/src/drafts/draft18/codec.ts +66 -9
  199. package/src/drafts/draft18/data-streams.ts +570 -482
  200. package/src/drafts/draft18/index.ts +3 -0
  201. package/src/drafts/draft18/types.ts +16 -8
  202. package/src/drafts/draft19/codec.ts +70 -10
  203. package/src/drafts/draft19/data-streams.ts +570 -482
  204. package/src/drafts/draft19/error-codes.ts +3 -1
  205. package/src/drafts/draft19/index.ts +3 -0
  206. package/src/drafts/draft19/messages.ts +3 -1
  207. package/src/drafts/draft19/types.ts +22 -11
  208. package/src/drafts/draft20/codec.ts +90 -23
  209. package/src/drafts/draft20/data-streams.ts +610 -563
  210. package/src/drafts/draft20/index.ts +3 -0
  211. package/src/drafts/draft20/types.ts +14 -2
  212. package/dist/codec-BJ7BHuiZ.d.ts +0 -18
  213. package/dist/codec-C6Mx4bwz.d.cts +0 -18
@@ -1,10 +1,12 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
2
 
3
3
 
4
4
 
5
5
 
6
6
 
7
- var _chunk4XLYCT5Qcjs = require('./chunk-4XLYCT5Q.cjs');
7
+
8
+
9
+ var _chunk5IMHJIAZcjs = require('./chunk-5IMHJIAZ.cjs');
8
10
 
9
11
  // src/drafts/draft18/messages.ts
10
12
  var MSG_REQUEST_UPDATE = 0x02n;
@@ -108,7 +110,7 @@ function isValidSubgroupType(streamType) {
108
110
  return (streamType & 6) !== 6;
109
111
  }
110
112
  function encodeSubgroupStream(stream) {
111
- const w = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)();
113
+ const w = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)();
112
114
  const streamType = stream.headerType;
113
115
  w.writeUint8(streamType);
114
116
  const propertiesPresent = (streamType & 1) !== 0;
@@ -129,7 +131,7 @@ function encodeSubgroupStream(stream) {
129
131
  w.writeVarInt(delta);
130
132
  if (propertiesPresent) {
131
133
  if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
132
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
134
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
133
135
  encodeObjectProperties(obj.objectProperties, tmpW);
134
136
  const raw = tmpW.finish();
135
137
  w.writeVarInt(BigInt(raw.byteLength));
@@ -149,7 +151,7 @@ function encodeSubgroupStream(stream) {
149
151
  return w.finish();
150
152
  }
151
153
  function encodeDatagram(dg) {
152
- const w = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)();
154
+ const w = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)();
153
155
  const dgType = dg.datagramType;
154
156
  w.writeUint8(dgType);
155
157
  w.writeVarInt(dg.trackAlias);
@@ -166,7 +168,7 @@ function encodeDatagram(dg) {
166
168
  }
167
169
  if (propertiesPresent) {
168
170
  if (dg.objectProperties && Object.keys(dg.objectProperties).length > 0) {
169
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
171
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
170
172
  encodeObjectProperties(dg.objectProperties, tmpW);
171
173
  const raw = tmpW.finish();
172
174
  w.writeVarInt(BigInt(raw.byteLength));
@@ -183,7 +185,7 @@ function encodeDatagram(dg) {
183
185
  return w.finish();
184
186
  }
185
187
  function encodeFetchStream(stream) {
186
- const w = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)();
188
+ const w = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)();
187
189
  w.writeVarInt(FETCH_STREAM_TYPE);
188
190
  w.writeVarInt(stream.requestId);
189
191
  let prevGroupId = 0n;
@@ -205,7 +207,7 @@ function encodeFetchStream(stream) {
205
207
  if (flags & 16) w.writeUint8(obj.publisherPriority);
206
208
  if (flags & 32) {
207
209
  if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
208
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
210
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
209
211
  encodeObjectProperties(obj.objectProperties, tmpW);
210
212
  const raw = tmpW.finish();
211
213
  w.writeVarInt(BigInt(raw.byteLength));
@@ -229,7 +231,7 @@ function encodeFetchStream(stream) {
229
231
  if (flags & 16) w.writeUint8(obj.publisherPriority);
230
232
  if (flags & 32) {
231
233
  if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
232
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
234
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
233
235
  encodeObjectProperties(obj.objectProperties, tmpW);
234
236
  const raw = tmpW.finish();
235
237
  w.writeVarInt(BigInt(raw.byteLength));
@@ -250,112 +252,121 @@ function encodeFetchStream(stream) {
250
252
  void prevObjectId;
251
253
  return w.finish();
252
254
  }
255
+ function readSubgroupHeader(r) {
256
+ const streamType = r.readUint8();
257
+ if (!isValidSubgroupType(streamType)) {
258
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
259
+ "CONSTRAINT_VIOLATION",
260
+ `Invalid subgroup stream type 0x${streamType.toString(16)}`,
261
+ 0
262
+ );
263
+ }
264
+ const propertiesPresent = (streamType & 1) !== 0;
265
+ const subgroupMode = (streamType & 6) >> 1;
266
+ const hasSubgroupField = subgroupMode === 2;
267
+ const subgroupIsFirstObjId = subgroupMode === 1;
268
+ const endOfGroup = (streamType & 8) !== 0;
269
+ const hasPriority = (streamType & 32) === 0;
270
+ const firstObjectFlag = (streamType & 64) !== 0;
271
+ const trackAlias = r.readVarInt();
272
+ const groupId = r.readVarInt();
273
+ let subgroupId = 0n;
274
+ if (hasSubgroupField) {
275
+ subgroupId = r.readVarInt();
276
+ }
277
+ let publisherPriority = 128;
278
+ if (hasPriority) {
279
+ publisherPriority = r.readUint8();
280
+ }
281
+ return {
282
+ streamType,
283
+ propertiesPresent,
284
+ subgroupIsFirstObjId,
285
+ endOfGroup,
286
+ firstObjectFlag,
287
+ trackAlias,
288
+ groupId,
289
+ subgroupId,
290
+ publisherPriority
291
+ };
292
+ }
293
+ function readSubgroupObject(r, propertiesPresent, isFirst, prevObjectId, base) {
294
+ const byteOffset = base + r.offset;
295
+ const delta = r.readVarInt();
296
+ const objectId = isFirst ? delta : prevObjectId + 1n + delta;
297
+ const extensionData = new Uint8Array(0);
298
+ let objectProperties;
299
+ if (propertiesPresent) {
300
+ const propsLen = Number(r.readVarInt());
301
+ if (propsLen > 0) {
302
+ objectProperties = decodeObjectProperties(r, propsLen);
303
+ }
304
+ }
305
+ const payloadLength = Number(r.readVarInt());
306
+ let payload;
307
+ let status;
308
+ let payloadByteOffset;
309
+ if (payloadLength === 0) {
310
+ status = r.readVarInt();
311
+ payloadByteOffset = base + r.offset;
312
+ payload = new Uint8Array(0);
313
+ } else {
314
+ payloadByteOffset = base + r.offset;
315
+ payload = r.readBytesView(payloadLength);
316
+ }
317
+ const obj = {
318
+ type: "object",
319
+ byteOffset,
320
+ payloadByteOffset,
321
+ objectId,
322
+ payloadLength,
323
+ payload,
324
+ extensionData
325
+ };
326
+ if (status !== void 0) obj.status = status;
327
+ if (objectProperties !== void 0)
328
+ obj.objectProperties = objectProperties;
329
+ return obj;
330
+ }
253
331
  function decodeSubgroupStream(bytes) {
254
332
  try {
255
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes);
256
- const streamType = r.readUint8();
257
- if (!isValidSubgroupType(streamType)) {
258
- return {
259
- ok: false,
260
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
261
- "CONSTRAINT_VIOLATION",
262
- `Invalid subgroup stream type 0x${streamType.toString(16)}`,
263
- 0
264
- )
265
- };
266
- }
267
- const propertiesPresent = (streamType & 1) !== 0;
268
- const subgroupMode = (streamType & 6) >> 1;
269
- const hasSubgroupField = subgroupMode === 2;
270
- const subgroupIsFirstObjId = subgroupMode === 1;
271
- const endOfGroup = (streamType & 8) !== 0;
272
- const hasPriority = (streamType & 32) === 0;
273
- const firstObject = (streamType & 64) !== 0;
274
- const trackAlias = r.readVarInt();
275
- const groupId = r.readVarInt();
276
- let subgroupId = 0n;
277
- if (hasSubgroupField) {
278
- subgroupId = r.readVarInt();
279
- }
280
- let publisherPriority = 128;
281
- if (hasPriority) {
282
- publisherPriority = r.readUint8();
283
- }
333
+ const r = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes);
334
+ const h = readSubgroupHeader(r);
284
335
  const objects = [];
285
336
  let prevObjectId = -1n;
286
337
  let isFirst = true;
338
+ let subgroupId = h.subgroupId;
287
339
  while (r.remaining > 0) {
288
- const byteOffset = r.offset;
289
- const delta = r.readVarInt();
290
- let objectId;
291
- if (isFirst) {
292
- objectId = delta;
293
- if (subgroupIsFirstObjId) {
294
- subgroupId = objectId;
295
- }
296
- isFirst = false;
297
- } else {
298
- objectId = prevObjectId + 1n + delta;
299
- }
300
- const extensionData = new Uint8Array(0);
301
- let objectProperties;
302
- if (propertiesPresent) {
303
- const propsLen = Number(r.readVarInt());
304
- if (propsLen > 0) {
305
- objectProperties = decodeObjectProperties(r, propsLen);
306
- }
307
- }
308
- const payloadLength = Number(r.readVarInt());
309
- let payload;
310
- let status;
311
- let payloadByteOffset;
312
- if (payloadLength === 0) {
313
- status = r.readVarInt();
314
- payloadByteOffset = r.offset;
315
- payload = new Uint8Array(0);
316
- } else {
317
- payloadByteOffset = r.offset;
318
- payload = r.readBytesView(payloadLength);
319
- }
320
- const obj = {
321
- type: "object",
322
- byteOffset,
323
- payloadByteOffset,
324
- objectId,
325
- payloadLength,
326
- payload,
327
- extensionData
328
- };
329
- if (status !== void 0) obj.status = status;
330
- if (objectProperties !== void 0)
331
- obj.objectProperties = objectProperties;
340
+ const obj = readSubgroupObject(r, h.propertiesPresent, isFirst, prevObjectId, 0);
341
+ if (isFirst && h.subgroupIsFirstObjId) subgroupId = obj.objectId;
342
+ isFirst = false;
332
343
  objects.push(obj);
333
- prevObjectId = objectId;
344
+ prevObjectId = obj.objectId;
334
345
  }
335
346
  const result = {
336
347
  type: "subgroup",
337
- headerType: streamType,
338
- trackAlias,
339
- groupId,
348
+ headerType: h.streamType,
349
+ trackAlias: h.trackAlias,
350
+ groupId: h.groupId,
340
351
  subgroupId,
341
- publisherPriority,
342
- objects
352
+ publisherPriority: h.publisherPriority,
353
+ objects,
354
+ ...h.endOfGroup ? { endOfGroup: true } : {},
355
+ ...h.firstObjectFlag ? { firstObject: true } : {}
343
356
  };
344
- if (endOfGroup) result.endOfGroup = true;
345
- if (firstObject) result.firstObject = true;
346
357
  return {
347
358
  ok: true,
348
359
  value: result,
349
360
  bytesRead: r.offset
350
361
  };
351
362
  } catch (e) {
352
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) return { ok: false, error: e };
363
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
353
364
  throw e;
354
365
  }
355
366
  }
356
367
  function decodeDatagram(bytes) {
357
368
  try {
358
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes);
369
+ const r = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes);
359
370
  const dgType = r.readUint8();
360
371
  const objectIdAbsent = (dgType & 4) !== 0;
361
372
  const endOfGroup = (dgType & 2) !== 0;
@@ -405,18 +416,190 @@ function decodeDatagram(bytes) {
405
416
  result.objectProperties = objectProperties;
406
417
  return { ok: true, value: result, bytesRead: r.offset };
407
418
  } catch (e) {
408
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) return { ok: false, error: e };
419
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
409
420
  throw e;
410
421
  }
411
422
  }
423
+ function newFetchObjectState() {
424
+ return { prevGroupId: 0n, prevSubgroupId: 0n, prevObjectId: 0n, prevPriority: 128, first: true };
425
+ }
426
+ function readFetchObject(r, base, st) {
427
+ const byteOffset = base + r.offset;
428
+ const flags = Number(r.readVarInt());
429
+ let groupId = st.prevGroupId;
430
+ let subgroupId = st.prevSubgroupId;
431
+ let objectId = st.prevObjectId + 1n;
432
+ let payloadLength;
433
+ let payload;
434
+ let payloadByteOffset;
435
+ const extensionData = new Uint8Array(0);
436
+ if (flags >= 128) {
437
+ if (flags !== 140 && flags !== 268) {
438
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
439
+ "CONSTRAINT_VIOLATION",
440
+ `Unknown serialization flags value: 0x${flags.toString(16)}`,
441
+ r.offset
442
+ );
443
+ }
444
+ groupId = r.readVarInt();
445
+ objectId = r.readVarInt();
446
+ payloadLength = Number(r.readVarInt());
447
+ payloadByteOffset = base + r.offset;
448
+ payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
449
+ } else if (flags & 64) {
450
+ const objectIdPresent = (flags & 4) !== 0;
451
+ const groupIdPresent = (flags & 8) !== 0;
452
+ const priorityPresent = (flags & 16) !== 0;
453
+ const propsPresent = (flags & 32) !== 0;
454
+ if (groupIdPresent) {
455
+ const groupDelta = r.readVarInt();
456
+ groupId = st.first ? groupDelta : st.prevGroupId + groupDelta + 1n;
457
+ }
458
+ if (objectIdPresent) {
459
+ objectId = r.readVarInt();
460
+ }
461
+ if (priorityPresent) {
462
+ st.prevPriority = r.readUint8();
463
+ }
464
+ let objectProperties;
465
+ if (propsPresent) {
466
+ const propsLen = Number(r.readVarInt());
467
+ if (propsLen > 0) {
468
+ objectProperties = decodeObjectProperties(r, propsLen);
469
+ }
470
+ }
471
+ payloadLength = Number(r.readVarInt());
472
+ payloadByteOffset = base + r.offset;
473
+ payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
474
+ const obj2 = {
475
+ type: "object",
476
+ byteOffset,
477
+ payloadByteOffset,
478
+ serializationFlags: flags,
479
+ groupId,
480
+ subgroupId: 0n,
481
+ objectId,
482
+ publisherPriority: st.prevPriority,
483
+ payloadLength,
484
+ payload,
485
+ extensionData
486
+ };
487
+ if (objectProperties)
488
+ obj2.objectProperties = objectProperties;
489
+ st.prevGroupId = groupId;
490
+ st.prevObjectId = objectId;
491
+ st.first = false;
492
+ return obj2;
493
+ } else {
494
+ const subgroupEncoding = flags & 3;
495
+ const objectIdPresent = (flags & 4) !== 0;
496
+ const groupIdPresent = (flags & 8) !== 0;
497
+ const priorityPresent = (flags & 16) !== 0;
498
+ const propsPresent = (flags & 32) !== 0;
499
+ if (groupIdPresent) {
500
+ const groupDelta = r.readVarInt();
501
+ groupId = st.first ? groupDelta : st.prevGroupId + groupDelta + 1n;
502
+ } else if (st.first) {
503
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
504
+ "CONSTRAINT_VIOLATION",
505
+ "First fetch object must include groupId",
506
+ r.offset
507
+ );
508
+ }
509
+ if (subgroupEncoding === 0) {
510
+ subgroupId = 0n;
511
+ } else if (subgroupEncoding === 1) {
512
+ if (st.first) {
513
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
514
+ "CONSTRAINT_VIOLATION",
515
+ "First fetch object cannot reference prior subgroupId",
516
+ r.offset
517
+ );
518
+ }
519
+ subgroupId = st.prevSubgroupId;
520
+ } else if (subgroupEncoding === 2) {
521
+ if (st.first) {
522
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
523
+ "CONSTRAINT_VIOLATION",
524
+ "First fetch object cannot reference prior subgroupId",
525
+ r.offset
526
+ );
527
+ }
528
+ subgroupId = st.prevSubgroupId + 1n;
529
+ } else if (subgroupEncoding === 3) {
530
+ subgroupId = r.readVarInt();
531
+ }
532
+ if (objectIdPresent) {
533
+ objectId = r.readVarInt();
534
+ } else if (st.first) {
535
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
536
+ "CONSTRAINT_VIOLATION",
537
+ "First fetch object must include objectId",
538
+ r.offset
539
+ );
540
+ }
541
+ if (priorityPresent) {
542
+ st.prevPriority = r.readUint8();
543
+ }
544
+ let objectProperties;
545
+ if (propsPresent) {
546
+ const propsLen = Number(r.readVarInt());
547
+ if (propsLen > 0) {
548
+ objectProperties = decodeObjectProperties(r, propsLen);
549
+ }
550
+ }
551
+ payloadLength = Number(r.readVarInt());
552
+ payloadByteOffset = base + r.offset;
553
+ payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
554
+ if (objectProperties) {
555
+ const obj2 = {
556
+ type: "object",
557
+ byteOffset,
558
+ payloadByteOffset,
559
+ serializationFlags: flags,
560
+ groupId,
561
+ subgroupId,
562
+ objectId,
563
+ publisherPriority: st.prevPriority,
564
+ payloadLength,
565
+ payload,
566
+ extensionData
567
+ };
568
+ obj2.objectProperties = objectProperties;
569
+ st.prevGroupId = groupId;
570
+ st.prevSubgroupId = subgroupId;
571
+ st.prevObjectId = objectId;
572
+ st.first = false;
573
+ return obj2;
574
+ }
575
+ }
576
+ const obj = {
577
+ type: "object",
578
+ byteOffset,
579
+ payloadByteOffset,
580
+ serializationFlags: flags,
581
+ groupId,
582
+ subgroupId,
583
+ objectId,
584
+ publisherPriority: st.prevPriority,
585
+ payloadLength,
586
+ payload,
587
+ extensionData
588
+ };
589
+ st.prevGroupId = groupId;
590
+ st.prevSubgroupId = subgroupId;
591
+ st.prevObjectId = objectId;
592
+ st.first = false;
593
+ return obj;
594
+ }
412
595
  function decodeFetchStream(bytes) {
413
596
  try {
414
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes);
597
+ const r = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes);
415
598
  const streamType = r.readVarInt();
416
599
  if (streamType !== FETCH_STREAM_TYPE) {
417
600
  return {
418
601
  ok: false,
419
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
602
+ error: new (0, _chunk5IMHJIAZcjs.DecodeError)(
420
603
  "CONSTRAINT_VIOLATION",
421
604
  `Expected fetch stream type 0x05, got 0x${streamType.toString(16)}`,
422
605
  0
@@ -425,196 +608,9 @@ function decodeFetchStream(bytes) {
425
608
  }
426
609
  const requestId = r.readVarInt();
427
610
  const objects = [];
428
- let prevGroupId = 0n;
429
- let prevSubgroupId = 0n;
430
- let prevObjectId = 0n;
431
- let prevPriority = 128;
432
- let first = true;
611
+ const st = newFetchObjectState();
433
612
  while (r.remaining > 0) {
434
- const byteOffset = r.offset;
435
- const flags = Number(r.readVarInt());
436
- let groupId = prevGroupId;
437
- let subgroupId = prevSubgroupId;
438
- let objectId = prevObjectId + 1n;
439
- let payloadLength;
440
- let payload;
441
- let payloadByteOffset;
442
- const extensionData = new Uint8Array(0);
443
- if (flags >= 128) {
444
- if (flags !== 140 && flags !== 268) {
445
- return {
446
- ok: false,
447
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
448
- "CONSTRAINT_VIOLATION",
449
- `Unknown serialization flags value: 0x${flags.toString(16)}`,
450
- r.offset
451
- )
452
- };
453
- }
454
- groupId = r.readVarInt();
455
- objectId = r.readVarInt();
456
- payloadLength = Number(r.readVarInt());
457
- payloadByteOffset = r.offset;
458
- payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
459
- } else if (flags & 64) {
460
- const objectIdPresent = (flags & 4) !== 0;
461
- const groupIdPresent = (flags & 8) !== 0;
462
- const priorityPresent = (flags & 16) !== 0;
463
- const propsPresent = (flags & 32) !== 0;
464
- if (groupIdPresent) {
465
- const groupDelta = r.readVarInt();
466
- groupId = first ? groupDelta : prevGroupId + groupDelta + 1n;
467
- }
468
- if (objectIdPresent) {
469
- objectId = r.readVarInt();
470
- }
471
- if (priorityPresent) {
472
- prevPriority = r.readUint8();
473
- }
474
- let objectProperties;
475
- if (propsPresent) {
476
- const propsLen = Number(r.readVarInt());
477
- if (propsLen > 0) {
478
- objectProperties = decodeObjectProperties(r, propsLen);
479
- }
480
- }
481
- payloadLength = Number(r.readVarInt());
482
- payloadByteOffset = r.offset;
483
- payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
484
- const obj2 = {
485
- type: "object",
486
- byteOffset,
487
- payloadByteOffset,
488
- serializationFlags: flags,
489
- groupId,
490
- subgroupId: 0n,
491
- objectId,
492
- publisherPriority: prevPriority,
493
- payloadLength,
494
- payload,
495
- extensionData
496
- };
497
- if (objectProperties)
498
- obj2.objectProperties = objectProperties;
499
- objects.push(obj2);
500
- prevGroupId = groupId;
501
- prevObjectId = objectId;
502
- first = false;
503
- continue;
504
- } else {
505
- const subgroupEncoding = flags & 3;
506
- const objectIdPresent = (flags & 4) !== 0;
507
- const groupIdPresent = (flags & 8) !== 0;
508
- const priorityPresent = (flags & 16) !== 0;
509
- const propsPresent = (flags & 32) !== 0;
510
- if (groupIdPresent) {
511
- const groupDelta = r.readVarInt();
512
- groupId = first ? groupDelta : prevGroupId + groupDelta + 1n;
513
- } else if (first) {
514
- return {
515
- ok: false,
516
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
517
- "CONSTRAINT_VIOLATION",
518
- "First fetch object must include groupId",
519
- r.offset
520
- )
521
- };
522
- }
523
- if (subgroupEncoding === 0) {
524
- subgroupId = 0n;
525
- } else if (subgroupEncoding === 1) {
526
- if (first) {
527
- return {
528
- ok: false,
529
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
530
- "CONSTRAINT_VIOLATION",
531
- "First fetch object cannot reference prior subgroupId",
532
- r.offset
533
- )
534
- };
535
- }
536
- subgroupId = prevSubgroupId;
537
- } else if (subgroupEncoding === 2) {
538
- if (first) {
539
- return {
540
- ok: false,
541
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
542
- "CONSTRAINT_VIOLATION",
543
- "First fetch object cannot reference prior subgroupId",
544
- r.offset
545
- )
546
- };
547
- }
548
- subgroupId = prevSubgroupId + 1n;
549
- } else if (subgroupEncoding === 3) {
550
- subgroupId = r.readVarInt();
551
- }
552
- if (objectIdPresent) {
553
- objectId = r.readVarInt();
554
- } else if (first) {
555
- return {
556
- ok: false,
557
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
558
- "CONSTRAINT_VIOLATION",
559
- "First fetch object must include objectId",
560
- r.offset
561
- )
562
- };
563
- }
564
- if (priorityPresent) {
565
- prevPriority = r.readUint8();
566
- }
567
- let objectProperties;
568
- if (propsPresent) {
569
- const propsLen = Number(r.readVarInt());
570
- if (propsLen > 0) {
571
- objectProperties = decodeObjectProperties(r, propsLen);
572
- }
573
- }
574
- payloadLength = Number(r.readVarInt());
575
- payloadByteOffset = r.offset;
576
- payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
577
- if (objectProperties) {
578
- const obj2 = {
579
- type: "object",
580
- byteOffset,
581
- payloadByteOffset,
582
- serializationFlags: flags,
583
- groupId,
584
- subgroupId,
585
- objectId,
586
- publisherPriority: prevPriority,
587
- payloadLength,
588
- payload,
589
- extensionData
590
- };
591
- obj2.objectProperties = objectProperties;
592
- objects.push(obj2);
593
- prevGroupId = groupId;
594
- prevSubgroupId = subgroupId;
595
- prevObjectId = objectId;
596
- first = false;
597
- continue;
598
- }
599
- }
600
- const obj = {
601
- type: "object",
602
- byteOffset,
603
- payloadByteOffset,
604
- serializationFlags: flags,
605
- groupId,
606
- subgroupId,
607
- objectId,
608
- publisherPriority: prevPriority,
609
- payloadLength,
610
- payload,
611
- extensionData
612
- };
613
- objects.push(obj);
614
- prevGroupId = groupId;
615
- prevSubgroupId = subgroupId;
616
- prevObjectId = objectId;
617
- first = false;
613
+ objects.push(readFetchObject(r, 0, st));
618
614
  }
619
615
  return {
620
616
  ok: true,
@@ -622,7 +618,7 @@ function decodeFetchStream(bytes) {
622
618
  bytesRead: r.offset
623
619
  };
624
620
  } catch (e) {
625
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) return { ok: false, error: e };
621
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
626
622
  throw e;
627
623
  }
628
624
  }
@@ -640,135 +636,125 @@ function decodeDataStream(streamType, bytes) {
640
636
  }
641
637
  }
642
638
  }
639
+ var StreamBuffer = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this); }
640
+ __init() {this.buf = new Uint8Array(0)}
641
+ /** Bytes written into `buf`. */
642
+ __init2() {this.len = 0}
643
+ /** Consumed prefix of `buf`; `base + offset` is the position in the stream. */
644
+ __init3() {this.offset = 0}
645
+ /** Absolute position of `buf[0]` within the stream. */
646
+ __init4() {this.base = 0}
647
+ get unread() {
648
+ return this.len - this.offset;
649
+ }
650
+ append(chunk) {
651
+ if (this.len + chunk.length > this.buf.length) {
652
+ const live = this.len - this.offset;
653
+ const needed = live + chunk.length;
654
+ let cap = Math.max(4096, this.buf.length);
655
+ while (cap < needed * 2) cap *= 2;
656
+ const next = new Uint8Array(cap);
657
+ next.set(this.buf.subarray(this.offset, this.len), 0);
658
+ this.buf = next;
659
+ this.base += this.offset;
660
+ this.len = live;
661
+ this.offset = 0;
662
+ }
663
+ this.buf.set(chunk, this.len);
664
+ this.len += chunk.length;
665
+ }
666
+ /**
667
+ * The written bytes, for a reader positioned at `offset`. Bounded by `len`
668
+ * rather than by capacity, so `BufferReader.remaining` counts real bytes and
669
+ * not the spare room after them.
670
+ */
671
+ written() {
672
+ return this.buf.subarray(0, this.len);
673
+ }
674
+ }, _class);
643
675
  function createSubgroupStreamDecoder() {
644
- let buffer = new Uint8Array(0);
645
- let offset = 0;
676
+ const b = new StreamBuffer();
677
+ let header = null;
646
678
  let headerEmitted = false;
647
679
  let prevObjectId = -1n;
648
- let firstObject = true;
649
- let _propertiesPresent = false;
680
+ let isFirst = true;
681
+ function emitHeader(controller, h, subgroupId) {
682
+ controller.enqueue({
683
+ type: "subgroup_header",
684
+ headerType: h.streamType,
685
+ trackAlias: h.trackAlias,
686
+ groupId: h.groupId,
687
+ subgroupId,
688
+ publisherPriority: h.publisherPriority,
689
+ ...h.endOfGroup ? { endOfGroup: true } : {},
690
+ ...h.firstObjectFlag ? { firstObject: true } : {}
691
+ });
692
+ headerEmitted = true;
693
+ }
650
694
  return new TransformStream({
651
695
  transform(chunk, controller) {
652
- if (offset > 0) {
653
- buffer = buffer.subarray(offset);
654
- offset = 0;
655
- }
656
- const newBuffer = new Uint8Array(buffer.length + chunk.length);
657
- newBuffer.set(buffer, 0);
658
- newBuffer.set(chunk, buffer.length);
659
- buffer = newBuffer;
660
- if (!headerEmitted) {
696
+ b.append(chunk);
697
+ const view = b.written();
698
+ if (header === null) {
661
699
  try {
662
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(buffer.subarray(offset));
663
- const streamType = r.readUint8();
664
- if (!isValidSubgroupType(streamType)) {
665
- controller.error(
666
- new (0, _chunk4XLYCT5Qcjs.DecodeError)(
667
- "CONSTRAINT_VIOLATION",
668
- `Invalid subgroup stream type 0x${streamType.toString(16)}`,
669
- 0
670
- )
671
- );
672
- return;
673
- }
674
- _propertiesPresent = (streamType & 1) !== 0;
675
- const subgroupMode = (streamType & 6) >> 1;
676
- const hasSubgroupField = subgroupMode === 2;
677
- const hasPriority = (streamType & 32) === 0;
678
- const trackAlias = r.readVarInt();
679
- const groupId = r.readVarInt();
680
- let subgroupId = 0n;
681
- if (hasSubgroupField) {
682
- subgroupId = r.readVarInt();
683
- }
684
- let publisherPriority = 128;
685
- if (hasPriority) {
686
- publisherPriority = r.readUint8();
687
- }
688
- controller.enqueue({
689
- type: "subgroup_header",
690
- trackAlias,
691
- groupId,
692
- subgroupId,
693
- publisherPriority
694
- });
695
- headerEmitted = true;
696
- offset += r.offset;
700
+ const hr = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(view, b.offset);
701
+ header = readSubgroupHeader(hr);
702
+ b.offset = hr.offset;
697
703
  } catch (e) {
698
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError && e.code === "UNEXPECTED_END") {
704
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
699
705
  return;
700
706
  }
701
707
  controller.error(e);
702
708
  return;
703
709
  }
710
+ if (!header.subgroupIsFirstObjId) emitHeader(controller, header, header.subgroupId);
704
711
  }
705
- while (offset < buffer.length) {
712
+ const h = header;
713
+ if (h === null) return;
714
+ const r = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(view, b.offset);
715
+ while (r.remaining > 0) {
716
+ const start = r.offset;
717
+ let obj;
706
718
  try {
707
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(buffer.subarray(offset));
708
- const delta = r.readVarInt();
709
- let objectId;
710
- if (firstObject) {
711
- objectId = delta;
712
- firstObject = false;
713
- } else {
714
- objectId = prevObjectId + 1n + delta;
715
- }
716
- let extensionData = new Uint8Array(0);
717
- if (_propertiesPresent) {
718
- const extLen = Number(r.readVarInt());
719
- extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
720
- }
721
- const payloadLength = Number(r.readVarInt());
722
- const payloadByteOffset = r.offset;
723
- const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
724
- controller.enqueue({
725
- type: "object",
726
- objectId,
727
- payloadLength,
728
- payload,
729
- extensionData,
730
- byteOffset: 0,
731
- payloadByteOffset
732
- });
733
- offset += r.offset;
734
- prevObjectId = objectId;
719
+ obj = readSubgroupObject(r, h.propertiesPresent, isFirst, prevObjectId, b.base);
735
720
  } catch (e) {
736
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError && e.code === "UNEXPECTED_END") {
737
- break;
721
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
722
+ b.offset = start;
723
+ return;
738
724
  }
739
725
  controller.error(e);
740
726
  return;
741
727
  }
728
+ if (!headerEmitted) emitHeader(controller, h, obj.objectId);
729
+ isFirst = false;
730
+ b.offset = r.offset;
731
+ prevObjectId = obj.objectId;
732
+ controller.enqueue(obj);
742
733
  }
743
734
  },
744
735
  flush(controller) {
745
- if (offset < buffer.length) {
746
- controller.error(new (0, _chunk4XLYCT5Qcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
736
+ if (header !== null && !headerEmitted) emitHeader(controller, header, 0n);
737
+ if (b.unread > 0) {
738
+ controller.error(new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
747
739
  }
748
740
  }
749
741
  });
750
742
  }
751
743
  function createFetchStreamDecoder() {
752
- let buffer = new Uint8Array(0);
753
- let offset = 0;
744
+ const b = new StreamBuffer();
754
745
  let headerEmitted = false;
746
+ const st = newFetchObjectState();
755
747
  return new TransformStream({
756
748
  transform(chunk, controller) {
757
- if (offset > 0) {
758
- buffer = buffer.subarray(offset);
759
- offset = 0;
760
- }
761
- const newBuffer = new Uint8Array(buffer.length + chunk.length);
762
- newBuffer.set(buffer, 0);
763
- newBuffer.set(chunk, buffer.length);
764
- buffer = newBuffer;
749
+ b.append(chunk);
750
+ const view = b.written();
765
751
  if (!headerEmitted) {
766
752
  try {
767
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(buffer.subarray(offset));
768
- const streamType = r.readVarInt();
753
+ const r2 = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(view, b.offset);
754
+ const streamType = r2.readVarInt();
769
755
  if (streamType !== FETCH_STREAM_TYPE) {
770
756
  controller.error(
771
- new (0, _chunk4XLYCT5Qcjs.DecodeError)(
757
+ new (0, _chunk5IMHJIAZcjs.DecodeError)(
772
758
  "CONSTRAINT_VIOLATION",
773
759
  `Expected fetch stream type 0x05, got 0x${streamType.toString(16)}`,
774
760
  0
@@ -776,113 +762,96 @@ function createFetchStreamDecoder() {
776
762
  );
777
763
  return;
778
764
  }
779
- const requestId = r.readVarInt();
765
+ const requestId = r2.readVarInt();
780
766
  controller.enqueue({ type: "fetch_header", requestId });
781
767
  headerEmitted = true;
782
- offset += r.offset;
768
+ b.offset = r2.offset;
783
769
  } catch (e) {
784
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError && e.code === "UNEXPECTED_END") {
770
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
785
771
  return;
786
772
  }
787
773
  controller.error(e);
788
774
  return;
789
775
  }
790
776
  }
791
- while (offset < buffer.length) {
777
+ const r = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(view, b.offset);
778
+ while (r.remaining > 0) {
779
+ const start = r.offset;
780
+ let obj;
792
781
  try {
793
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(buffer.subarray(offset));
794
- const flags = Number(r.readVarInt());
795
- const objectIdPresent = (flags & 4) !== 0;
796
- const groupIdPresent = (flags & 8) !== 0;
797
- const priorityPresent = (flags & 16) !== 0;
798
- const extensionsPresent = (flags & 32) !== 0;
799
- const subgroupEncoding = flags & 3;
800
- if (groupIdPresent) r.readVarInt();
801
- if (subgroupEncoding === 3) r.readVarInt();
802
- let objectId = 0n;
803
- if (objectIdPresent) objectId = r.readVarInt();
804
- if (priorityPresent) r.readUint8();
805
- let extensionData = new Uint8Array(0);
806
- if (extensionsPresent) {
807
- const extLen = Number(r.readVarInt());
808
- extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
809
- }
810
- const payloadLength = Number(r.readVarInt());
811
- const payloadByteOffset = r.offset;
812
- const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
813
- controller.enqueue({
814
- type: "object",
815
- objectId,
816
- payloadLength,
817
- payload,
818
- extensionData,
819
- byteOffset: 0,
820
- payloadByteOffset
821
- });
822
- offset += r.offset;
782
+ obj = readFetchObject(r, b.base, st);
823
783
  } catch (e) {
824
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError && e.code === "UNEXPECTED_END") {
825
- break;
784
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
785
+ b.offset = start;
786
+ return;
826
787
  }
827
788
  controller.error(e);
828
789
  return;
829
790
  }
791
+ b.offset = r.offset;
792
+ controller.enqueue(obj);
830
793
  }
831
794
  },
832
795
  flush(controller) {
833
- if (offset < buffer.length) {
834
- controller.error(new (0, _chunk4XLYCT5Qcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
796
+ if (b.unread > 0) {
797
+ controller.error(new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
835
798
  }
836
799
  }
837
800
  });
838
801
  }
839
802
  function createDataStreamDecoder() {
840
- let buffer = new Uint8Array(0);
841
- let offset = 0;
842
- let inner = null;
843
- return new TransformStream({
844
- transform(chunk, controller) {
845
- if (offset > 0) {
846
- buffer = buffer.subarray(offset);
847
- offset = 0;
848
- }
849
- const newBuffer = new Uint8Array(buffer.length + chunk.length);
850
- newBuffer.set(buffer, 0);
851
- newBuffer.set(chunk, buffer.length);
852
- buffer = newBuffer;
853
- if (inner === null) {
854
- if (offset >= buffer.length) return;
855
- const firstByte = buffer[offset];
856
- if (isValidSubgroupType(firstByte)) {
857
- const decoder = createSubgroupStreamDecoder();
858
- inner = decoder;
859
- } else if (firstByte === 5) {
860
- const decoder = createFetchStreamDecoder();
861
- inner = decoder;
862
- } else {
863
- controller.error(
864
- new (0, _chunk4XLYCT5Qcjs.DecodeError)(
865
- "CONSTRAINT_VIOLATION",
866
- `Unknown data stream type: 0x${firstByte.toString(16)}`,
867
- 0
868
- )
869
- );
870
- return;
803
+ let writer = null;
804
+ let pump = Promise.resolve();
805
+ let broken = false;
806
+ function attach(inner, controller) {
807
+ writer = inner.writable.getWriter();
808
+ const reader = inner.readable.getReader();
809
+ pump = (async () => {
810
+ try {
811
+ for (; ; ) {
812
+ const { done, value } = await reader.read();
813
+ if (done) break;
814
+ controller.enqueue(value);
815
+ }
816
+ } catch (e) {
817
+ if (!broken) {
818
+ broken = true;
819
+ controller.error(e);
871
820
  }
872
821
  }
873
- },
874
- flush(controller) {
875
- if (offset >= buffer.length) return;
876
- const view = buffer.subarray(offset);
877
- const firstByte = view[0];
878
- let result;
822
+ })();
823
+ }
824
+ async function feed(bytes) {
825
+ if (writer === null || broken || bytes.length === 0) return;
826
+ try {
827
+ await writer.write(bytes);
828
+ } catch (e2) {
829
+ broken = true;
830
+ }
831
+ }
832
+ return new TransformStream({
833
+ async transform(chunk, controller) {
834
+ if (broken) return;
835
+ if (writer !== null) {
836
+ await feed(chunk);
837
+ return;
838
+ }
839
+ if (chunk.length === 0) return;
840
+ const firstByte = chunk[0];
879
841
  if (isValidSubgroupType(firstByte)) {
880
- result = decodeSubgroupStream(view);
842
+ attach(
843
+ createSubgroupStreamDecoder(),
844
+ controller
845
+ );
881
846
  } else if (firstByte === 5) {
882
- result = decodeFetchStream(view);
847
+ attach(
848
+ createFetchStreamDecoder(),
849
+ controller
850
+ );
883
851
  } else {
852
+ broken = true;
884
853
  controller.error(
885
- new (0, _chunk4XLYCT5Qcjs.DecodeError)(
854
+ new (0, _chunk5IMHJIAZcjs.DecodeError)(
886
855
  "CONSTRAINT_VIOLATION",
887
856
  `Unknown data stream type: 0x${firstByte.toString(16)}`,
888
857
  0
@@ -890,31 +859,15 @@ function createDataStreamDecoder() {
890
859
  );
891
860
  return;
892
861
  }
893
- if (!result.ok) {
894
- controller.error(result.error);
895
- return;
896
- }
897
- const stream = result.value;
898
- if (stream.type === "subgroup") {
899
- controller.enqueue({
900
- type: "subgroup_header",
901
- trackAlias: stream.trackAlias,
902
- groupId: stream.groupId,
903
- subgroupId: stream.subgroupId,
904
- publisherPriority: stream.publisherPriority
905
- });
906
- for (const obj of stream.objects) {
907
- controller.enqueue(obj);
908
- }
909
- } else if (stream.type === "fetch") {
910
- controller.enqueue({
911
- type: "fetch_header",
912
- requestId: stream.requestId
913
- });
914
- for (const obj of stream.objects) {
915
- controller.enqueue(obj);
916
- }
862
+ await feed(chunk);
863
+ },
864
+ async flush() {
865
+ if (writer === null) return;
866
+ try {
867
+ await writer.close();
868
+ } catch (e3) {
917
869
  }
870
+ await pump;
918
871
  }
919
872
  });
920
873
  }
@@ -939,7 +892,7 @@ function encodeSetupOptions(opts, writer) {
939
892
  entries.push({
940
893
  type: SETUP_OPT_AUTHORIZATION_TOKEN,
941
894
  encode: (w) => {
942
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(64);
895
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(64);
943
896
  encodeAuthorizationToken(token, tmpW);
944
897
  const raw = tmpW.finish();
945
898
  w.writeVarInt(BigInt(raw.byteLength));
@@ -980,11 +933,11 @@ function encodeSetupOptions(opts, writer) {
980
933
  type: id,
981
934
  encode: (w) => {
982
935
  if (id % 2n === 0n) {
983
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
984
- const tmpReader = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(raw);
936
+ const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
937
+ const tmpReader = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(raw);
985
938
  w.writeVarInt(tmpReader.readVarInt());
986
939
  } else {
987
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
940
+ const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
988
941
  w.writeVarInt(BigInt(raw.byteLength));
989
942
  w.writeBytes(raw);
990
943
  }
@@ -1013,13 +966,13 @@ function decodeSetupOptions(reader, payloadEnd) {
1013
966
  if (optType === SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE) {
1014
967
  result.max_auth_token_cache_size = value;
1015
968
  } else {
1016
- const tmpWriter = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(16);
969
+ const tmpWriter = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(16);
1017
970
  tmpWriter.writeVarInt(value);
1018
971
  const raw = tmpWriter.finish();
1019
972
  unknown.push({
1020
973
  id: `0x${optType.toString(16)}`,
1021
974
  length: raw.byteLength,
1022
- raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, raw)
975
+ raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, raw)
1023
976
  });
1024
977
  }
1025
978
  } else {
@@ -1028,10 +981,9 @@ function decodeSetupOptions(reader, payloadEnd) {
1028
981
  if (optType === SETUP_OPT_PATH) {
1029
982
  result.path = textDecoder.decode(bytes);
1030
983
  } else if (optType === SETUP_OPT_AUTHORIZATION_TOKEN) {
1031
- result.authorization_token = [
1032
- ..._nullishCoalesce(result.authorization_token, () => ( [])),
1033
- decodeAuthorizationToken(new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes))
1034
- ];
984
+ const token = decodeAuthorizationToken(new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes));
985
+ noteAuthTokenValue(reader.offset - length, length, token.token_value);
986
+ result.authorization_token = [..._nullishCoalesce(result.authorization_token, () => ( [])), token];
1035
987
  } else if (optType === SETUP_OPT_AUTHORITY) {
1036
988
  result.authority = textDecoder.decode(bytes);
1037
989
  } else if (optType === SETUP_OPT_MOQT_IMPLEMENTATION) {
@@ -1040,7 +992,7 @@ function decodeSetupOptions(reader, payloadEnd) {
1040
992
  unknown.push({
1041
993
  id: `0x${optType.toString(16)}`,
1042
994
  length,
1043
- raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, bytes)
995
+ raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, bytes)
1044
996
  });
1045
997
  }
1046
998
  }
@@ -1145,7 +1097,7 @@ function encodeParams(params, writer) {
1145
1097
  entries.push({
1146
1098
  type: PARAM_AUTHORIZATION_TOKEN,
1147
1099
  encode: (w) => {
1148
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(64);
1100
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(64);
1149
1101
  encodeAuthorizationToken(token, tmpW);
1150
1102
  const raw = tmpW.finish();
1151
1103
  w.writeVarInt(BigInt(raw.byteLength));
@@ -1206,7 +1158,7 @@ function encodeParams(params, writer) {
1206
1158
  type: PARAM_SUBSCRIPTION_FILTER,
1207
1159
  encode: (w) => {
1208
1160
  const f = params.subscription_filter;
1209
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
1161
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
1210
1162
  tmpW.writeVarInt(f.filter_type);
1211
1163
  if (f.filter_type === 3n || f.filter_type === 4n) {
1212
1164
  tmpW.writeVarInt(f.start_group);
@@ -1250,7 +1202,7 @@ function encodeParams(params, writer) {
1250
1202
  entries.push({
1251
1203
  type: id,
1252
1204
  encode: (w) => {
1253
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
1205
+ const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
1254
1206
  w.writeBytes(raw);
1255
1207
  }
1256
1208
  });
@@ -1275,7 +1227,7 @@ function decodeParams(reader, messageType) {
1275
1227
  prevType = paramType;
1276
1228
  const scope = PARAMETER_SCOPE.get(paramType);
1277
1229
  if (scope !== void 0 && !scope.has(messageType)) {
1278
- throw new (0, _chunk4XLYCT5Qcjs.DecodeError)(
1230
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
1279
1231
  "CONSTRAINT_VIOLATION",
1280
1232
  `Message Parameter 0x${paramType.toString(16)} may not appear in ${messageType}`,
1281
1233
  reader.offset
@@ -1286,10 +1238,9 @@ function decodeParams(reader, messageType) {
1286
1238
  } else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
1287
1239
  const length = Number(reader.readVarInt());
1288
1240
  const bytes = reader.readBytes(length);
1289
- result.authorization_token = [
1290
- ..._nullishCoalesce(result.authorization_token, () => ( [])),
1291
- decodeAuthorizationToken(new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes))
1292
- ];
1241
+ const token = decodeAuthorizationToken(new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes));
1242
+ noteAuthTokenValue(reader.offset - length, length, token.token_value);
1243
+ result.authorization_token = [..._nullishCoalesce(result.authorization_token, () => ( [])), token];
1293
1244
  } else if (paramType === PARAM_RENDEZVOUS_TIMEOUT) {
1294
1245
  result.rendezvous_timeout = reader.readVarInt();
1295
1246
  } else if (paramType === PARAM_SUBGROUP_DELIVERY_TIMEOUT) {
@@ -1328,7 +1279,7 @@ function decodeParams(reader, messageType) {
1328
1279
  } else if (paramType === PARAM_TRACK_NAMESPACE_PREFIX) {
1329
1280
  result.track_namespace_prefix = decodeNamespaceTuple(reader);
1330
1281
  } else {
1331
- throw new (0, _chunk4XLYCT5Qcjs.DecodeError)(
1282
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
1332
1283
  "INVALID_PARAMETER",
1333
1284
  `Unknown Message Parameter type 0x${paramType.toString(16)}`,
1334
1285
  reader.offset
@@ -1399,11 +1350,11 @@ function encodeTrackProperties(props, writer) {
1399
1350
  type: id,
1400
1351
  encode: (w) => {
1401
1352
  if (id % 2n === 0n) {
1402
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
1403
- const tmpReader = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(raw);
1353
+ const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
1354
+ const tmpReader = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(raw);
1404
1355
  w.writeVarInt(tmpReader.readVarInt());
1405
1356
  } else {
1406
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
1357
+ const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
1407
1358
  w.writeVarInt(BigInt(raw.byteLength));
1408
1359
  w.writeBytes(raw);
1409
1360
  }
@@ -1442,13 +1393,13 @@ function decodeTrackProperties(reader, payloadEnd) {
1442
1393
  } else if (propType === TPROP_DYNAMIC_GROUPS) {
1443
1394
  result.dynamic_groups = value;
1444
1395
  } else {
1445
- const tmpWriter = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(16);
1396
+ const tmpWriter = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(16);
1446
1397
  tmpWriter.writeVarInt(value);
1447
1398
  const raw = tmpWriter.finish();
1448
1399
  unknown.push({
1449
1400
  id: `0x${propType.toString(16)}`,
1450
1401
  length: raw.byteLength,
1451
- raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, raw)
1402
+ raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, raw)
1452
1403
  });
1453
1404
  }
1454
1405
  } else {
@@ -1460,7 +1411,7 @@ function decodeTrackProperties(reader, payloadEnd) {
1460
1411
  unknown.push({
1461
1412
  id: `0x${propType.toString(16)}`,
1462
1413
  length,
1463
- raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, bytes)
1414
+ raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, bytes)
1464
1415
  });
1465
1416
  }
1466
1417
  }
@@ -1694,7 +1645,7 @@ function decodeFetchPayload(r) {
1694
1645
  const fetch_type = r.readVarInt();
1695
1646
  const ft = Number(fetch_type);
1696
1647
  if (ft < 1 || ft > 3) {
1697
- throw new (0, _chunk4XLYCT5Qcjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${ft}`, r.offset);
1648
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${ft}`, r.offset);
1698
1649
  }
1699
1650
  let standalone;
1700
1651
  let joining;
@@ -1791,13 +1742,13 @@ function encodeMessage(message) {
1791
1742
  if (typeId === void 0) {
1792
1743
  throw new Error(`Unknown message type: ${message.type}`);
1793
1744
  }
1794
- const payloadWriter = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)();
1745
+ const payloadWriter = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)();
1795
1746
  encodePayload(message, payloadWriter);
1796
1747
  const payload = payloadWriter.finishView();
1797
1748
  if (payload.byteLength > 65535) {
1798
1749
  throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
1799
1750
  }
1800
- const writer = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(payload.byteLength + 16);
1751
+ const writer = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(payload.byteLength + 16);
1801
1752
  writer.writeVarInt(typeId);
1802
1753
  writer.writeUint8(payload.byteLength >> 8 & 255);
1803
1754
  writer.writeUint8(payload.byteLength & 255);
@@ -1850,13 +1801,13 @@ function encodePayload(msg, w) {
1850
1801
  }
1851
1802
  function decodeMessage(bytes) {
1852
1803
  try {
1853
- const reader = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes);
1804
+ const reader = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes);
1854
1805
  const typeId = reader.readVarInt();
1855
1806
  const lenHi = reader.readUint8();
1856
1807
  const lenLo = reader.readUint8();
1857
1808
  const payloadLength = lenHi << 8 | lenLo;
1858
1809
  const payloadBytes = reader.readBytes(payloadLength);
1859
- const payloadReader = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(payloadBytes);
1810
+ const payloadReader = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(payloadBytes);
1860
1811
  let message;
1861
1812
  if (typeId === MSG_SETUP) {
1862
1813
  message = decodeSetupPayload(payloadReader, payloadLength);
@@ -1897,7 +1848,7 @@ function decodeMessage(bytes) {
1897
1848
  } else {
1898
1849
  return {
1899
1850
  ok: false,
1900
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
1851
+ error: new (0, _chunk5IMHJIAZcjs.DecodeError)(
1901
1852
  "UNKNOWN_MESSAGE_TYPE",
1902
1853
  `Unknown message type ID: 0x${typeId.toString(16)}`,
1903
1854
  0
@@ -1906,7 +1857,7 @@ function decodeMessage(bytes) {
1906
1857
  }
1907
1858
  return { ok: true, value: message, bytesRead: reader.offset };
1908
1859
  } catch (e) {
1909
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) {
1860
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError) {
1910
1861
  return { ok: false, error: e };
1911
1862
  }
1912
1863
  throw e;
@@ -1941,7 +1892,7 @@ function createStreamDecoder() {
1941
1892
  flush(controller) {
1942
1893
  if (offset < buffer.length) {
1943
1894
  controller.error(
1944
- new (0, _chunk4XLYCT5Qcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete message data", 0)
1895
+ new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete message data", 0)
1945
1896
  );
1946
1897
  }
1947
1898
  }
@@ -1965,6 +1916,24 @@ function createDraft18Codec() {
1965
1916
  createDataStreamDecoder
1966
1917
  };
1967
1918
  }
1919
+ function noteAuthTokenValue(valueStart, valueLength, value) {
1920
+ if (value === void 0 || value.byteLength === 0) return;
1921
+ _chunk5IMHJIAZcjs.recordAuthValueSpan.call(void 0, valueStart + valueLength - value.byteLength, value.byteLength);
1922
+ }
1923
+ function redactAuthTokens(bytes) {
1924
+ let payloadStart;
1925
+ try {
1926
+ const probe = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes);
1927
+ probe.readVarInt();
1928
+ probe.readUint8();
1929
+ probe.readUint8();
1930
+ payloadStart = probe.offset;
1931
+ } catch (e4) {
1932
+ return { bytes, redacted: 0, incomplete: false, decoded: false };
1933
+ }
1934
+ return _chunk5IMHJIAZcjs.redactWith.call(void 0, bytes, payloadStart, () => decodeMessage(bytes).ok);
1935
+ }
1936
+
1968
1937
 
1969
1938
 
1970
1939
 
@@ -2007,4 +1976,4 @@ function createDraft18Codec() {
2007
1976
 
2008
1977
 
2009
1978
 
2010
- exports.MSG_REQUEST_UPDATE = MSG_REQUEST_UPDATE; exports.MSG_SUBSCRIBE = MSG_SUBSCRIBE; exports.MSG_SUBSCRIBE_OK = MSG_SUBSCRIBE_OK; exports.MSG_REQUEST_ERROR = MSG_REQUEST_ERROR; exports.MSG_PUBLISH_NAMESPACE = MSG_PUBLISH_NAMESPACE; exports.MSG_REQUEST_OK = MSG_REQUEST_OK; exports.MSG_NAMESPACE = MSG_NAMESPACE; exports.MSG_PUBLISH_DONE = MSG_PUBLISH_DONE; exports.MSG_TRACK_STATUS = MSG_TRACK_STATUS; exports.MSG_NAMESPACE_DONE = MSG_NAMESPACE_DONE; exports.MSG_PUBLISH_BLOCKED = MSG_PUBLISH_BLOCKED; exports.MSG_GOAWAY = MSG_GOAWAY; exports.MSG_FETCH = MSG_FETCH; exports.MSG_FETCH_OK = MSG_FETCH_OK; exports.MSG_PUBLISH = MSG_PUBLISH; exports.MSG_PUBLISH_OK = MSG_PUBLISH_OK; exports.MSG_SUBSCRIBE_NAMESPACE = MSG_SUBSCRIBE_NAMESPACE; exports.MSG_SUBSCRIBE_TRACKS = MSG_SUBSCRIBE_TRACKS; exports.MSG_SETUP = MSG_SETUP; exports.SETUP_OPT_PATH = SETUP_OPT_PATH; exports.SETUP_OPT_AUTHORIZATION_TOKEN = SETUP_OPT_AUTHORIZATION_TOKEN; exports.SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE = SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE; exports.SETUP_OPT_AUTHORITY = SETUP_OPT_AUTHORITY; exports.SETUP_OPT_MOQT_IMPLEMENTATION = SETUP_OPT_MOQT_IMPLEMENTATION; exports.MESSAGE_TYPE_MAP = MESSAGE_TYPE_MAP; exports.MESSAGE_ID_MAP = MESSAGE_ID_MAP; exports.encodeSubgroupStream = encodeSubgroupStream; exports.encodeDatagram = encodeDatagram; exports.encodeFetchStream = encodeFetchStream; exports.decodeSubgroupStream = decodeSubgroupStream; exports.decodeDatagram = decodeDatagram; exports.decodeFetchStream = decodeFetchStream; exports.decodeDataStream = decodeDataStream; exports.createSubgroupStreamDecoder = createSubgroupStreamDecoder; exports.createFetchStreamDecoder = createFetchStreamDecoder; exports.createDataStreamDecoder = createDataStreamDecoder; exports.encodeMessage = encodeMessage; exports.decodeMessage = decodeMessage; exports.createStreamDecoder = createStreamDecoder; exports.createDraft18Codec = createDraft18Codec;
1979
+ exports.MSG_REQUEST_UPDATE = MSG_REQUEST_UPDATE; exports.MSG_SUBSCRIBE = MSG_SUBSCRIBE; exports.MSG_SUBSCRIBE_OK = MSG_SUBSCRIBE_OK; exports.MSG_REQUEST_ERROR = MSG_REQUEST_ERROR; exports.MSG_PUBLISH_NAMESPACE = MSG_PUBLISH_NAMESPACE; exports.MSG_REQUEST_OK = MSG_REQUEST_OK; exports.MSG_NAMESPACE = MSG_NAMESPACE; exports.MSG_PUBLISH_DONE = MSG_PUBLISH_DONE; exports.MSG_TRACK_STATUS = MSG_TRACK_STATUS; exports.MSG_NAMESPACE_DONE = MSG_NAMESPACE_DONE; exports.MSG_PUBLISH_BLOCKED = MSG_PUBLISH_BLOCKED; exports.MSG_GOAWAY = MSG_GOAWAY; exports.MSG_FETCH = MSG_FETCH; exports.MSG_FETCH_OK = MSG_FETCH_OK; exports.MSG_PUBLISH = MSG_PUBLISH; exports.MSG_PUBLISH_OK = MSG_PUBLISH_OK; exports.MSG_SUBSCRIBE_NAMESPACE = MSG_SUBSCRIBE_NAMESPACE; exports.MSG_SUBSCRIBE_TRACKS = MSG_SUBSCRIBE_TRACKS; exports.MSG_SETUP = MSG_SETUP; exports.SETUP_OPT_PATH = SETUP_OPT_PATH; exports.SETUP_OPT_AUTHORIZATION_TOKEN = SETUP_OPT_AUTHORIZATION_TOKEN; exports.SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE = SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE; exports.SETUP_OPT_AUTHORITY = SETUP_OPT_AUTHORITY; exports.SETUP_OPT_MOQT_IMPLEMENTATION = SETUP_OPT_MOQT_IMPLEMENTATION; exports.MESSAGE_TYPE_MAP = MESSAGE_TYPE_MAP; exports.MESSAGE_ID_MAP = MESSAGE_ID_MAP; exports.encodeSubgroupStream = encodeSubgroupStream; exports.encodeDatagram = encodeDatagram; exports.encodeFetchStream = encodeFetchStream; exports.decodeSubgroupStream = decodeSubgroupStream; exports.decodeDatagram = decodeDatagram; exports.decodeFetchStream = decodeFetchStream; exports.decodeDataStream = decodeDataStream; exports.createSubgroupStreamDecoder = createSubgroupStreamDecoder; exports.createFetchStreamDecoder = createFetchStreamDecoder; exports.createDataStreamDecoder = createDataStreamDecoder; exports.encodeMessage = encodeMessage; exports.decodeMessage = decodeMessage; exports.createStreamDecoder = createStreamDecoder; exports.createDraft18Codec = createDraft18Codec; exports.redactAuthTokens = redactAuthTokens;