@moqtap/codec 0.10.0 → 0.12.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 (262) hide show
  1. package/CHANGELOG.md +175 -0
  2. package/README.md +3 -2
  3. package/dist/auth-redaction-B9JJOlIY.d.cts +100 -0
  4. package/dist/auth-redaction-B9JJOlIY.d.ts +100 -0
  5. package/dist/{chunk-RYKQXBG6.cjs → chunk-27K5BUAG.cjs} +481 -517
  6. package/dist/{chunk-WCPENYNE.js → chunk-3RNQMGKA.js} +359 -390
  7. package/dist/{chunk-TSUZ6GJV.js → chunk-5AWIXOLB.js} +438 -469
  8. package/dist/{chunk-4XLYCT5Q.cjs → chunk-5IMHJIAZ.cjs} +52 -2
  9. package/dist/{chunk-KTNERCTZ.cjs → chunk-5JGZCKJO.cjs} +488 -518
  10. package/dist/{chunk-WCTMPDUX.cjs → chunk-73K4OSAN.cjs} +401 -432
  11. package/dist/{chunk-N2V7Z37J.js → chunk-7VQKRGRD.js} +19 -3
  12. package/dist/{chunk-BIBMDTU5.cjs → chunk-A3UCQOIB.cjs} +486 -517
  13. package/dist/{chunk-K2B3OVFK.js → chunk-A7PDMVXM.js} +24 -3
  14. package/dist/{chunk-VZHL2U2N.cjs → chunk-A7VQO6YC.cjs} +54 -38
  15. package/dist/{chunk-AQ445VV7.cjs → chunk-ACQHZLRZ.cjs} +66 -46
  16. package/dist/{chunk-L5DRACXS.js → chunk-BBICOMW6.js} +25 -3
  17. package/dist/{chunk-T4VWPKDG.cjs → chunk-BNIUVOCJ.cjs} +529 -599
  18. package/dist/{chunk-UKKDOOUO.cjs → chunk-CNC6ANS4.cjs} +58 -37
  19. package/dist/{chunk-OZRK73NQ.js → chunk-FDLQSWHK.js} +433 -469
  20. package/dist/{chunk-IJAF6PAY.js → chunk-FFNOE4UR.js} +19 -3
  21. package/dist/{chunk-CZNW3R5E.cjs → chunk-GMENT63T.cjs} +54 -38
  22. package/dist/{chunk-XCRCAUGI.cjs → chunk-HM7BLRVP.cjs} +291 -297
  23. package/dist/{chunk-XHAP2YST.js → chunk-HZONHFNO.js} +19 -3
  24. package/dist/{chunk-SDJTSMOW.cjs → chunk-ILYABWDK.cjs} +60 -38
  25. package/dist/{chunk-IDV2JYJ6.cjs → chunk-KRSFTZVO.cjs} +56 -40
  26. package/dist/{chunk-RIIA4ALQ.cjs → chunk-KSPH6KMH.cjs} +54 -38
  27. package/dist/{chunk-OUNN4IQB.cjs → chunk-KTY4LAUV.cjs} +482 -497
  28. package/dist/chunk-OBATJBNL.cjs +868 -0
  29. package/dist/{chunk-RZTLQAKF.js → chunk-OJNLJT5D.js} +0 -1
  30. package/dist/{chunk-FT3HDNIB.js → chunk-PJK2ZS3I.js} +467 -537
  31. package/dist/{chunk-G53WYUXL.js → chunk-PSMZKHOC.js} +441 -456
  32. package/dist/{chunk-7RE6KSIY.cjs → chunk-Q5JQGHWY.cjs} +0 -1
  33. package/dist/{chunk-BX2N7TZM.js → chunk-SQTUQY5E.js} +31 -11
  34. package/dist/chunk-T2TCLZZV.js +2304 -0
  35. package/dist/chunk-WB65UG7G.cjs +2304 -0
  36. package/dist/{chunk-CF5DDD3Q.js → chunk-WCRLAKDW.js} +239 -245
  37. package/dist/{chunk-KYVTM5VI.js → chunk-WL2YUEXH.js} +19 -3
  38. package/dist/chunk-XPCBPACE.js +868 -0
  39. package/dist/{chunk-KGDVC4O6.js → chunk-YCNIVZS7.js} +439 -469
  40. package/dist/{chunk-KLPWJU6W.js → chunk-YRZQVNZO.js} +50 -0
  41. package/dist/{codec-DOmAmFkI.d.ts → codec-B-oUU-cp.d.ts} +21 -2
  42. package/dist/{codec-DNmiG2e0.d.cts → codec-B3RpCI9k.d.cts} +21 -2
  43. package/dist/codec-B5pcOS3m.d.cts +38 -0
  44. package/dist/{codec-BNy5syCU.d.ts → codec-BLjxwK2f.d.ts} +21 -2
  45. package/dist/{codec-alVA27Uc.d.ts → codec-BV3CL_3m.d.ts} +21 -2
  46. package/dist/{codec-Czejcmxr.d.cts → codec-BYCDWgED.d.ts} +22 -3
  47. package/dist/{codec-DaXjRrOV.d.ts → codec-Bwqq7ZQT.d.ts} +22 -3
  48. package/dist/{codec-CFWu5KVT.d.cts → codec-BzWxOFby.d.cts} +22 -3
  49. package/dist/codec-C-nJhNNl.d.ts +38 -0
  50. package/dist/{codec-EvybrBuY.d.cts → codec-C11VEPbQ.d.cts} +21 -2
  51. package/dist/codec-C9U0Vzy9.d.cts +68 -0
  52. package/dist/{codec-Cm3D261p.d.ts → codec-CCx22jnd.d.ts} +21 -2
  53. package/dist/{codec-CwZ6OCPP.d.ts → codec-CP3zkfTv.d.ts} +22 -3
  54. package/dist/{codec-BxQTybUX.d.cts → codec-CRmOLDpt.d.ts} +22 -3
  55. package/dist/{codec-DzkdW4kO.d.cts → codec-CUu56DDU.d.cts} +21 -2
  56. package/dist/codec-Cb8mUre3.d.ts +68 -0
  57. package/dist/{codec-f7vxeVIS.d.cts → codec-CemqAQdR.d.cts} +22 -3
  58. package/dist/{codec-gl4_QEva.d.ts → codec-CxMvsVMS.d.ts} +21 -2
  59. package/dist/{codec-Bd60SGKH.d.cts → codec-DIgMVTi4.d.cts} +21 -2
  60. package/dist/{codec--CVeqGQv.d.ts → codec-DYzozF68.d.ts} +21 -2
  61. package/dist/{codec-CWnf8mn_.d.cts → codec-D_O9zxax.d.ts} +22 -3
  62. package/dist/{codec-08ZOr5wI.d.ts → codec-Ddc-QxV6.d.cts} +22 -3
  63. package/dist/{codec-CBdOIfMY.d.ts → codec-DoojMl2z.d.cts} +22 -3
  64. package/dist/{codec-BrTi4K7r.d.cts → codec-DqdjiOQF.d.ts} +22 -3
  65. package/dist/{codec-CXCjya_G.d.cts → codec-Dstemwrq.d.cts} +21 -2
  66. package/dist/{codec-Dl_QIXMz.d.ts → codec-Dt6nuejp.d.ts} +21 -2
  67. package/dist/{codec-Bux_Q40X.d.ts → codec-DuYhd8fP.d.cts} +22 -3
  68. package/dist/{codec-Cfo_z5ET.d.cts → codec-DwNOFgPU.d.cts} +21 -2
  69. package/dist/{codec-guzqtfMk.d.cts → codec-l01BpNhF.d.cts} +21 -2
  70. package/dist/{codec-C3mdsGx3.d.ts → codec-psN2vB6I.d.cts} +22 -3
  71. package/dist/draft07-session.d.cts +3 -3
  72. package/dist/draft07-session.d.ts +3 -3
  73. package/dist/draft07.cjs +48 -4
  74. package/dist/draft07.d.cts +44 -4
  75. package/dist/draft07.d.ts +44 -4
  76. package/dist/draft07.js +49 -5
  77. package/dist/draft08-session.d.cts +3 -3
  78. package/dist/draft08-session.d.ts +3 -3
  79. package/dist/draft08.cjs +76 -3
  80. package/dist/draft08.d.cts +73 -5
  81. package/dist/draft08.d.ts +73 -5
  82. package/dist/draft08.js +77 -4
  83. package/dist/draft09-session.d.cts +3 -3
  84. package/dist/draft09-session.d.ts +3 -3
  85. package/dist/draft09.cjs +76 -3
  86. package/dist/draft09.d.cts +73 -5
  87. package/dist/draft09.d.ts +73 -5
  88. package/dist/draft09.js +77 -4
  89. package/dist/draft10-session.d.cts +3 -3
  90. package/dist/draft10-session.d.ts +3 -3
  91. package/dist/draft10.cjs +76 -3
  92. package/dist/draft10.d.cts +73 -5
  93. package/dist/draft10.d.ts +73 -5
  94. package/dist/draft10.js +77 -4
  95. package/dist/draft11-session.d.cts +3 -3
  96. package/dist/draft11-session.d.ts +3 -3
  97. package/dist/draft11.cjs +104 -3
  98. package/dist/draft11.d.cts +101 -5
  99. package/dist/draft11.d.ts +101 -5
  100. package/dist/draft11.js +105 -4
  101. package/dist/draft12-session.d.cts +3 -3
  102. package/dist/draft12-session.d.ts +3 -3
  103. package/dist/draft12.cjs +113 -3
  104. package/dist/draft12.d.cts +110 -5
  105. package/dist/draft12.d.ts +110 -5
  106. package/dist/draft12.js +114 -4
  107. package/dist/draft13-session.d.cts +3 -3
  108. package/dist/draft13-session.d.ts +3 -3
  109. package/dist/draft13.cjs +105 -3
  110. package/dist/draft13.d.cts +102 -5
  111. package/dist/draft13.d.ts +102 -5
  112. package/dist/draft13.js +106 -4
  113. package/dist/draft14-session.d.cts +3 -3
  114. package/dist/draft14-session.d.ts +3 -3
  115. package/dist/draft14.cjs +107 -3
  116. package/dist/draft14.d.cts +104 -31
  117. package/dist/draft14.d.ts +104 -31
  118. package/dist/draft14.js +108 -4
  119. package/dist/draft15-session.d.cts +4 -4
  120. package/dist/draft15-session.d.ts +4 -4
  121. package/dist/draft15.cjs +69 -3
  122. package/dist/draft15.d.cts +68 -25
  123. package/dist/draft15.d.ts +68 -25
  124. package/dist/draft15.js +70 -4
  125. package/dist/draft16-session.cjs +2 -2
  126. package/dist/draft16-session.d.cts +4 -4
  127. package/dist/draft16-session.d.ts +4 -4
  128. package/dist/draft16-session.js +1 -1
  129. package/dist/draft16.cjs +76 -8
  130. package/dist/draft16.d.cts +70 -16
  131. package/dist/draft16.d.ts +70 -16
  132. package/dist/draft16.js +73 -5
  133. package/dist/draft17-session.d.cts +4 -4
  134. package/dist/draft17-session.d.ts +4 -4
  135. package/dist/draft17.cjs +77 -3
  136. package/dist/draft17.d.cts +75 -6
  137. package/dist/draft17.d.ts +75 -6
  138. package/dist/draft17.js +78 -4
  139. package/dist/draft18-session.d.cts +4 -4
  140. package/dist/draft18-session.d.ts +4 -4
  141. package/dist/draft18.cjs +8 -3
  142. package/dist/draft18.d.cts +6 -5
  143. package/dist/draft18.d.ts +6 -5
  144. package/dist/draft18.js +9 -4
  145. package/dist/draft19-session.d.cts +4 -4
  146. package/dist/draft19-session.d.ts +4 -4
  147. package/dist/draft19.cjs +11 -4
  148. package/dist/draft19.d.cts +6 -5
  149. package/dist/draft19.d.ts +6 -5
  150. package/dist/draft19.js +12 -5
  151. package/dist/draft20-session.d.cts +4 -4
  152. package/dist/draft20-session.d.ts +4 -4
  153. package/dist/draft20.cjs +8 -3
  154. package/dist/draft20.d.cts +6 -5
  155. package/dist/draft20.d.ts +6 -5
  156. package/dist/draft20.js +9 -4
  157. package/dist/draft21-session.cjs +8 -0
  158. package/dist/draft21-session.d.cts +195 -0
  159. package/dist/draft21-session.d.ts +195 -0
  160. package/dist/draft21-session.js +8 -0
  161. package/dist/draft21.cjs +222 -0
  162. package/dist/draft21.d.cts +176 -0
  163. package/dist/draft21.d.ts +176 -0
  164. package/dist/draft21.js +222 -0
  165. package/dist/index.cjs +37 -31
  166. package/dist/index.d.cts +29 -23
  167. package/dist/index.d.ts +29 -23
  168. package/dist/index.js +22 -16
  169. package/dist/{session-types-Dn7b3RZM.d.ts → session-types-Cxx7W8zZ.d.ts} +1 -1
  170. package/dist/{session-types-B9idsih-.d.cts → session-types-DZkI_qFG.d.cts} +1 -1
  171. package/dist/session.cjs +7 -3
  172. package/dist/session.d.cts +11 -9
  173. package/dist/session.d.ts +11 -9
  174. package/dist/session.js +6 -2
  175. package/dist/{types-DG5_iKuv.d.cts → types-2NisMA8_.d.cts} +1 -1
  176. package/dist/{types-DG5_iKuv.d.ts → types-2NisMA8_.d.ts} +1 -1
  177. package/dist/{types-C1rxh-id.d.cts → types-Btp416jt.d.cts} +8 -0
  178. package/dist/{types-C1rxh-id.d.ts → types-Btp416jt.d.ts} +8 -0
  179. package/dist/{types-CZTzbIzQ.d.cts → types-BxTL1NXw.d.cts} +7 -0
  180. package/dist/{types-CZTzbIzQ.d.ts → types-BxTL1NXw.d.ts} +7 -0
  181. package/dist/{types-pShrs3fN.d.cts → types-CuibHYcf.d.cts} +7 -0
  182. package/dist/{types-pShrs3fN.d.ts → types-CuibHYcf.d.ts} +7 -0
  183. package/dist/{types-CY-QWxd-.d.cts → types-CwN7AEoL.d.cts} +13 -1
  184. package/dist/{types-CY-QWxd-.d.ts → types-CwN7AEoL.d.ts} +13 -1
  185. package/dist/{types-D4bmW8rY.d.cts → types-DAnalt5K.d.cts} +7 -0
  186. package/dist/{types-D4bmW8rY.d.ts → types-DAnalt5K.d.ts} +7 -0
  187. package/dist/types-DDwidj2d.d.cts +371 -0
  188. package/dist/types-DDwidj2d.d.ts +371 -0
  189. package/dist/{types-Bg86GGVZ.d.cts → types-DxXNP32l.d.cts} +8 -0
  190. package/dist/{types-Bg86GGVZ.d.ts → types-DxXNP32l.d.ts} +8 -0
  191. package/package.json +15 -3
  192. package/src/core/auth-redaction.ts +190 -0
  193. package/src/core/types.ts +1 -0
  194. package/src/drafts/draft07/codec.ts +40 -0
  195. package/src/drafts/draft07/error-codes.ts +44 -0
  196. package/src/drafts/draft07/index.ts +15 -0
  197. package/src/drafts/draft08/codec.ts +40 -0
  198. package/src/drafts/draft08/error-codes.ts +76 -0
  199. package/src/drafts/draft08/index.ts +21 -0
  200. package/src/drafts/draft09/codec.ts +40 -0
  201. package/src/drafts/draft09/error-codes.ts +76 -0
  202. package/src/drafts/draft09/index.ts +21 -0
  203. package/src/drafts/draft10/codec.ts +40 -0
  204. package/src/drafts/draft10/error-codes.ts +76 -0
  205. package/src/drafts/draft10/index.ts +21 -0
  206. package/src/drafts/draft11/codec.ts +60 -0
  207. package/src/drafts/draft11/error-codes.ts +106 -0
  208. package/src/drafts/draft11/index.ts +23 -0
  209. package/src/drafts/draft12/codec.ts +61 -0
  210. package/src/drafts/draft12/error-codes.ts +116 -0
  211. package/src/drafts/draft12/index.ts +25 -0
  212. package/src/drafts/draft13/codec.ts +69 -11
  213. package/src/drafts/draft13/error-codes.ts +107 -0
  214. package/src/drafts/draft13/index.ts +23 -0
  215. package/src/drafts/draft13/types.ts +1 -1
  216. package/src/drafts/draft14/codec.ts +65 -4
  217. package/src/drafts/draft14/data-streams.ts +331 -259
  218. package/src/drafts/draft14/error-codes.ts +109 -0
  219. package/src/drafts/draft14/index.ts +23 -0
  220. package/src/drafts/draft15/codec.ts +65 -8
  221. package/src/drafts/draft15/data-streams.ts +489 -444
  222. package/src/drafts/draft15/error-codes.ts +66 -0
  223. package/src/drafts/draft15/index.ts +15 -0
  224. package/src/drafts/draft15/types.ts +7 -0
  225. package/src/drafts/draft16/codec.ts +146 -52
  226. package/src/drafts/draft16/data-streams.ts +513 -442
  227. package/src/drafts/draft16/error-codes.ts +68 -0
  228. package/src/drafts/draft16/index.ts +15 -0
  229. package/src/drafts/draft16/messages.ts +4 -4
  230. package/src/drafts/draft16/session-fsm.ts +0 -1
  231. package/src/drafts/draft16/types.ts +22 -8
  232. package/src/drafts/draft17/codec.ts +73 -12
  233. package/src/drafts/draft17/data-streams.ts +567 -488
  234. package/src/drafts/draft17/index.ts +15 -0
  235. package/src/drafts/draft17/types.ts +7 -0
  236. package/src/drafts/draft18/codec.ts +66 -9
  237. package/src/drafts/draft18/data-streams.ts +570 -482
  238. package/src/drafts/draft18/index.ts +3 -0
  239. package/src/drafts/draft18/types.ts +16 -8
  240. package/src/drafts/draft19/codec.ts +70 -10
  241. package/src/drafts/draft19/data-streams.ts +570 -482
  242. package/src/drafts/draft19/error-codes.ts +3 -1
  243. package/src/drafts/draft19/index.ts +3 -0
  244. package/src/drafts/draft19/messages.ts +3 -1
  245. package/src/drafts/draft19/types.ts +22 -11
  246. package/src/drafts/draft20/codec.ts +90 -23
  247. package/src/drafts/draft20/data-streams.ts +610 -563
  248. package/src/drafts/draft20/index.ts +3 -0
  249. package/src/drafts/draft20/types.ts +14 -2
  250. package/src/drafts/draft21/codec.ts +1816 -0
  251. package/src/drafts/draft21/data-streams.ts +1338 -0
  252. package/src/drafts/draft21/error-codes.ts +135 -0
  253. package/src/drafts/draft21/index.ts +168 -0
  254. package/src/drafts/draft21/messages.ts +68 -0
  255. package/src/drafts/draft21/rules.ts +107 -0
  256. package/src/drafts/draft21/session-fsm.ts +1063 -0
  257. package/src/drafts/draft21/session.ts +21 -0
  258. package/src/drafts/draft21/types.ts +473 -0
  259. package/src/index.ts +9 -1
  260. package/src/session.ts +4 -0
  261. package/dist/codec-BJ7BHuiZ.d.ts +0 -18
  262. 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/draft19/messages.ts
10
12
  var MSG_REQUEST_UPDATE = 0x02n;
@@ -110,7 +112,7 @@ function isValidSubgroupType(streamType) {
110
112
  return (streamType & 6) !== 6;
111
113
  }
112
114
  function encodeSubgroupStream(stream) {
113
- const w = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)();
115
+ const w = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)();
114
116
  const streamType = stream.headerType;
115
117
  w.writeUint8(streamType);
116
118
  const propertiesPresent = (streamType & 1) !== 0;
@@ -131,7 +133,7 @@ function encodeSubgroupStream(stream) {
131
133
  w.writeVarInt(delta);
132
134
  if (propertiesPresent) {
133
135
  if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
134
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
136
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
135
137
  encodeObjectProperties(obj.objectProperties, tmpW);
136
138
  const raw = tmpW.finish();
137
139
  w.writeVarInt(BigInt(raw.byteLength));
@@ -151,7 +153,7 @@ function encodeSubgroupStream(stream) {
151
153
  return w.finish();
152
154
  }
153
155
  function encodeDatagram(dg) {
154
- const w = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)();
156
+ const w = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)();
155
157
  const dgType = dg.datagramType;
156
158
  w.writeUint8(dgType);
157
159
  w.writeVarInt(dg.trackAlias);
@@ -168,7 +170,7 @@ function encodeDatagram(dg) {
168
170
  }
169
171
  if (propertiesPresent) {
170
172
  if (dg.objectProperties && Object.keys(dg.objectProperties).length > 0) {
171
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
173
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
172
174
  encodeObjectProperties(dg.objectProperties, tmpW);
173
175
  const raw = tmpW.finish();
174
176
  w.writeVarInt(BigInt(raw.byteLength));
@@ -185,7 +187,7 @@ function encodeDatagram(dg) {
185
187
  return w.finish();
186
188
  }
187
189
  function encodeFetchStream(stream) {
188
- const w = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)();
190
+ const w = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)();
189
191
  w.writeVarInt(FETCH_STREAM_TYPE);
190
192
  w.writeVarInt(stream.requestId);
191
193
  let prevGroupId = 0n;
@@ -207,7 +209,7 @@ function encodeFetchStream(stream) {
207
209
  if (flags & 16) w.writeUint8(obj.publisherPriority);
208
210
  if (flags & 32) {
209
211
  if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
210
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
212
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
211
213
  encodeObjectProperties(obj.objectProperties, tmpW);
212
214
  const raw = tmpW.finish();
213
215
  w.writeVarInt(BigInt(raw.byteLength));
@@ -231,7 +233,7 @@ function encodeFetchStream(stream) {
231
233
  if (flags & 16) w.writeUint8(obj.publisherPriority);
232
234
  if (flags & 32) {
233
235
  if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
234
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
236
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
235
237
  encodeObjectProperties(obj.objectProperties, tmpW);
236
238
  const raw = tmpW.finish();
237
239
  w.writeVarInt(BigInt(raw.byteLength));
@@ -252,112 +254,121 @@ function encodeFetchStream(stream) {
252
254
  void prevObjectId;
253
255
  return w.finish();
254
256
  }
257
+ function readSubgroupHeader(r) {
258
+ const streamType = r.readUint8();
259
+ if (!isValidSubgroupType(streamType)) {
260
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
261
+ "CONSTRAINT_VIOLATION",
262
+ `Invalid subgroup stream type 0x${streamType.toString(16)}`,
263
+ 0
264
+ );
265
+ }
266
+ const propertiesPresent = (streamType & 1) !== 0;
267
+ const subgroupMode = (streamType & 6) >> 1;
268
+ const hasSubgroupField = subgroupMode === 2;
269
+ const subgroupIsFirstObjId = subgroupMode === 1;
270
+ const endOfGroup = (streamType & 8) !== 0;
271
+ const hasPriority = (streamType & 32) === 0;
272
+ const firstObjectFlag = (streamType & 64) !== 0;
273
+ const trackAlias = r.readVarInt();
274
+ const groupId = r.readVarInt();
275
+ let subgroupId = 0n;
276
+ if (hasSubgroupField) {
277
+ subgroupId = r.readVarInt();
278
+ }
279
+ let publisherPriority = 128;
280
+ if (hasPriority) {
281
+ publisherPriority = r.readUint8();
282
+ }
283
+ return {
284
+ streamType,
285
+ propertiesPresent,
286
+ subgroupIsFirstObjId,
287
+ endOfGroup,
288
+ firstObjectFlag,
289
+ trackAlias,
290
+ groupId,
291
+ subgroupId,
292
+ publisherPriority
293
+ };
294
+ }
295
+ function readSubgroupObject(r, propertiesPresent, isFirst, prevObjectId, base) {
296
+ const byteOffset = base + r.offset;
297
+ const delta = r.readVarInt();
298
+ const objectId = isFirst ? delta : prevObjectId + 1n + delta;
299
+ const extensionData = new Uint8Array(0);
300
+ let objectProperties;
301
+ if (propertiesPresent) {
302
+ const propsLen = Number(r.readVarInt());
303
+ if (propsLen > 0) {
304
+ objectProperties = decodeObjectProperties(r, propsLen);
305
+ }
306
+ }
307
+ const payloadLength = Number(r.readVarInt());
308
+ let payload;
309
+ let status;
310
+ let payloadByteOffset;
311
+ if (payloadLength === 0) {
312
+ status = r.readVarInt();
313
+ payloadByteOffset = base + r.offset;
314
+ payload = new Uint8Array(0);
315
+ } else {
316
+ payloadByteOffset = base + r.offset;
317
+ payload = r.readBytesView(payloadLength);
318
+ }
319
+ const obj = {
320
+ type: "object",
321
+ byteOffset,
322
+ payloadByteOffset,
323
+ objectId,
324
+ payloadLength,
325
+ payload,
326
+ extensionData
327
+ };
328
+ if (status !== void 0) obj.status = status;
329
+ if (objectProperties !== void 0)
330
+ obj.objectProperties = objectProperties;
331
+ return obj;
332
+ }
255
333
  function decodeSubgroupStream(bytes) {
256
334
  try {
257
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes);
258
- const streamType = r.readUint8();
259
- if (!isValidSubgroupType(streamType)) {
260
- return {
261
- ok: false,
262
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
263
- "CONSTRAINT_VIOLATION",
264
- `Invalid subgroup stream type 0x${streamType.toString(16)}`,
265
- 0
266
- )
267
- };
268
- }
269
- const propertiesPresent = (streamType & 1) !== 0;
270
- const subgroupMode = (streamType & 6) >> 1;
271
- const hasSubgroupField = subgroupMode === 2;
272
- const subgroupIsFirstObjId = subgroupMode === 1;
273
- const endOfGroup = (streamType & 8) !== 0;
274
- const hasPriority = (streamType & 32) === 0;
275
- const firstObject = (streamType & 64) !== 0;
276
- const trackAlias = r.readVarInt();
277
- const groupId = r.readVarInt();
278
- let subgroupId = 0n;
279
- if (hasSubgroupField) {
280
- subgroupId = r.readVarInt();
281
- }
282
- let publisherPriority = 128;
283
- if (hasPriority) {
284
- publisherPriority = r.readUint8();
285
- }
335
+ const r = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes);
336
+ const h = readSubgroupHeader(r);
286
337
  const objects = [];
287
338
  let prevObjectId = -1n;
288
339
  let isFirst = true;
340
+ let subgroupId = h.subgroupId;
289
341
  while (r.remaining > 0) {
290
- const byteOffset = r.offset;
291
- const delta = r.readVarInt();
292
- let objectId;
293
- if (isFirst) {
294
- objectId = delta;
295
- if (subgroupIsFirstObjId) {
296
- subgroupId = objectId;
297
- }
298
- isFirst = false;
299
- } else {
300
- objectId = prevObjectId + 1n + delta;
301
- }
302
- const extensionData = new Uint8Array(0);
303
- let objectProperties;
304
- if (propertiesPresent) {
305
- const propsLen = Number(r.readVarInt());
306
- if (propsLen > 0) {
307
- objectProperties = decodeObjectProperties(r, propsLen);
308
- }
309
- }
310
- const payloadLength = Number(r.readVarInt());
311
- let payload;
312
- let status;
313
- let payloadByteOffset;
314
- if (payloadLength === 0) {
315
- status = r.readVarInt();
316
- payloadByteOffset = r.offset;
317
- payload = new Uint8Array(0);
318
- } else {
319
- payloadByteOffset = r.offset;
320
- payload = r.readBytesView(payloadLength);
321
- }
322
- const obj = {
323
- type: "object",
324
- byteOffset,
325
- payloadByteOffset,
326
- objectId,
327
- payloadLength,
328
- payload,
329
- extensionData
330
- };
331
- if (status !== void 0) obj.status = status;
332
- if (objectProperties !== void 0)
333
- obj.objectProperties = objectProperties;
342
+ const obj = readSubgroupObject(r, h.propertiesPresent, isFirst, prevObjectId, 0);
343
+ if (isFirst && h.subgroupIsFirstObjId) subgroupId = obj.objectId;
344
+ isFirst = false;
334
345
  objects.push(obj);
335
- prevObjectId = objectId;
346
+ prevObjectId = obj.objectId;
336
347
  }
337
348
  const result = {
338
349
  type: "subgroup",
339
- headerType: streamType,
340
- trackAlias,
341
- groupId,
350
+ headerType: h.streamType,
351
+ trackAlias: h.trackAlias,
352
+ groupId: h.groupId,
342
353
  subgroupId,
343
- publisherPriority,
344
- objects
354
+ publisherPriority: h.publisherPriority,
355
+ objects,
356
+ ...h.endOfGroup ? { endOfGroup: true } : {},
357
+ ...h.firstObjectFlag ? { firstObject: true } : {}
345
358
  };
346
- if (endOfGroup) result.endOfGroup = true;
347
- if (firstObject) result.firstObject = true;
348
359
  return {
349
360
  ok: true,
350
361
  value: result,
351
362
  bytesRead: r.offset
352
363
  };
353
364
  } catch (e) {
354
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) return { ok: false, error: e };
365
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
355
366
  throw e;
356
367
  }
357
368
  }
358
369
  function decodeDatagram(bytes) {
359
370
  try {
360
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes);
371
+ const r = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes);
361
372
  const dgType = r.readUint8();
362
373
  const objectIdAbsent = (dgType & 4) !== 0;
363
374
  const endOfGroup = (dgType & 2) !== 0;
@@ -407,18 +418,190 @@ function decodeDatagram(bytes) {
407
418
  result.objectProperties = objectProperties;
408
419
  return { ok: true, value: result, bytesRead: r.offset };
409
420
  } catch (e) {
410
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) return { ok: false, error: e };
421
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
411
422
  throw e;
412
423
  }
413
424
  }
425
+ function newFetchObjectState() {
426
+ return { prevGroupId: 0n, prevSubgroupId: 0n, prevObjectId: 0n, prevPriority: 128, first: true };
427
+ }
428
+ function readFetchObject(r, base, st) {
429
+ const byteOffset = base + r.offset;
430
+ const flags = Number(r.readVarInt());
431
+ let groupId = st.prevGroupId;
432
+ let subgroupId = st.prevSubgroupId;
433
+ let objectId = st.prevObjectId + 1n;
434
+ let payloadLength;
435
+ let payload;
436
+ let payloadByteOffset;
437
+ const extensionData = new Uint8Array(0);
438
+ if (flags >= 128) {
439
+ if (flags !== 140 && flags !== 268) {
440
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
441
+ "CONSTRAINT_VIOLATION",
442
+ `Unknown serialization flags value: 0x${flags.toString(16)}`,
443
+ r.offset
444
+ );
445
+ }
446
+ groupId = r.readVarInt();
447
+ objectId = r.readVarInt();
448
+ payloadLength = Number(r.readVarInt());
449
+ payloadByteOffset = base + r.offset;
450
+ payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
451
+ } else if (flags & 64) {
452
+ const objectIdPresent = (flags & 4) !== 0;
453
+ const groupIdPresent = (flags & 8) !== 0;
454
+ const priorityPresent = (flags & 16) !== 0;
455
+ const propsPresent = (flags & 32) !== 0;
456
+ if (groupIdPresent) {
457
+ const groupDelta = r.readVarInt();
458
+ groupId = st.first ? groupDelta : st.prevGroupId + groupDelta + 1n;
459
+ }
460
+ if (objectIdPresent) {
461
+ objectId = r.readVarInt();
462
+ }
463
+ if (priorityPresent) {
464
+ st.prevPriority = r.readUint8();
465
+ }
466
+ let objectProperties;
467
+ if (propsPresent) {
468
+ const propsLen = Number(r.readVarInt());
469
+ if (propsLen > 0) {
470
+ objectProperties = decodeObjectProperties(r, propsLen);
471
+ }
472
+ }
473
+ payloadLength = Number(r.readVarInt());
474
+ payloadByteOffset = base + r.offset;
475
+ payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
476
+ const obj2 = {
477
+ type: "object",
478
+ byteOffset,
479
+ payloadByteOffset,
480
+ serializationFlags: flags,
481
+ groupId,
482
+ subgroupId: 0n,
483
+ objectId,
484
+ publisherPriority: st.prevPriority,
485
+ payloadLength,
486
+ payload,
487
+ extensionData
488
+ };
489
+ if (objectProperties)
490
+ obj2.objectProperties = objectProperties;
491
+ st.prevGroupId = groupId;
492
+ st.prevObjectId = objectId;
493
+ st.first = false;
494
+ return obj2;
495
+ } else {
496
+ const subgroupEncoding = flags & 3;
497
+ const objectIdPresent = (flags & 4) !== 0;
498
+ const groupIdPresent = (flags & 8) !== 0;
499
+ const priorityPresent = (flags & 16) !== 0;
500
+ const propsPresent = (flags & 32) !== 0;
501
+ if (groupIdPresent) {
502
+ const groupDelta = r.readVarInt();
503
+ groupId = st.first ? groupDelta : st.prevGroupId + groupDelta + 1n;
504
+ } else if (st.first) {
505
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
506
+ "CONSTRAINT_VIOLATION",
507
+ "First fetch object must include groupId",
508
+ r.offset
509
+ );
510
+ }
511
+ if (subgroupEncoding === 0) {
512
+ subgroupId = 0n;
513
+ } else if (subgroupEncoding === 1) {
514
+ if (st.first) {
515
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
516
+ "CONSTRAINT_VIOLATION",
517
+ "First fetch object cannot reference prior subgroupId",
518
+ r.offset
519
+ );
520
+ }
521
+ subgroupId = st.prevSubgroupId;
522
+ } else if (subgroupEncoding === 2) {
523
+ if (st.first) {
524
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
525
+ "CONSTRAINT_VIOLATION",
526
+ "First fetch object cannot reference prior subgroupId",
527
+ r.offset
528
+ );
529
+ }
530
+ subgroupId = st.prevSubgroupId + 1n;
531
+ } else if (subgroupEncoding === 3) {
532
+ subgroupId = r.readVarInt();
533
+ }
534
+ if (objectIdPresent) {
535
+ objectId = r.readVarInt();
536
+ } else if (st.first) {
537
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
538
+ "CONSTRAINT_VIOLATION",
539
+ "First fetch object must include objectId",
540
+ r.offset
541
+ );
542
+ }
543
+ if (priorityPresent) {
544
+ st.prevPriority = r.readUint8();
545
+ }
546
+ let objectProperties;
547
+ if (propsPresent) {
548
+ const propsLen = Number(r.readVarInt());
549
+ if (propsLen > 0) {
550
+ objectProperties = decodeObjectProperties(r, propsLen);
551
+ }
552
+ }
553
+ payloadLength = Number(r.readVarInt());
554
+ payloadByteOffset = base + r.offset;
555
+ payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
556
+ if (objectProperties) {
557
+ const obj2 = {
558
+ type: "object",
559
+ byteOffset,
560
+ payloadByteOffset,
561
+ serializationFlags: flags,
562
+ groupId,
563
+ subgroupId,
564
+ objectId,
565
+ publisherPriority: st.prevPriority,
566
+ payloadLength,
567
+ payload,
568
+ extensionData
569
+ };
570
+ obj2.objectProperties = objectProperties;
571
+ st.prevGroupId = groupId;
572
+ st.prevSubgroupId = subgroupId;
573
+ st.prevObjectId = objectId;
574
+ st.first = false;
575
+ return obj2;
576
+ }
577
+ }
578
+ const obj = {
579
+ type: "object",
580
+ byteOffset,
581
+ payloadByteOffset,
582
+ serializationFlags: flags,
583
+ groupId,
584
+ subgroupId,
585
+ objectId,
586
+ publisherPriority: st.prevPriority,
587
+ payloadLength,
588
+ payload,
589
+ extensionData
590
+ };
591
+ st.prevGroupId = groupId;
592
+ st.prevSubgroupId = subgroupId;
593
+ st.prevObjectId = objectId;
594
+ st.first = false;
595
+ return obj;
596
+ }
414
597
  function decodeFetchStream(bytes) {
415
598
  try {
416
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes);
599
+ const r = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes);
417
600
  const streamType = r.readVarInt();
418
601
  if (streamType !== FETCH_STREAM_TYPE) {
419
602
  return {
420
603
  ok: false,
421
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
604
+ error: new (0, _chunk5IMHJIAZcjs.DecodeError)(
422
605
  "CONSTRAINT_VIOLATION",
423
606
  `Expected fetch stream type 0x05, got 0x${streamType.toString(16)}`,
424
607
  0
@@ -427,196 +610,9 @@ function decodeFetchStream(bytes) {
427
610
  }
428
611
  const requestId = r.readVarInt();
429
612
  const objects = [];
430
- let prevGroupId = 0n;
431
- let prevSubgroupId = 0n;
432
- let prevObjectId = 0n;
433
- let prevPriority = 128;
434
- let first = true;
613
+ const st = newFetchObjectState();
435
614
  while (r.remaining > 0) {
436
- const byteOffset = r.offset;
437
- const flags = Number(r.readVarInt());
438
- let groupId = prevGroupId;
439
- let subgroupId = prevSubgroupId;
440
- let objectId = prevObjectId + 1n;
441
- let payloadLength;
442
- let payload;
443
- let payloadByteOffset;
444
- const extensionData = new Uint8Array(0);
445
- if (flags >= 128) {
446
- if (flags !== 140 && flags !== 268) {
447
- return {
448
- ok: false,
449
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
450
- "CONSTRAINT_VIOLATION",
451
- `Unknown serialization flags value: 0x${flags.toString(16)}`,
452
- r.offset
453
- )
454
- };
455
- }
456
- groupId = r.readVarInt();
457
- objectId = r.readVarInt();
458
- payloadLength = Number(r.readVarInt());
459
- payloadByteOffset = r.offset;
460
- payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
461
- } else if (flags & 64) {
462
- const objectIdPresent = (flags & 4) !== 0;
463
- const groupIdPresent = (flags & 8) !== 0;
464
- const priorityPresent = (flags & 16) !== 0;
465
- const propsPresent = (flags & 32) !== 0;
466
- if (groupIdPresent) {
467
- const groupDelta = r.readVarInt();
468
- groupId = first ? groupDelta : prevGroupId + groupDelta + 1n;
469
- }
470
- if (objectIdPresent) {
471
- objectId = r.readVarInt();
472
- }
473
- if (priorityPresent) {
474
- prevPriority = r.readUint8();
475
- }
476
- let objectProperties;
477
- if (propsPresent) {
478
- const propsLen = Number(r.readVarInt());
479
- if (propsLen > 0) {
480
- objectProperties = decodeObjectProperties(r, propsLen);
481
- }
482
- }
483
- payloadLength = Number(r.readVarInt());
484
- payloadByteOffset = r.offset;
485
- payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
486
- const obj2 = {
487
- type: "object",
488
- byteOffset,
489
- payloadByteOffset,
490
- serializationFlags: flags,
491
- groupId,
492
- subgroupId: 0n,
493
- objectId,
494
- publisherPriority: prevPriority,
495
- payloadLength,
496
- payload,
497
- extensionData
498
- };
499
- if (objectProperties)
500
- obj2.objectProperties = objectProperties;
501
- objects.push(obj2);
502
- prevGroupId = groupId;
503
- prevObjectId = objectId;
504
- first = false;
505
- continue;
506
- } else {
507
- const subgroupEncoding = flags & 3;
508
- const objectIdPresent = (flags & 4) !== 0;
509
- const groupIdPresent = (flags & 8) !== 0;
510
- const priorityPresent = (flags & 16) !== 0;
511
- const propsPresent = (flags & 32) !== 0;
512
- if (groupIdPresent) {
513
- const groupDelta = r.readVarInt();
514
- groupId = first ? groupDelta : prevGroupId + groupDelta + 1n;
515
- } else if (first) {
516
- return {
517
- ok: false,
518
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
519
- "CONSTRAINT_VIOLATION",
520
- "First fetch object must include groupId",
521
- r.offset
522
- )
523
- };
524
- }
525
- if (subgroupEncoding === 0) {
526
- subgroupId = 0n;
527
- } else if (subgroupEncoding === 1) {
528
- if (first) {
529
- return {
530
- ok: false,
531
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
532
- "CONSTRAINT_VIOLATION",
533
- "First fetch object cannot reference prior subgroupId",
534
- r.offset
535
- )
536
- };
537
- }
538
- subgroupId = prevSubgroupId;
539
- } else if (subgroupEncoding === 2) {
540
- if (first) {
541
- return {
542
- ok: false,
543
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
544
- "CONSTRAINT_VIOLATION",
545
- "First fetch object cannot reference prior subgroupId",
546
- r.offset
547
- )
548
- };
549
- }
550
- subgroupId = prevSubgroupId + 1n;
551
- } else if (subgroupEncoding === 3) {
552
- subgroupId = r.readVarInt();
553
- }
554
- if (objectIdPresent) {
555
- objectId = r.readVarInt();
556
- } else if (first) {
557
- return {
558
- ok: false,
559
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
560
- "CONSTRAINT_VIOLATION",
561
- "First fetch object must include objectId",
562
- r.offset
563
- )
564
- };
565
- }
566
- if (priorityPresent) {
567
- prevPriority = r.readUint8();
568
- }
569
- let objectProperties;
570
- if (propsPresent) {
571
- const propsLen = Number(r.readVarInt());
572
- if (propsLen > 0) {
573
- objectProperties = decodeObjectProperties(r, propsLen);
574
- }
575
- }
576
- payloadLength = Number(r.readVarInt());
577
- payloadByteOffset = r.offset;
578
- payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
579
- if (objectProperties) {
580
- const obj2 = {
581
- type: "object",
582
- byteOffset,
583
- payloadByteOffset,
584
- serializationFlags: flags,
585
- groupId,
586
- subgroupId,
587
- objectId,
588
- publisherPriority: prevPriority,
589
- payloadLength,
590
- payload,
591
- extensionData
592
- };
593
- obj2.objectProperties = objectProperties;
594
- objects.push(obj2);
595
- prevGroupId = groupId;
596
- prevSubgroupId = subgroupId;
597
- prevObjectId = objectId;
598
- first = false;
599
- continue;
600
- }
601
- }
602
- const obj = {
603
- type: "object",
604
- byteOffset,
605
- payloadByteOffset,
606
- serializationFlags: flags,
607
- groupId,
608
- subgroupId,
609
- objectId,
610
- publisherPriority: prevPriority,
611
- payloadLength,
612
- payload,
613
- extensionData
614
- };
615
- objects.push(obj);
616
- prevGroupId = groupId;
617
- prevSubgroupId = subgroupId;
618
- prevObjectId = objectId;
619
- first = false;
615
+ objects.push(readFetchObject(r, 0, st));
620
616
  }
621
617
  return {
622
618
  ok: true,
@@ -624,7 +620,7 @@ function decodeFetchStream(bytes) {
624
620
  bytesRead: r.offset
625
621
  };
626
622
  } catch (e) {
627
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) return { ok: false, error: e };
623
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
628
624
  throw e;
629
625
  }
630
626
  }
@@ -642,135 +638,125 @@ function decodeDataStream(streamType, bytes) {
642
638
  }
643
639
  }
644
640
  }
641
+ 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); }
642
+ __init() {this.buf = new Uint8Array(0)}
643
+ /** Bytes written into `buf`. */
644
+ __init2() {this.len = 0}
645
+ /** Consumed prefix of `buf`; `base + offset` is the position in the stream. */
646
+ __init3() {this.offset = 0}
647
+ /** Absolute position of `buf[0]` within the stream. */
648
+ __init4() {this.base = 0}
649
+ get unread() {
650
+ return this.len - this.offset;
651
+ }
652
+ append(chunk) {
653
+ if (this.len + chunk.length > this.buf.length) {
654
+ const live = this.len - this.offset;
655
+ const needed = live + chunk.length;
656
+ let cap = Math.max(4096, this.buf.length);
657
+ while (cap < needed * 2) cap *= 2;
658
+ const next = new Uint8Array(cap);
659
+ next.set(this.buf.subarray(this.offset, this.len), 0);
660
+ this.buf = next;
661
+ this.base += this.offset;
662
+ this.len = live;
663
+ this.offset = 0;
664
+ }
665
+ this.buf.set(chunk, this.len);
666
+ this.len += chunk.length;
667
+ }
668
+ /**
669
+ * The written bytes, for a reader positioned at `offset`. Bounded by `len`
670
+ * rather than by capacity, so `BufferReader.remaining` counts real bytes and
671
+ * not the spare room after them.
672
+ */
673
+ written() {
674
+ return this.buf.subarray(0, this.len);
675
+ }
676
+ }, _class);
645
677
  function createSubgroupStreamDecoder() {
646
- let buffer = new Uint8Array(0);
647
- let offset = 0;
678
+ const b = new StreamBuffer();
679
+ let header = null;
648
680
  let headerEmitted = false;
649
681
  let prevObjectId = -1n;
650
- let firstObject = true;
651
- let _propertiesPresent = false;
682
+ let isFirst = true;
683
+ function emitHeader(controller, h, subgroupId) {
684
+ controller.enqueue({
685
+ type: "subgroup_header",
686
+ headerType: h.streamType,
687
+ trackAlias: h.trackAlias,
688
+ groupId: h.groupId,
689
+ subgroupId,
690
+ publisherPriority: h.publisherPriority,
691
+ ...h.endOfGroup ? { endOfGroup: true } : {},
692
+ ...h.firstObjectFlag ? { firstObject: true } : {}
693
+ });
694
+ headerEmitted = true;
695
+ }
652
696
  return new TransformStream({
653
697
  transform(chunk, controller) {
654
- if (offset > 0) {
655
- buffer = buffer.subarray(offset);
656
- offset = 0;
657
- }
658
- const newBuffer = new Uint8Array(buffer.length + chunk.length);
659
- newBuffer.set(buffer, 0);
660
- newBuffer.set(chunk, buffer.length);
661
- buffer = newBuffer;
662
- if (!headerEmitted) {
698
+ b.append(chunk);
699
+ const view = b.written();
700
+ if (header === null) {
663
701
  try {
664
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(buffer.subarray(offset));
665
- const streamType = r.readUint8();
666
- if (!isValidSubgroupType(streamType)) {
667
- controller.error(
668
- new (0, _chunk4XLYCT5Qcjs.DecodeError)(
669
- "CONSTRAINT_VIOLATION",
670
- `Invalid subgroup stream type 0x${streamType.toString(16)}`,
671
- 0
672
- )
673
- );
674
- return;
675
- }
676
- _propertiesPresent = (streamType & 1) !== 0;
677
- const subgroupMode = (streamType & 6) >> 1;
678
- const hasSubgroupField = subgroupMode === 2;
679
- const hasPriority = (streamType & 32) === 0;
680
- const trackAlias = r.readVarInt();
681
- const groupId = r.readVarInt();
682
- let subgroupId = 0n;
683
- if (hasSubgroupField) {
684
- subgroupId = r.readVarInt();
685
- }
686
- let publisherPriority = 128;
687
- if (hasPriority) {
688
- publisherPriority = r.readUint8();
689
- }
690
- controller.enqueue({
691
- type: "subgroup_header",
692
- trackAlias,
693
- groupId,
694
- subgroupId,
695
- publisherPriority
696
- });
697
- headerEmitted = true;
698
- offset += r.offset;
702
+ const hr = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(view, b.offset);
703
+ header = readSubgroupHeader(hr);
704
+ b.offset = hr.offset;
699
705
  } catch (e) {
700
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError && e.code === "UNEXPECTED_END") {
706
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
701
707
  return;
702
708
  }
703
709
  controller.error(e);
704
710
  return;
705
711
  }
712
+ if (!header.subgroupIsFirstObjId) emitHeader(controller, header, header.subgroupId);
706
713
  }
707
- while (offset < buffer.length) {
714
+ const h = header;
715
+ if (h === null) return;
716
+ const r = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(view, b.offset);
717
+ while (r.remaining > 0) {
718
+ const start = r.offset;
719
+ let obj;
708
720
  try {
709
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(buffer.subarray(offset));
710
- const delta = r.readVarInt();
711
- let objectId;
712
- if (firstObject) {
713
- objectId = delta;
714
- firstObject = false;
715
- } else {
716
- objectId = prevObjectId + 1n + delta;
717
- }
718
- let extensionData = new Uint8Array(0);
719
- if (_propertiesPresent) {
720
- const extLen = Number(r.readVarInt());
721
- extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
722
- }
723
- const payloadLength = Number(r.readVarInt());
724
- const payloadByteOffset = r.offset;
725
- const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
726
- controller.enqueue({
727
- type: "object",
728
- objectId,
729
- payloadLength,
730
- payload,
731
- extensionData,
732
- byteOffset: 0,
733
- payloadByteOffset
734
- });
735
- offset += r.offset;
736
- prevObjectId = objectId;
721
+ obj = readSubgroupObject(r, h.propertiesPresent, isFirst, prevObjectId, b.base);
737
722
  } catch (e) {
738
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError && e.code === "UNEXPECTED_END") {
739
- break;
723
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
724
+ b.offset = start;
725
+ return;
740
726
  }
741
727
  controller.error(e);
742
728
  return;
743
729
  }
730
+ if (!headerEmitted) emitHeader(controller, h, obj.objectId);
731
+ isFirst = false;
732
+ b.offset = r.offset;
733
+ prevObjectId = obj.objectId;
734
+ controller.enqueue(obj);
744
735
  }
745
736
  },
746
737
  flush(controller) {
747
- if (offset < buffer.length) {
748
- controller.error(new (0, _chunk4XLYCT5Qcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
738
+ if (header !== null && !headerEmitted) emitHeader(controller, header, 0n);
739
+ if (b.unread > 0) {
740
+ controller.error(new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
749
741
  }
750
742
  }
751
743
  });
752
744
  }
753
745
  function createFetchStreamDecoder() {
754
- let buffer = new Uint8Array(0);
755
- let offset = 0;
746
+ const b = new StreamBuffer();
756
747
  let headerEmitted = false;
748
+ const st = newFetchObjectState();
757
749
  return new TransformStream({
758
750
  transform(chunk, controller) {
759
- if (offset > 0) {
760
- buffer = buffer.subarray(offset);
761
- offset = 0;
762
- }
763
- const newBuffer = new Uint8Array(buffer.length + chunk.length);
764
- newBuffer.set(buffer, 0);
765
- newBuffer.set(chunk, buffer.length);
766
- buffer = newBuffer;
751
+ b.append(chunk);
752
+ const view = b.written();
767
753
  if (!headerEmitted) {
768
754
  try {
769
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(buffer.subarray(offset));
770
- const streamType = r.readVarInt();
755
+ const r2 = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(view, b.offset);
756
+ const streamType = r2.readVarInt();
771
757
  if (streamType !== FETCH_STREAM_TYPE) {
772
758
  controller.error(
773
- new (0, _chunk4XLYCT5Qcjs.DecodeError)(
759
+ new (0, _chunk5IMHJIAZcjs.DecodeError)(
774
760
  "CONSTRAINT_VIOLATION",
775
761
  `Expected fetch stream type 0x05, got 0x${streamType.toString(16)}`,
776
762
  0
@@ -778,113 +764,96 @@ function createFetchStreamDecoder() {
778
764
  );
779
765
  return;
780
766
  }
781
- const requestId = r.readVarInt();
767
+ const requestId = r2.readVarInt();
782
768
  controller.enqueue({ type: "fetch_header", requestId });
783
769
  headerEmitted = true;
784
- offset += r.offset;
770
+ b.offset = r2.offset;
785
771
  } catch (e) {
786
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError && e.code === "UNEXPECTED_END") {
772
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
787
773
  return;
788
774
  }
789
775
  controller.error(e);
790
776
  return;
791
777
  }
792
778
  }
793
- while (offset < buffer.length) {
779
+ const r = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(view, b.offset);
780
+ while (r.remaining > 0) {
781
+ const start = r.offset;
782
+ let obj;
794
783
  try {
795
- const r = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(buffer.subarray(offset));
796
- const flags = Number(r.readVarInt());
797
- const objectIdPresent = (flags & 4) !== 0;
798
- const groupIdPresent = (flags & 8) !== 0;
799
- const priorityPresent = (flags & 16) !== 0;
800
- const extensionsPresent = (flags & 32) !== 0;
801
- const subgroupEncoding = flags & 3;
802
- if (groupIdPresent) r.readVarInt();
803
- if (subgroupEncoding === 3) r.readVarInt();
804
- let objectId = 0n;
805
- if (objectIdPresent) objectId = r.readVarInt();
806
- if (priorityPresent) r.readUint8();
807
- let extensionData = new Uint8Array(0);
808
- if (extensionsPresent) {
809
- const extLen = Number(r.readVarInt());
810
- extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
811
- }
812
- const payloadLength = Number(r.readVarInt());
813
- const payloadByteOffset = r.offset;
814
- const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
815
- controller.enqueue({
816
- type: "object",
817
- objectId,
818
- payloadLength,
819
- payload,
820
- extensionData,
821
- byteOffset: 0,
822
- payloadByteOffset
823
- });
824
- offset += r.offset;
784
+ obj = readFetchObject(r, b.base, st);
825
785
  } catch (e) {
826
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError && e.code === "UNEXPECTED_END") {
827
- break;
786
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
787
+ b.offset = start;
788
+ return;
828
789
  }
829
790
  controller.error(e);
830
791
  return;
831
792
  }
793
+ b.offset = r.offset;
794
+ controller.enqueue(obj);
832
795
  }
833
796
  },
834
797
  flush(controller) {
835
- if (offset < buffer.length) {
836
- controller.error(new (0, _chunk4XLYCT5Qcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
798
+ if (b.unread > 0) {
799
+ controller.error(new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
837
800
  }
838
801
  }
839
802
  });
840
803
  }
841
804
  function createDataStreamDecoder() {
842
- let buffer = new Uint8Array(0);
843
- let offset = 0;
844
- let inner = null;
845
- return new TransformStream({
846
- transform(chunk, controller) {
847
- if (offset > 0) {
848
- buffer = buffer.subarray(offset);
849
- offset = 0;
850
- }
851
- const newBuffer = new Uint8Array(buffer.length + chunk.length);
852
- newBuffer.set(buffer, 0);
853
- newBuffer.set(chunk, buffer.length);
854
- buffer = newBuffer;
855
- if (inner === null) {
856
- if (offset >= buffer.length) return;
857
- const firstByte = buffer[offset];
858
- if (isValidSubgroupType(firstByte)) {
859
- const decoder = createSubgroupStreamDecoder();
860
- inner = decoder;
861
- } else if (firstByte === 5) {
862
- const decoder = createFetchStreamDecoder();
863
- inner = decoder;
864
- } else {
865
- controller.error(
866
- new (0, _chunk4XLYCT5Qcjs.DecodeError)(
867
- "CONSTRAINT_VIOLATION",
868
- `Unknown data stream type: 0x${firstByte.toString(16)}`,
869
- 0
870
- )
871
- );
872
- return;
805
+ let writer = null;
806
+ let pump = Promise.resolve();
807
+ let broken = false;
808
+ function attach(inner, controller) {
809
+ writer = inner.writable.getWriter();
810
+ const reader = inner.readable.getReader();
811
+ pump = (async () => {
812
+ try {
813
+ for (; ; ) {
814
+ const { done, value } = await reader.read();
815
+ if (done) break;
816
+ controller.enqueue(value);
817
+ }
818
+ } catch (e) {
819
+ if (!broken) {
820
+ broken = true;
821
+ controller.error(e);
873
822
  }
874
823
  }
875
- },
876
- flush(controller) {
877
- if (offset >= buffer.length) return;
878
- const view = buffer.subarray(offset);
879
- const firstByte = view[0];
880
- let result;
824
+ })();
825
+ }
826
+ async function feed(bytes) {
827
+ if (writer === null || broken || bytes.length === 0) return;
828
+ try {
829
+ await writer.write(bytes);
830
+ } catch (e2) {
831
+ broken = true;
832
+ }
833
+ }
834
+ return new TransformStream({
835
+ async transform(chunk, controller) {
836
+ if (broken) return;
837
+ if (writer !== null) {
838
+ await feed(chunk);
839
+ return;
840
+ }
841
+ if (chunk.length === 0) return;
842
+ const firstByte = chunk[0];
881
843
  if (isValidSubgroupType(firstByte)) {
882
- result = decodeSubgroupStream(view);
844
+ attach(
845
+ createSubgroupStreamDecoder(),
846
+ controller
847
+ );
883
848
  } else if (firstByte === 5) {
884
- result = decodeFetchStream(view);
849
+ attach(
850
+ createFetchStreamDecoder(),
851
+ controller
852
+ );
885
853
  } else {
854
+ broken = true;
886
855
  controller.error(
887
- new (0, _chunk4XLYCT5Qcjs.DecodeError)(
856
+ new (0, _chunk5IMHJIAZcjs.DecodeError)(
888
857
  "CONSTRAINT_VIOLATION",
889
858
  `Unknown data stream type: 0x${firstByte.toString(16)}`,
890
859
  0
@@ -892,31 +861,15 @@ function createDataStreamDecoder() {
892
861
  );
893
862
  return;
894
863
  }
895
- if (!result.ok) {
896
- controller.error(result.error);
897
- return;
898
- }
899
- const stream = result.value;
900
- if (stream.type === "subgroup") {
901
- controller.enqueue({
902
- type: "subgroup_header",
903
- trackAlias: stream.trackAlias,
904
- groupId: stream.groupId,
905
- subgroupId: stream.subgroupId,
906
- publisherPriority: stream.publisherPriority
907
- });
908
- for (const obj of stream.objects) {
909
- controller.enqueue(obj);
910
- }
911
- } else if (stream.type === "fetch") {
912
- controller.enqueue({
913
- type: "fetch_header",
914
- requestId: stream.requestId
915
- });
916
- for (const obj of stream.objects) {
917
- controller.enqueue(obj);
918
- }
864
+ await feed(chunk);
865
+ },
866
+ async flush() {
867
+ if (writer === null) return;
868
+ try {
869
+ await writer.close();
870
+ } catch (e3) {
919
871
  }
872
+ await pump;
920
873
  }
921
874
  });
922
875
  }
@@ -941,7 +894,7 @@ function encodeSetupOptions(opts, writer) {
941
894
  entries.push({
942
895
  type: SETUP_OPT_AUTHORIZATION_TOKEN,
943
896
  encode: (w) => {
944
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(64);
897
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(64);
945
898
  encodeAuthorizationToken(token, tmpW);
946
899
  const raw = tmpW.finish();
947
900
  w.writeVarInt(BigInt(raw.byteLength));
@@ -994,11 +947,11 @@ function encodeSetupOptions(opts, writer) {
994
947
  type: id,
995
948
  encode: (w) => {
996
949
  if (id % 2n === 0n) {
997
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
998
- const tmpReader = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(raw);
950
+ const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
951
+ const tmpReader = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(raw);
999
952
  w.writeVarInt(tmpReader.readVarInt());
1000
953
  } else {
1001
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
954
+ const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
1002
955
  w.writeVarInt(BigInt(raw.byteLength));
1003
956
  w.writeBytes(raw);
1004
957
  }
@@ -1031,13 +984,13 @@ function decodeSetupOptions(reader, payloadEnd) {
1031
984
  } else if (optType === SETUP_OPT_MAX_REQUEST_UPDATES) {
1032
985
  result.max_request_updates = value;
1033
986
  } else {
1034
- const tmpWriter = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(16);
987
+ const tmpWriter = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(16);
1035
988
  tmpWriter.writeVarInt(value);
1036
989
  const raw = tmpWriter.finish();
1037
990
  unknown.push({
1038
991
  id: `0x${optType.toString(16)}`,
1039
992
  length: raw.byteLength,
1040
- raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, raw)
993
+ raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, raw)
1041
994
  });
1042
995
  }
1043
996
  } else {
@@ -1046,10 +999,9 @@ function decodeSetupOptions(reader, payloadEnd) {
1046
999
  if (optType === SETUP_OPT_PATH) {
1047
1000
  result.path = textDecoder.decode(bytes);
1048
1001
  } else if (optType === SETUP_OPT_AUTHORIZATION_TOKEN) {
1049
- result.authorization_token = [
1050
- ..._nullishCoalesce(result.authorization_token, () => ( [])),
1051
- decodeAuthorizationToken(new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes))
1052
- ];
1002
+ const token = decodeAuthorizationToken(new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes));
1003
+ noteAuthTokenValue(reader.offset - length, length, token);
1004
+ result.authorization_token = [..._nullishCoalesce(result.authorization_token, () => ( [])), token];
1053
1005
  } else if (optType === SETUP_OPT_AUTHORITY) {
1054
1006
  result.authority = textDecoder.decode(bytes);
1055
1007
  } else if (optType === SETUP_OPT_MOQT_IMPLEMENTATION) {
@@ -1058,7 +1010,7 @@ function decodeSetupOptions(reader, payloadEnd) {
1058
1010
  unknown.push({
1059
1011
  id: `0x${optType.toString(16)}`,
1060
1012
  length,
1061
- raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, bytes)
1013
+ raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, bytes)
1062
1014
  });
1063
1015
  }
1064
1016
  }
@@ -1078,6 +1030,11 @@ function encodeAuthorizationToken(token, w) {
1078
1030
  w.writeBytes(tv);
1079
1031
  }
1080
1032
  }
1033
+ function noteAuthTokenValue(valueStart, valueLength, token) {
1034
+ const value = token.token_value;
1035
+ if (value === void 0 || value.byteLength === 0) return;
1036
+ _chunk5IMHJIAZcjs.recordAuthValueSpan.call(void 0, valueStart + valueLength - value.byteLength, value.byteLength);
1037
+ }
1081
1038
  function decodeAuthorizationToken(r) {
1082
1039
  const alias_type = r.readVarInt();
1083
1040
  const aliasType = Number(alias_type);
@@ -1134,7 +1091,7 @@ function encodeRangeFilter(filter, hasProperty, w) {
1134
1091
  w.writeVarInt(0n);
1135
1092
  return;
1136
1093
  }
1137
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
1094
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
1138
1095
  tmpW.writeUint8(Number(_nullishCoalesce(filter.set_id, () => ( 0n))));
1139
1096
  if (hasProperty) {
1140
1097
  tmpW.writeVarInt(_nullishCoalesce(filter.property_type, () => ( 0n)));
@@ -1220,7 +1177,7 @@ function encodeParams(params, writer) {
1220
1177
  entries.push({
1221
1178
  type: PARAM_AUTHORIZATION_TOKEN,
1222
1179
  encode: (w) => {
1223
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(64);
1180
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(64);
1224
1181
  encodeAuthorizationToken(token, tmpW);
1225
1182
  const raw = tmpW.finish();
1226
1183
  w.writeVarInt(BigInt(raw.byteLength));
@@ -1281,7 +1238,7 @@ function encodeParams(params, writer) {
1281
1238
  type: PARAM_LOCATION_FILTER,
1282
1239
  encode: (w) => {
1283
1240
  const f = params.location_filter;
1284
- const tmpW = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(32);
1241
+ const tmpW = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(32);
1285
1242
  tmpW.writeVarInt(f.filter_type);
1286
1243
  if (f.filter_type === 3n || f.filter_type === 4n) {
1287
1244
  tmpW.writeVarInt(f.start_group);
@@ -1355,7 +1312,7 @@ function encodeParams(params, writer) {
1355
1312
  entries.push({
1356
1313
  type: id,
1357
1314
  encode: (w) => {
1358
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
1315
+ const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
1359
1316
  w.writeBytes(raw);
1360
1317
  }
1361
1318
  });
@@ -1380,7 +1337,7 @@ function decodeParams(reader, messageType) {
1380
1337
  prevType = paramType;
1381
1338
  const scope = PARAMETER_SCOPE.get(paramType);
1382
1339
  if (scope !== void 0 && !scope.has(messageType)) {
1383
- throw new (0, _chunk4XLYCT5Qcjs.DecodeError)(
1340
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
1384
1341
  "CONSTRAINT_VIOLATION",
1385
1342
  `Message Parameter 0x${paramType.toString(16)} may not appear in ${messageType}`,
1386
1343
  reader.offset
@@ -1391,10 +1348,9 @@ function decodeParams(reader, messageType) {
1391
1348
  } else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
1392
1349
  const length = Number(reader.readVarInt());
1393
1350
  const bytes = reader.readBytes(length);
1394
- result.authorization_token = [
1395
- ..._nullishCoalesce(result.authorization_token, () => ( [])),
1396
- decodeAuthorizationToken(new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes))
1397
- ];
1351
+ const token = decodeAuthorizationToken(new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes));
1352
+ noteAuthTokenValue(reader.offset - length, length, token);
1353
+ result.authorization_token = [..._nullishCoalesce(result.authorization_token, () => ( [])), token];
1398
1354
  } else if (paramType === PARAM_RENDEZVOUS_TIMEOUT) {
1399
1355
  result.rendezvous_timeout = reader.readVarInt();
1400
1356
  } else if (paramType === PARAM_SUBGROUP_DELIVERY_TIMEOUT) {
@@ -1449,7 +1405,7 @@ function decodeParams(reader, messageType) {
1449
1405
  } else if (paramType === PARAM_TRACK_NAMESPACE_PREFIX) {
1450
1406
  result.track_namespace_prefix = decodeNamespaceTuple(reader);
1451
1407
  } else {
1452
- throw new (0, _chunk4XLYCT5Qcjs.DecodeError)(
1408
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
1453
1409
  "INVALID_PARAMETER",
1454
1410
  `Unknown Message Parameter type 0x${paramType.toString(16)}`,
1455
1411
  reader.offset
@@ -1520,11 +1476,11 @@ function encodeTrackProperties(props, writer) {
1520
1476
  type: id,
1521
1477
  encode: (w) => {
1522
1478
  if (id % 2n === 0n) {
1523
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
1524
- const tmpReader = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(raw);
1479
+ const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
1480
+ const tmpReader = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(raw);
1525
1481
  w.writeVarInt(tmpReader.readVarInt());
1526
1482
  } else {
1527
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
1483
+ const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
1528
1484
  w.writeVarInt(BigInt(raw.byteLength));
1529
1485
  w.writeBytes(raw);
1530
1486
  }
@@ -1563,13 +1519,13 @@ function decodeTrackProperties(reader, payloadEnd) {
1563
1519
  } else if (propType === TPROP_DYNAMIC_GROUPS) {
1564
1520
  result.dynamic_groups = value;
1565
1521
  } else {
1566
- const tmpWriter = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(16);
1522
+ const tmpWriter = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(16);
1567
1523
  tmpWriter.writeVarInt(value);
1568
1524
  const raw = tmpWriter.finish();
1569
1525
  unknown.push({
1570
1526
  id: `0x${propType.toString(16)}`,
1571
1527
  length: raw.byteLength,
1572
- raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, raw)
1528
+ raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, raw)
1573
1529
  });
1574
1530
  }
1575
1531
  } else {
@@ -1581,7 +1537,7 @@ function decodeTrackProperties(reader, payloadEnd) {
1581
1537
  unknown.push({
1582
1538
  id: `0x${propType.toString(16)}`,
1583
1539
  length,
1584
- raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, bytes)
1540
+ raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, bytes)
1585
1541
  });
1586
1542
  }
1587
1543
  }
@@ -1812,7 +1768,7 @@ function decodeFetchPayload(r) {
1812
1768
  const fetch_type = r.readVarInt();
1813
1769
  const ft = Number(fetch_type);
1814
1770
  if (ft < 1 || ft > 3) {
1815
- throw new (0, _chunk4XLYCT5Qcjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${ft}`, r.offset);
1771
+ throw new (0, _chunk5IMHJIAZcjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${ft}`, r.offset);
1816
1772
  }
1817
1773
  let standalone;
1818
1774
  let joining;
@@ -1902,13 +1858,13 @@ function encodeMessage(message) {
1902
1858
  if (typeId === void 0) {
1903
1859
  throw new Error(`Unknown message type: ${message.type}`);
1904
1860
  }
1905
- const payloadWriter = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)();
1861
+ const payloadWriter = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)();
1906
1862
  encodePayload(message, payloadWriter);
1907
1863
  const payload = payloadWriter.finishView();
1908
1864
  if (payload.byteLength > 65535) {
1909
1865
  throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
1910
1866
  }
1911
- const writer = new (0, _chunk4XLYCT5Qcjs.MoqtBufferWriter)(payload.byteLength + 16);
1867
+ const writer = new (0, _chunk5IMHJIAZcjs.MoqtBufferWriter)(payload.byteLength + 16);
1912
1868
  writer.writeVarInt(typeId);
1913
1869
  writer.writeUint8(payload.byteLength >> 8 & 255);
1914
1870
  writer.writeUint8(payload.byteLength & 255);
@@ -1961,13 +1917,13 @@ function encodePayload(msg, w) {
1961
1917
  }
1962
1918
  function decodeMessage(bytes) {
1963
1919
  try {
1964
- const reader = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(bytes);
1920
+ const reader = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes);
1965
1921
  const typeId = reader.readVarInt();
1966
1922
  const lenHi = reader.readUint8();
1967
1923
  const lenLo = reader.readUint8();
1968
1924
  const payloadLength = lenHi << 8 | lenLo;
1969
1925
  const payloadBytes = reader.readBytes(payloadLength);
1970
- const payloadReader = new (0, _chunk4XLYCT5Qcjs.MoqtBufferReader)(payloadBytes);
1926
+ const payloadReader = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(payloadBytes);
1971
1927
  let message;
1972
1928
  if (typeId === MSG_SETUP) {
1973
1929
  message = decodeSetupPayload(payloadReader, payloadLength);
@@ -2008,7 +1964,7 @@ function decodeMessage(bytes) {
2008
1964
  } else {
2009
1965
  return {
2010
1966
  ok: false,
2011
- error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
1967
+ error: new (0, _chunk5IMHJIAZcjs.DecodeError)(
2012
1968
  "UNKNOWN_MESSAGE_TYPE",
2013
1969
  `Unknown message type ID: 0x${typeId.toString(16)}`,
2014
1970
  0
@@ -2017,7 +1973,7 @@ function decodeMessage(bytes) {
2017
1973
  }
2018
1974
  return { ok: true, value: message, bytesRead: reader.offset };
2019
1975
  } catch (e) {
2020
- if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) {
1976
+ if (e instanceof _chunk5IMHJIAZcjs.DecodeError) {
2021
1977
  return { ok: false, error: e };
2022
1978
  }
2023
1979
  throw e;
@@ -2052,7 +2008,7 @@ function createStreamDecoder() {
2052
2008
  flush(controller) {
2053
2009
  if (offset < buffer.length) {
2054
2010
  controller.error(
2055
- new (0, _chunk4XLYCT5Qcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete message data", 0)
2011
+ new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete message data", 0)
2056
2012
  );
2057
2013
  }
2058
2014
  }
@@ -2078,6 +2034,20 @@ function createDraft19Codec() {
2078
2034
  createDataStreamDecoder
2079
2035
  };
2080
2036
  }
2037
+ function redactAuthTokens(bytes) {
2038
+ let payloadStart;
2039
+ try {
2040
+ const probe = new (0, _chunk5IMHJIAZcjs.MoqtBufferReader)(bytes);
2041
+ probe.readVarInt();
2042
+ probe.readUint8();
2043
+ probe.readUint8();
2044
+ payloadStart = probe.offset;
2045
+ } catch (e4) {
2046
+ return { bytes, redacted: 0, incomplete: false, decoded: false };
2047
+ }
2048
+ return _chunk5IMHJIAZcjs.redactWith.call(void 0, bytes, payloadStart, () => decodeMessage(bytes).ok);
2049
+ }
2050
+
2081
2051
 
2082
2052
 
2083
2053
 
@@ -2122,4 +2092,4 @@ function createDraft19Codec() {
2122
2092
 
2123
2093
 
2124
2094
 
2125
- 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_SKIPPED = MSG_PUBLISH_SKIPPED; 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_MAX_FILTER_RANGES = SETUP_OPT_MAX_FILTER_RANGES; exports.SETUP_OPT_MOQT_IMPLEMENTATION = SETUP_OPT_MOQT_IMPLEMENTATION; exports.SETUP_OPT_MAX_REQUEST_UPDATES = SETUP_OPT_MAX_REQUEST_UPDATES; 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.createDraft19Codec = createDraft19Codec;
2095
+ 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_SKIPPED = MSG_PUBLISH_SKIPPED; 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_MAX_FILTER_RANGES = SETUP_OPT_MAX_FILTER_RANGES; exports.SETUP_OPT_MOQT_IMPLEMENTATION = SETUP_OPT_MOQT_IMPLEMENTATION; exports.SETUP_OPT_MAX_REQUEST_UPDATES = SETUP_OPT_MAX_REQUEST_UPDATES; 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.createDraft19Codec = createDraft19Codec; exports.redactAuthTokens = redactAuthTokens;