@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.
- package/CHANGELOG.md +175 -0
- package/README.md +3 -2
- package/dist/auth-redaction-B9JJOlIY.d.cts +100 -0
- package/dist/auth-redaction-B9JJOlIY.d.ts +100 -0
- package/dist/{chunk-RYKQXBG6.cjs → chunk-27K5BUAG.cjs} +481 -517
- package/dist/{chunk-WCPENYNE.js → chunk-3RNQMGKA.js} +359 -390
- package/dist/{chunk-TSUZ6GJV.js → chunk-5AWIXOLB.js} +438 -469
- package/dist/{chunk-4XLYCT5Q.cjs → chunk-5IMHJIAZ.cjs} +52 -2
- package/dist/{chunk-KTNERCTZ.cjs → chunk-5JGZCKJO.cjs} +488 -518
- package/dist/{chunk-WCTMPDUX.cjs → chunk-73K4OSAN.cjs} +401 -432
- package/dist/{chunk-N2V7Z37J.js → chunk-7VQKRGRD.js} +19 -3
- package/dist/{chunk-BIBMDTU5.cjs → chunk-A3UCQOIB.cjs} +486 -517
- package/dist/{chunk-K2B3OVFK.js → chunk-A7PDMVXM.js} +24 -3
- package/dist/{chunk-VZHL2U2N.cjs → chunk-A7VQO6YC.cjs} +54 -38
- package/dist/{chunk-AQ445VV7.cjs → chunk-ACQHZLRZ.cjs} +66 -46
- package/dist/{chunk-L5DRACXS.js → chunk-BBICOMW6.js} +25 -3
- package/dist/{chunk-T4VWPKDG.cjs → chunk-BNIUVOCJ.cjs} +529 -599
- package/dist/{chunk-UKKDOOUO.cjs → chunk-CNC6ANS4.cjs} +58 -37
- package/dist/{chunk-OZRK73NQ.js → chunk-FDLQSWHK.js} +433 -469
- package/dist/{chunk-IJAF6PAY.js → chunk-FFNOE4UR.js} +19 -3
- package/dist/{chunk-CZNW3R5E.cjs → chunk-GMENT63T.cjs} +54 -38
- package/dist/{chunk-XCRCAUGI.cjs → chunk-HM7BLRVP.cjs} +291 -297
- package/dist/{chunk-XHAP2YST.js → chunk-HZONHFNO.js} +19 -3
- package/dist/{chunk-SDJTSMOW.cjs → chunk-ILYABWDK.cjs} +60 -38
- package/dist/{chunk-IDV2JYJ6.cjs → chunk-KRSFTZVO.cjs} +56 -40
- package/dist/{chunk-RIIA4ALQ.cjs → chunk-KSPH6KMH.cjs} +54 -38
- package/dist/{chunk-OUNN4IQB.cjs → chunk-KTY4LAUV.cjs} +482 -497
- package/dist/chunk-OBATJBNL.cjs +868 -0
- package/dist/{chunk-RZTLQAKF.js → chunk-OJNLJT5D.js} +0 -1
- package/dist/{chunk-FT3HDNIB.js → chunk-PJK2ZS3I.js} +467 -537
- package/dist/{chunk-G53WYUXL.js → chunk-PSMZKHOC.js} +441 -456
- package/dist/{chunk-7RE6KSIY.cjs → chunk-Q5JQGHWY.cjs} +0 -1
- package/dist/{chunk-BX2N7TZM.js → chunk-SQTUQY5E.js} +31 -11
- package/dist/chunk-T2TCLZZV.js +2304 -0
- package/dist/chunk-WB65UG7G.cjs +2304 -0
- package/dist/{chunk-CF5DDD3Q.js → chunk-WCRLAKDW.js} +239 -245
- package/dist/{chunk-KYVTM5VI.js → chunk-WL2YUEXH.js} +19 -3
- package/dist/chunk-XPCBPACE.js +868 -0
- package/dist/{chunk-KGDVC4O6.js → chunk-YCNIVZS7.js} +439 -469
- package/dist/{chunk-KLPWJU6W.js → chunk-YRZQVNZO.js} +50 -0
- package/dist/{codec-DOmAmFkI.d.ts → codec-B-oUU-cp.d.ts} +21 -2
- package/dist/{codec-DNmiG2e0.d.cts → codec-B3RpCI9k.d.cts} +21 -2
- package/dist/codec-B5pcOS3m.d.cts +38 -0
- package/dist/{codec-BNy5syCU.d.ts → codec-BLjxwK2f.d.ts} +21 -2
- package/dist/{codec-alVA27Uc.d.ts → codec-BV3CL_3m.d.ts} +21 -2
- package/dist/{codec-Czejcmxr.d.cts → codec-BYCDWgED.d.ts} +22 -3
- package/dist/{codec-DaXjRrOV.d.ts → codec-Bwqq7ZQT.d.ts} +22 -3
- package/dist/{codec-CFWu5KVT.d.cts → codec-BzWxOFby.d.cts} +22 -3
- package/dist/codec-C-nJhNNl.d.ts +38 -0
- package/dist/{codec-EvybrBuY.d.cts → codec-C11VEPbQ.d.cts} +21 -2
- package/dist/codec-C9U0Vzy9.d.cts +68 -0
- package/dist/{codec-Cm3D261p.d.ts → codec-CCx22jnd.d.ts} +21 -2
- package/dist/{codec-CwZ6OCPP.d.ts → codec-CP3zkfTv.d.ts} +22 -3
- package/dist/{codec-BxQTybUX.d.cts → codec-CRmOLDpt.d.ts} +22 -3
- package/dist/{codec-DzkdW4kO.d.cts → codec-CUu56DDU.d.cts} +21 -2
- package/dist/codec-Cb8mUre3.d.ts +68 -0
- package/dist/{codec-f7vxeVIS.d.cts → codec-CemqAQdR.d.cts} +22 -3
- package/dist/{codec-gl4_QEva.d.ts → codec-CxMvsVMS.d.ts} +21 -2
- package/dist/{codec-Bd60SGKH.d.cts → codec-DIgMVTi4.d.cts} +21 -2
- package/dist/{codec--CVeqGQv.d.ts → codec-DYzozF68.d.ts} +21 -2
- package/dist/{codec-CWnf8mn_.d.cts → codec-D_O9zxax.d.ts} +22 -3
- package/dist/{codec-08ZOr5wI.d.ts → codec-Ddc-QxV6.d.cts} +22 -3
- package/dist/{codec-CBdOIfMY.d.ts → codec-DoojMl2z.d.cts} +22 -3
- package/dist/{codec-BrTi4K7r.d.cts → codec-DqdjiOQF.d.ts} +22 -3
- package/dist/{codec-CXCjya_G.d.cts → codec-Dstemwrq.d.cts} +21 -2
- package/dist/{codec-Dl_QIXMz.d.ts → codec-Dt6nuejp.d.ts} +21 -2
- package/dist/{codec-Bux_Q40X.d.ts → codec-DuYhd8fP.d.cts} +22 -3
- package/dist/{codec-Cfo_z5ET.d.cts → codec-DwNOFgPU.d.cts} +21 -2
- package/dist/{codec-guzqtfMk.d.cts → codec-l01BpNhF.d.cts} +21 -2
- package/dist/{codec-C3mdsGx3.d.ts → codec-psN2vB6I.d.cts} +22 -3
- package/dist/draft07-session.d.cts +3 -3
- package/dist/draft07-session.d.ts +3 -3
- package/dist/draft07.cjs +48 -4
- package/dist/draft07.d.cts +44 -4
- package/dist/draft07.d.ts +44 -4
- package/dist/draft07.js +49 -5
- package/dist/draft08-session.d.cts +3 -3
- package/dist/draft08-session.d.ts +3 -3
- package/dist/draft08.cjs +76 -3
- package/dist/draft08.d.cts +73 -5
- package/dist/draft08.d.ts +73 -5
- package/dist/draft08.js +77 -4
- package/dist/draft09-session.d.cts +3 -3
- package/dist/draft09-session.d.ts +3 -3
- package/dist/draft09.cjs +76 -3
- package/dist/draft09.d.cts +73 -5
- package/dist/draft09.d.ts +73 -5
- package/dist/draft09.js +77 -4
- package/dist/draft10-session.d.cts +3 -3
- package/dist/draft10-session.d.ts +3 -3
- package/dist/draft10.cjs +76 -3
- package/dist/draft10.d.cts +73 -5
- package/dist/draft10.d.ts +73 -5
- package/dist/draft10.js +77 -4
- package/dist/draft11-session.d.cts +3 -3
- package/dist/draft11-session.d.ts +3 -3
- package/dist/draft11.cjs +104 -3
- package/dist/draft11.d.cts +101 -5
- package/dist/draft11.d.ts +101 -5
- package/dist/draft11.js +105 -4
- package/dist/draft12-session.d.cts +3 -3
- package/dist/draft12-session.d.ts +3 -3
- package/dist/draft12.cjs +113 -3
- package/dist/draft12.d.cts +110 -5
- package/dist/draft12.d.ts +110 -5
- package/dist/draft12.js +114 -4
- package/dist/draft13-session.d.cts +3 -3
- package/dist/draft13-session.d.ts +3 -3
- package/dist/draft13.cjs +105 -3
- package/dist/draft13.d.cts +102 -5
- package/dist/draft13.d.ts +102 -5
- package/dist/draft13.js +106 -4
- package/dist/draft14-session.d.cts +3 -3
- package/dist/draft14-session.d.ts +3 -3
- package/dist/draft14.cjs +107 -3
- package/dist/draft14.d.cts +104 -31
- package/dist/draft14.d.ts +104 -31
- package/dist/draft14.js +108 -4
- package/dist/draft15-session.d.cts +4 -4
- package/dist/draft15-session.d.ts +4 -4
- package/dist/draft15.cjs +69 -3
- package/dist/draft15.d.cts +68 -25
- package/dist/draft15.d.ts +68 -25
- package/dist/draft15.js +70 -4
- package/dist/draft16-session.cjs +2 -2
- package/dist/draft16-session.d.cts +4 -4
- package/dist/draft16-session.d.ts +4 -4
- package/dist/draft16-session.js +1 -1
- package/dist/draft16.cjs +76 -8
- package/dist/draft16.d.cts +70 -16
- package/dist/draft16.d.ts +70 -16
- package/dist/draft16.js +73 -5
- package/dist/draft17-session.d.cts +4 -4
- package/dist/draft17-session.d.ts +4 -4
- package/dist/draft17.cjs +77 -3
- package/dist/draft17.d.cts +75 -6
- package/dist/draft17.d.ts +75 -6
- package/dist/draft17.js +78 -4
- package/dist/draft18-session.d.cts +4 -4
- package/dist/draft18-session.d.ts +4 -4
- package/dist/draft18.cjs +8 -3
- package/dist/draft18.d.cts +6 -5
- package/dist/draft18.d.ts +6 -5
- package/dist/draft18.js +9 -4
- package/dist/draft19-session.d.cts +4 -4
- package/dist/draft19-session.d.ts +4 -4
- package/dist/draft19.cjs +11 -4
- package/dist/draft19.d.cts +6 -5
- package/dist/draft19.d.ts +6 -5
- package/dist/draft19.js +12 -5
- package/dist/draft20-session.d.cts +4 -4
- package/dist/draft20-session.d.ts +4 -4
- package/dist/draft20.cjs +8 -3
- package/dist/draft20.d.cts +6 -5
- package/dist/draft20.d.ts +6 -5
- package/dist/draft20.js +9 -4
- package/dist/draft21-session.cjs +8 -0
- package/dist/draft21-session.d.cts +195 -0
- package/dist/draft21-session.d.ts +195 -0
- package/dist/draft21-session.js +8 -0
- package/dist/draft21.cjs +222 -0
- package/dist/draft21.d.cts +176 -0
- package/dist/draft21.d.ts +176 -0
- package/dist/draft21.js +222 -0
- package/dist/index.cjs +37 -31
- package/dist/index.d.cts +29 -23
- package/dist/index.d.ts +29 -23
- package/dist/index.js +22 -16
- package/dist/{session-types-Dn7b3RZM.d.ts → session-types-Cxx7W8zZ.d.ts} +1 -1
- package/dist/{session-types-B9idsih-.d.cts → session-types-DZkI_qFG.d.cts} +1 -1
- package/dist/session.cjs +7 -3
- package/dist/session.d.cts +11 -9
- package/dist/session.d.ts +11 -9
- package/dist/session.js +6 -2
- package/dist/{types-DG5_iKuv.d.cts → types-2NisMA8_.d.cts} +1 -1
- package/dist/{types-DG5_iKuv.d.ts → types-2NisMA8_.d.ts} +1 -1
- package/dist/{types-C1rxh-id.d.cts → types-Btp416jt.d.cts} +8 -0
- package/dist/{types-C1rxh-id.d.ts → types-Btp416jt.d.ts} +8 -0
- package/dist/{types-CZTzbIzQ.d.cts → types-BxTL1NXw.d.cts} +7 -0
- package/dist/{types-CZTzbIzQ.d.ts → types-BxTL1NXw.d.ts} +7 -0
- package/dist/{types-pShrs3fN.d.cts → types-CuibHYcf.d.cts} +7 -0
- package/dist/{types-pShrs3fN.d.ts → types-CuibHYcf.d.ts} +7 -0
- package/dist/{types-CY-QWxd-.d.cts → types-CwN7AEoL.d.cts} +13 -1
- package/dist/{types-CY-QWxd-.d.ts → types-CwN7AEoL.d.ts} +13 -1
- package/dist/{types-D4bmW8rY.d.cts → types-DAnalt5K.d.cts} +7 -0
- package/dist/{types-D4bmW8rY.d.ts → types-DAnalt5K.d.ts} +7 -0
- package/dist/types-DDwidj2d.d.cts +371 -0
- package/dist/types-DDwidj2d.d.ts +371 -0
- package/dist/{types-Bg86GGVZ.d.cts → types-DxXNP32l.d.cts} +8 -0
- package/dist/{types-Bg86GGVZ.d.ts → types-DxXNP32l.d.ts} +8 -0
- package/package.json +15 -3
- package/src/core/auth-redaction.ts +190 -0
- package/src/core/types.ts +1 -0
- package/src/drafts/draft07/codec.ts +40 -0
- package/src/drafts/draft07/error-codes.ts +44 -0
- package/src/drafts/draft07/index.ts +15 -0
- package/src/drafts/draft08/codec.ts +40 -0
- package/src/drafts/draft08/error-codes.ts +76 -0
- package/src/drafts/draft08/index.ts +21 -0
- package/src/drafts/draft09/codec.ts +40 -0
- package/src/drafts/draft09/error-codes.ts +76 -0
- package/src/drafts/draft09/index.ts +21 -0
- package/src/drafts/draft10/codec.ts +40 -0
- package/src/drafts/draft10/error-codes.ts +76 -0
- package/src/drafts/draft10/index.ts +21 -0
- package/src/drafts/draft11/codec.ts +60 -0
- package/src/drafts/draft11/error-codes.ts +106 -0
- package/src/drafts/draft11/index.ts +23 -0
- package/src/drafts/draft12/codec.ts +61 -0
- package/src/drafts/draft12/error-codes.ts +116 -0
- package/src/drafts/draft12/index.ts +25 -0
- package/src/drafts/draft13/codec.ts +69 -11
- package/src/drafts/draft13/error-codes.ts +107 -0
- package/src/drafts/draft13/index.ts +23 -0
- package/src/drafts/draft13/types.ts +1 -1
- package/src/drafts/draft14/codec.ts +65 -4
- package/src/drafts/draft14/data-streams.ts +331 -259
- package/src/drafts/draft14/error-codes.ts +109 -0
- package/src/drafts/draft14/index.ts +23 -0
- package/src/drafts/draft15/codec.ts +65 -8
- package/src/drafts/draft15/data-streams.ts +489 -444
- package/src/drafts/draft15/error-codes.ts +66 -0
- package/src/drafts/draft15/index.ts +15 -0
- package/src/drafts/draft15/types.ts +7 -0
- package/src/drafts/draft16/codec.ts +146 -52
- package/src/drafts/draft16/data-streams.ts +513 -442
- package/src/drafts/draft16/error-codes.ts +68 -0
- package/src/drafts/draft16/index.ts +15 -0
- package/src/drafts/draft16/messages.ts +4 -4
- package/src/drafts/draft16/session-fsm.ts +0 -1
- package/src/drafts/draft16/types.ts +22 -8
- package/src/drafts/draft17/codec.ts +73 -12
- package/src/drafts/draft17/data-streams.ts +567 -488
- package/src/drafts/draft17/index.ts +15 -0
- package/src/drafts/draft17/types.ts +7 -0
- package/src/drafts/draft18/codec.ts +66 -9
- package/src/drafts/draft18/data-streams.ts +570 -482
- package/src/drafts/draft18/index.ts +3 -0
- package/src/drafts/draft18/types.ts +16 -8
- package/src/drafts/draft19/codec.ts +70 -10
- package/src/drafts/draft19/data-streams.ts +570 -482
- package/src/drafts/draft19/error-codes.ts +3 -1
- package/src/drafts/draft19/index.ts +3 -0
- package/src/drafts/draft19/messages.ts +3 -1
- package/src/drafts/draft19/types.ts +22 -11
- package/src/drafts/draft20/codec.ts +90 -23
- package/src/drafts/draft20/data-streams.ts +610 -563
- package/src/drafts/draft20/index.ts +3 -0
- package/src/drafts/draft20/types.ts +14 -2
- package/src/drafts/draft21/codec.ts +1816 -0
- package/src/drafts/draft21/data-streams.ts +1338 -0
- package/src/drafts/draft21/error-codes.ts +135 -0
- package/src/drafts/draft21/index.ts +168 -0
- package/src/drafts/draft21/messages.ts +68 -0
- package/src/drafts/draft21/rules.ts +107 -0
- package/src/drafts/draft21/session-fsm.ts +1063 -0
- package/src/drafts/draft21/session.ts +21 -0
- package/src/drafts/draft21/types.ts +473 -0
- package/src/index.ts +9 -1
- package/src/session.ts +4 -0
- package/dist/codec-BJ7BHuiZ.d.ts +0 -18
- 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
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk5IMHJIAZcjs = require('./chunk-5IMHJIAZ.cjs');
|
|
8
10
|
|
|
9
11
|
// src/drafts/draft16/messages.ts
|
|
10
12
|
var MSG_REQUEST_UPDATE = 0x02n;
|
|
@@ -70,7 +72,7 @@ var MESSAGE_ID_MAP = new Map(
|
|
|
70
72
|
// src/drafts/draft16/data-streams.ts
|
|
71
73
|
var FETCH_STREAM_TYPE = 0x05n;
|
|
72
74
|
function encodeSubgroupStream(stream) {
|
|
73
|
-
const w = new (0,
|
|
75
|
+
const w = new (0, _chunk5IMHJIAZcjs.BufferWriter)();
|
|
74
76
|
const streamType = stream.headerType;
|
|
75
77
|
w.writeVarInt(BigInt(streamType));
|
|
76
78
|
const extensionsPresent = (streamType & 1) !== 0;
|
|
@@ -103,7 +105,7 @@ function encodeSubgroupStream(stream) {
|
|
|
103
105
|
return w.finish();
|
|
104
106
|
}
|
|
105
107
|
function encodeDatagram(dg) {
|
|
106
|
-
const w = new (0,
|
|
108
|
+
const w = new (0, _chunk5IMHJIAZcjs.BufferWriter)();
|
|
107
109
|
const dgType = dg.datagramType;
|
|
108
110
|
w.writeVarInt(BigInt(dgType));
|
|
109
111
|
w.writeVarInt(dg.trackAlias);
|
|
@@ -131,7 +133,7 @@ function encodeDatagram(dg) {
|
|
|
131
133
|
return w.finish();
|
|
132
134
|
}
|
|
133
135
|
function encodeFetchStream(stream) {
|
|
134
|
-
const w = new (0,
|
|
136
|
+
const w = new (0, _chunk5IMHJIAZcjs.BufferWriter)();
|
|
135
137
|
w.writeVarInt(FETCH_STREAM_TYPE);
|
|
136
138
|
w.writeVarInt(stream.requestId);
|
|
137
139
|
for (const obj of stream.objects) {
|
|
@@ -159,104 +161,112 @@ function encodeFetchStream(stream) {
|
|
|
159
161
|
}
|
|
160
162
|
return w.finish();
|
|
161
163
|
}
|
|
164
|
+
function readSubgroupHeader(r) {
|
|
165
|
+
const streamType = Number(r.readVarInt());
|
|
166
|
+
if (!(streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63) || (streamType & 6) === 6) {
|
|
167
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
168
|
+
"CONSTRAINT_VIOLATION",
|
|
169
|
+
`Expected subgroup stream type 0x10-0x1F/0x30-0x3F, got 0x${streamType.toString(16)}`,
|
|
170
|
+
0
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
const extensionsPresent = (streamType & 1) !== 0;
|
|
174
|
+
const hasSubgroupField = (streamType & 4) !== 0;
|
|
175
|
+
const subgroupIsFirstObjId = (streamType & 2) !== 0 && !hasSubgroupField;
|
|
176
|
+
const endOfGroup = (streamType & 8) !== 0;
|
|
177
|
+
const hasPriority = streamType < 48;
|
|
178
|
+
const trackAlias = r.readVarInt();
|
|
179
|
+
const groupId = r.readVarInt();
|
|
180
|
+
let subgroupId = 0n;
|
|
181
|
+
if (hasSubgroupField) {
|
|
182
|
+
subgroupId = r.readVarInt();
|
|
183
|
+
}
|
|
184
|
+
let publisherPriority = 128;
|
|
185
|
+
if (hasPriority) {
|
|
186
|
+
publisherPriority = r.readUint8();
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
streamType,
|
|
190
|
+
extensionsPresent,
|
|
191
|
+
subgroupIsFirstObjId,
|
|
192
|
+
endOfGroup,
|
|
193
|
+
trackAlias,
|
|
194
|
+
groupId,
|
|
195
|
+
subgroupId,
|
|
196
|
+
publisherPriority
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function readSubgroupObject(r, extensionsPresent, isFirst, prevObjectId, base) {
|
|
200
|
+
const byteOffset = base + r.offset;
|
|
201
|
+
const delta = r.readVarInt();
|
|
202
|
+
const objectId = isFirst ? delta : prevObjectId + 1n + delta;
|
|
203
|
+
let extensionData = new Uint8Array(0);
|
|
204
|
+
if (extensionsPresent) {
|
|
205
|
+
const extLen = Number(r.readVarInt());
|
|
206
|
+
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
207
|
+
}
|
|
208
|
+
const payloadLength = Number(r.readVarInt());
|
|
209
|
+
let payload;
|
|
210
|
+
let status;
|
|
211
|
+
let payloadByteOffset;
|
|
212
|
+
if (payloadLength === 0) {
|
|
213
|
+
status = r.readVarInt();
|
|
214
|
+
payloadByteOffset = base + r.offset;
|
|
215
|
+
payload = new Uint8Array(0);
|
|
216
|
+
} else {
|
|
217
|
+
payloadByteOffset = base + r.offset;
|
|
218
|
+
payload = r.readBytesView(payloadLength);
|
|
219
|
+
}
|
|
220
|
+
const obj = {
|
|
221
|
+
type: "object",
|
|
222
|
+
byteOffset,
|
|
223
|
+
payloadByteOffset,
|
|
224
|
+
objectId,
|
|
225
|
+
payloadLength,
|
|
226
|
+
payload,
|
|
227
|
+
extensionData
|
|
228
|
+
};
|
|
229
|
+
if (status !== void 0) obj.status = status;
|
|
230
|
+
return obj;
|
|
231
|
+
}
|
|
162
232
|
function decodeSubgroupStream(bytes) {
|
|
163
233
|
try {
|
|
164
|
-
const r = new (0,
|
|
165
|
-
const
|
|
166
|
-
if (!(streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63) || (streamType & 6) === 6) {
|
|
167
|
-
return {
|
|
168
|
-
ok: false,
|
|
169
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
170
|
-
"CONSTRAINT_VIOLATION",
|
|
171
|
-
`Expected subgroup stream type 0x10-0x1F/0x30-0x3F, got 0x${streamType.toString(16)}`,
|
|
172
|
-
0
|
|
173
|
-
)
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
const extensionsPresent = (streamType & 1) !== 0;
|
|
177
|
-
const hasSubgroupField = (streamType & 4) !== 0;
|
|
178
|
-
const subgroupIsFirstObjId = (streamType & 2) !== 0 && !hasSubgroupField;
|
|
179
|
-
const endOfGroup = (streamType & 8) !== 0;
|
|
180
|
-
const hasPriority = streamType < 48;
|
|
181
|
-
const trackAlias = r.readVarInt();
|
|
182
|
-
const groupId = r.readVarInt();
|
|
183
|
-
let subgroupId = 0n;
|
|
184
|
-
if (hasSubgroupField) {
|
|
185
|
-
subgroupId = r.readVarInt();
|
|
186
|
-
}
|
|
187
|
-
let publisherPriority = 128;
|
|
188
|
-
if (hasPriority) {
|
|
189
|
-
publisherPriority = r.readUint8();
|
|
190
|
-
}
|
|
234
|
+
const r = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
235
|
+
const h = readSubgroupHeader(r);
|
|
191
236
|
const objects = [];
|
|
192
237
|
let prevObjectId = -1n;
|
|
193
|
-
let
|
|
238
|
+
let isFirst = true;
|
|
239
|
+
let subgroupId = h.subgroupId;
|
|
194
240
|
while (r.remaining > 0) {
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (firstObject) {
|
|
199
|
-
objectId = delta;
|
|
200
|
-
if (subgroupIsFirstObjId && firstObject) {
|
|
201
|
-
subgroupId = objectId;
|
|
202
|
-
}
|
|
203
|
-
firstObject = false;
|
|
204
|
-
} else {
|
|
205
|
-
objectId = prevObjectId + 1n + delta;
|
|
206
|
-
}
|
|
207
|
-
let extensionData = new Uint8Array(0);
|
|
208
|
-
if (extensionsPresent) {
|
|
209
|
-
const extLen = Number(r.readVarInt());
|
|
210
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
211
|
-
}
|
|
212
|
-
const payloadLength = Number(r.readVarInt());
|
|
213
|
-
let payload;
|
|
214
|
-
let status;
|
|
215
|
-
let payloadByteOffset;
|
|
216
|
-
if (payloadLength === 0) {
|
|
217
|
-
status = r.readVarInt();
|
|
218
|
-
payloadByteOffset = r.offset;
|
|
219
|
-
payload = new Uint8Array(0);
|
|
220
|
-
} else {
|
|
221
|
-
payloadByteOffset = r.offset;
|
|
222
|
-
payload = r.readBytesView(payloadLength);
|
|
223
|
-
}
|
|
224
|
-
const obj = {
|
|
225
|
-
type: "object",
|
|
226
|
-
byteOffset,
|
|
227
|
-
payloadByteOffset,
|
|
228
|
-
objectId,
|
|
229
|
-
payloadLength,
|
|
230
|
-
extensionData,
|
|
231
|
-
payload
|
|
232
|
-
};
|
|
233
|
-
if (status !== void 0) obj.status = status;
|
|
241
|
+
const obj = readSubgroupObject(r, h.extensionsPresent, isFirst, prevObjectId, 0);
|
|
242
|
+
if (isFirst && h.subgroupIsFirstObjId) subgroupId = obj.objectId;
|
|
243
|
+
isFirst = false;
|
|
234
244
|
objects.push(obj);
|
|
235
|
-
prevObjectId = objectId;
|
|
245
|
+
prevObjectId = obj.objectId;
|
|
236
246
|
}
|
|
237
247
|
const result = {
|
|
238
248
|
type: "subgroup",
|
|
239
|
-
headerType: streamType,
|
|
240
|
-
trackAlias,
|
|
241
|
-
groupId,
|
|
249
|
+
headerType: h.streamType,
|
|
250
|
+
trackAlias: h.trackAlias,
|
|
251
|
+
groupId: h.groupId,
|
|
242
252
|
subgroupId,
|
|
243
|
-
publisherPriority,
|
|
244
|
-
objects
|
|
253
|
+
publisherPriority: h.publisherPriority,
|
|
254
|
+
objects,
|
|
255
|
+
...h.endOfGroup ? { endOfGroup: true } : {}
|
|
245
256
|
};
|
|
246
|
-
if (endOfGroup) result.endOfGroup = true;
|
|
247
257
|
return {
|
|
248
258
|
ok: true,
|
|
249
259
|
value: result,
|
|
250
260
|
bytesRead: r.offset
|
|
251
261
|
};
|
|
252
262
|
} catch (e) {
|
|
253
|
-
if (e instanceof
|
|
263
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
|
|
254
264
|
throw e;
|
|
255
265
|
}
|
|
256
266
|
}
|
|
257
267
|
function decodeDatagram(bytes) {
|
|
258
268
|
try {
|
|
259
|
-
const r = new (0,
|
|
269
|
+
const r = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
260
270
|
const dgType = Number(r.readVarInt());
|
|
261
271
|
const extensionsPresent = (dgType & 1) !== 0;
|
|
262
272
|
const objectIdAbsent = (dgType & 4) !== 0;
|
|
@@ -304,18 +314,135 @@ function decodeDatagram(bytes) {
|
|
|
304
314
|
result.extensionData = extensionData;
|
|
305
315
|
return { ok: true, value: result, bytesRead: r.offset };
|
|
306
316
|
} catch (e) {
|
|
307
|
-
if (e instanceof
|
|
317
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
|
|
308
318
|
throw e;
|
|
309
319
|
}
|
|
310
320
|
}
|
|
321
|
+
function newFetchObjectState() {
|
|
322
|
+
return { prevGroupId: 0n, prevSubgroupId: 0n, prevObjectId: 0n, prevPriority: 128, first: true };
|
|
323
|
+
}
|
|
324
|
+
function readFetchObject(r, base, st) {
|
|
325
|
+
let obj;
|
|
326
|
+
const byteOffset = base + r.offset;
|
|
327
|
+
const flags = Number(r.readVarInt());
|
|
328
|
+
let groupId = st.prevGroupId;
|
|
329
|
+
let subgroupId = st.prevSubgroupId;
|
|
330
|
+
let objectId = st.prevObjectId + 1n;
|
|
331
|
+
let payloadLength;
|
|
332
|
+
let payload;
|
|
333
|
+
if (flags >= 128) {
|
|
334
|
+
if (flags !== 140 && flags !== 268) {
|
|
335
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
336
|
+
"CONSTRAINT_VIOLATION",
|
|
337
|
+
`Unknown serialization flags value: 0x${flags.toString(16)}`,
|
|
338
|
+
r.offset
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
groupId = r.readVarInt();
|
|
342
|
+
objectId = r.readVarInt();
|
|
343
|
+
payloadLength = Number(r.readVarInt());
|
|
344
|
+
const payloadByteOffset = base + r.offset;
|
|
345
|
+
payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
|
|
346
|
+
obj = {
|
|
347
|
+
type: "object",
|
|
348
|
+
byteOffset,
|
|
349
|
+
payloadByteOffset,
|
|
350
|
+
serializationFlags: flags,
|
|
351
|
+
groupId,
|
|
352
|
+
subgroupId,
|
|
353
|
+
objectId,
|
|
354
|
+
publisherPriority: st.prevPriority,
|
|
355
|
+
payloadLength,
|
|
356
|
+
extensionData: new Uint8Array(0),
|
|
357
|
+
payload
|
|
358
|
+
};
|
|
359
|
+
} else {
|
|
360
|
+
const datagramForwarding = (flags & 64) !== 0;
|
|
361
|
+
const subgroupEncoding = datagramForwarding ? -1 : flags & 3;
|
|
362
|
+
const objectIdPresent = (flags & 4) !== 0;
|
|
363
|
+
const groupIdPresent = (flags & 8) !== 0;
|
|
364
|
+
const priorityPresent = (flags & 16) !== 0;
|
|
365
|
+
const extensionsPresent = (flags & 32) !== 0;
|
|
366
|
+
if (groupIdPresent) {
|
|
367
|
+
groupId = r.readVarInt();
|
|
368
|
+
} else if (st.first) {
|
|
369
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
370
|
+
"CONSTRAINT_VIOLATION",
|
|
371
|
+
"First fetch object must include groupId",
|
|
372
|
+
r.offset
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
if (datagramForwarding) {
|
|
376
|
+
} else if (subgroupEncoding === 0) {
|
|
377
|
+
subgroupId = 0n;
|
|
378
|
+
} else if (subgroupEncoding === 1) {
|
|
379
|
+
if (st.first) {
|
|
380
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
381
|
+
"CONSTRAINT_VIOLATION",
|
|
382
|
+
"First fetch object cannot reference prior subgroupId",
|
|
383
|
+
r.offset
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
} else if (subgroupEncoding === 2) {
|
|
387
|
+
if (st.first) {
|
|
388
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
389
|
+
"CONSTRAINT_VIOLATION",
|
|
390
|
+
"First fetch object cannot reference prior subgroupId",
|
|
391
|
+
r.offset
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
subgroupId = st.prevSubgroupId + 1n;
|
|
395
|
+
} else {
|
|
396
|
+
subgroupId = r.readVarInt();
|
|
397
|
+
}
|
|
398
|
+
if (objectIdPresent) {
|
|
399
|
+
objectId = r.readVarInt();
|
|
400
|
+
} else if (st.first) {
|
|
401
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
402
|
+
"CONSTRAINT_VIOLATION",
|
|
403
|
+
"First fetch object must include objectId",
|
|
404
|
+
r.offset
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
if (priorityPresent) {
|
|
408
|
+
st.prevPriority = r.readUint8();
|
|
409
|
+
}
|
|
410
|
+
let extensionData = new Uint8Array(0);
|
|
411
|
+
if (extensionsPresent) {
|
|
412
|
+
const extLen = Number(r.readVarInt());
|
|
413
|
+
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
414
|
+
}
|
|
415
|
+
payloadLength = Number(r.readVarInt());
|
|
416
|
+
const payloadByteOffset = base + r.offset;
|
|
417
|
+
payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
|
|
418
|
+
obj = {
|
|
419
|
+
type: "object",
|
|
420
|
+
byteOffset,
|
|
421
|
+
payloadByteOffset,
|
|
422
|
+
serializationFlags: flags,
|
|
423
|
+
groupId,
|
|
424
|
+
subgroupId,
|
|
425
|
+
objectId,
|
|
426
|
+
publisherPriority: st.prevPriority,
|
|
427
|
+
payloadLength,
|
|
428
|
+
extensionData,
|
|
429
|
+
payload
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
st.prevGroupId = groupId;
|
|
433
|
+
st.prevSubgroupId = subgroupId;
|
|
434
|
+
st.prevObjectId = objectId;
|
|
435
|
+
st.first = false;
|
|
436
|
+
return obj;
|
|
437
|
+
}
|
|
311
438
|
function decodeFetchStream(bytes) {
|
|
312
439
|
try {
|
|
313
|
-
const r = new (0,
|
|
440
|
+
const r = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
314
441
|
const streamType = r.readVarInt();
|
|
315
442
|
if (streamType !== FETCH_STREAM_TYPE) {
|
|
316
443
|
return {
|
|
317
444
|
ok: false,
|
|
318
|
-
error: new (0,
|
|
445
|
+
error: new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
319
446
|
"CONSTRAINT_VIOLATION",
|
|
320
447
|
`Expected fetch stream type 0x05, got 0x${streamType.toString(16)}`,
|
|
321
448
|
0
|
|
@@ -324,137 +451,9 @@ function decodeFetchStream(bytes) {
|
|
|
324
451
|
}
|
|
325
452
|
const requestId = r.readVarInt();
|
|
326
453
|
const objects = [];
|
|
327
|
-
|
|
328
|
-
let prevSubgroupId = 0n;
|
|
329
|
-
let prevObjectId = 0n;
|
|
330
|
-
let prevPriority = 128;
|
|
331
|
-
let first = true;
|
|
454
|
+
const st = newFetchObjectState();
|
|
332
455
|
while (r.remaining > 0) {
|
|
333
|
-
|
|
334
|
-
const flags = Number(r.readVarInt());
|
|
335
|
-
let groupId = prevGroupId;
|
|
336
|
-
let subgroupId = prevSubgroupId;
|
|
337
|
-
let objectId = prevObjectId + 1n;
|
|
338
|
-
let payloadLength;
|
|
339
|
-
let payload;
|
|
340
|
-
if (flags >= 128) {
|
|
341
|
-
if (flags !== 140 && flags !== 268) {
|
|
342
|
-
return {
|
|
343
|
-
ok: false,
|
|
344
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
345
|
-
"CONSTRAINT_VIOLATION",
|
|
346
|
-
`Unknown serialization flags value: 0x${flags.toString(16)}`,
|
|
347
|
-
r.offset
|
|
348
|
-
)
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
groupId = r.readVarInt();
|
|
352
|
-
objectId = r.readVarInt();
|
|
353
|
-
payloadLength = Number(r.readVarInt());
|
|
354
|
-
const payloadByteOffset = r.offset;
|
|
355
|
-
payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
|
|
356
|
-
objects.push({
|
|
357
|
-
type: "object",
|
|
358
|
-
byteOffset,
|
|
359
|
-
payloadByteOffset,
|
|
360
|
-
serializationFlags: flags,
|
|
361
|
-
groupId,
|
|
362
|
-
subgroupId,
|
|
363
|
-
objectId,
|
|
364
|
-
publisherPriority: prevPriority,
|
|
365
|
-
payloadLength,
|
|
366
|
-
extensionData: new Uint8Array(0),
|
|
367
|
-
payload
|
|
368
|
-
});
|
|
369
|
-
} else {
|
|
370
|
-
const datagramForwarding = (flags & 64) !== 0;
|
|
371
|
-
const subgroupEncoding = datagramForwarding ? -1 : flags & 3;
|
|
372
|
-
const objectIdPresent = (flags & 4) !== 0;
|
|
373
|
-
const groupIdPresent = (flags & 8) !== 0;
|
|
374
|
-
const priorityPresent = (flags & 16) !== 0;
|
|
375
|
-
const extensionsPresent = (flags & 32) !== 0;
|
|
376
|
-
if (groupIdPresent) {
|
|
377
|
-
groupId = r.readVarInt();
|
|
378
|
-
} else if (first) {
|
|
379
|
-
return {
|
|
380
|
-
ok: false,
|
|
381
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
382
|
-
"CONSTRAINT_VIOLATION",
|
|
383
|
-
"First fetch object must include groupId",
|
|
384
|
-
r.offset
|
|
385
|
-
)
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
if (datagramForwarding) {
|
|
389
|
-
} else if (subgroupEncoding === 0) {
|
|
390
|
-
subgroupId = 0n;
|
|
391
|
-
} else if (subgroupEncoding === 1) {
|
|
392
|
-
if (first) {
|
|
393
|
-
return {
|
|
394
|
-
ok: false,
|
|
395
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
396
|
-
"CONSTRAINT_VIOLATION",
|
|
397
|
-
"First fetch object cannot reference prior subgroupId",
|
|
398
|
-
r.offset
|
|
399
|
-
)
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
} else if (subgroupEncoding === 2) {
|
|
403
|
-
if (first) {
|
|
404
|
-
return {
|
|
405
|
-
ok: false,
|
|
406
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
407
|
-
"CONSTRAINT_VIOLATION",
|
|
408
|
-
"First fetch object cannot reference prior subgroupId",
|
|
409
|
-
r.offset
|
|
410
|
-
)
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
subgroupId = prevSubgroupId + 1n;
|
|
414
|
-
} else {
|
|
415
|
-
subgroupId = r.readVarInt();
|
|
416
|
-
}
|
|
417
|
-
if (objectIdPresent) {
|
|
418
|
-
objectId = r.readVarInt();
|
|
419
|
-
} else if (first) {
|
|
420
|
-
return {
|
|
421
|
-
ok: false,
|
|
422
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
423
|
-
"CONSTRAINT_VIOLATION",
|
|
424
|
-
"First fetch object must include objectId",
|
|
425
|
-
r.offset
|
|
426
|
-
)
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
if (priorityPresent) {
|
|
430
|
-
prevPriority = r.readUint8();
|
|
431
|
-
}
|
|
432
|
-
let extensionData = new Uint8Array(0);
|
|
433
|
-
if (extensionsPresent) {
|
|
434
|
-
const extLen = Number(r.readVarInt());
|
|
435
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
436
|
-
}
|
|
437
|
-
payloadLength = Number(r.readVarInt());
|
|
438
|
-
const payloadByteOffset = r.offset;
|
|
439
|
-
payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
|
|
440
|
-
objects.push({
|
|
441
|
-
type: "object",
|
|
442
|
-
byteOffset,
|
|
443
|
-
payloadByteOffset,
|
|
444
|
-
serializationFlags: flags,
|
|
445
|
-
groupId,
|
|
446
|
-
subgroupId,
|
|
447
|
-
objectId,
|
|
448
|
-
publisherPriority: prevPriority,
|
|
449
|
-
payloadLength,
|
|
450
|
-
extensionData,
|
|
451
|
-
payload
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
prevGroupId = groupId;
|
|
455
|
-
prevSubgroupId = subgroupId;
|
|
456
|
-
prevObjectId = objectId;
|
|
457
|
-
first = false;
|
|
456
|
+
objects.push(readFetchObject(r, 0, st));
|
|
458
457
|
}
|
|
459
458
|
return {
|
|
460
459
|
ok: true,
|
|
@@ -462,7 +461,7 @@ function decodeFetchStream(bytes) {
|
|
|
462
461
|
bytesRead: r.offset
|
|
463
462
|
};
|
|
464
463
|
} catch (e) {
|
|
465
|
-
if (e instanceof
|
|
464
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
|
|
466
465
|
throw e;
|
|
467
466
|
}
|
|
468
467
|
}
|
|
@@ -480,145 +479,124 @@ function decodeDataStream(streamType, bytes) {
|
|
|
480
479
|
}
|
|
481
480
|
}
|
|
482
481
|
}
|
|
482
|
+
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); }
|
|
483
|
+
__init() {this.buf = new Uint8Array(0)}
|
|
484
|
+
/** Bytes written into `buf`. */
|
|
485
|
+
__init2() {this.len = 0}
|
|
486
|
+
/** Consumed prefix of `buf`; `base + offset` is the position in the stream. */
|
|
487
|
+
__init3() {this.offset = 0}
|
|
488
|
+
/** Absolute position of `buf[0]` within the stream. */
|
|
489
|
+
__init4() {this.base = 0}
|
|
490
|
+
get unread() {
|
|
491
|
+
return this.len - this.offset;
|
|
492
|
+
}
|
|
493
|
+
append(chunk) {
|
|
494
|
+
if (this.len + chunk.length > this.buf.length) {
|
|
495
|
+
const live = this.len - this.offset;
|
|
496
|
+
const needed = live + chunk.length;
|
|
497
|
+
let cap = Math.max(4096, this.buf.length);
|
|
498
|
+
while (cap < needed * 2) cap *= 2;
|
|
499
|
+
const next = new Uint8Array(cap);
|
|
500
|
+
next.set(this.buf.subarray(this.offset, this.len), 0);
|
|
501
|
+
this.buf = next;
|
|
502
|
+
this.base += this.offset;
|
|
503
|
+
this.len = live;
|
|
504
|
+
this.offset = 0;
|
|
505
|
+
}
|
|
506
|
+
this.buf.set(chunk, this.len);
|
|
507
|
+
this.len += chunk.length;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* The written bytes, for a reader positioned at `offset`. Bounded by `len`
|
|
511
|
+
* rather than by capacity, so `BufferReader.remaining` counts real bytes and
|
|
512
|
+
* not the spare room after them.
|
|
513
|
+
*/
|
|
514
|
+
written() {
|
|
515
|
+
return this.buf.subarray(0, this.len);
|
|
516
|
+
}
|
|
517
|
+
}, _class);
|
|
483
518
|
function createSubgroupStreamDecoder() {
|
|
484
|
-
|
|
485
|
-
let
|
|
519
|
+
const b = new StreamBuffer();
|
|
520
|
+
let header = null;
|
|
486
521
|
let headerEmitted = false;
|
|
487
522
|
let prevObjectId = -1n;
|
|
488
|
-
let
|
|
489
|
-
|
|
490
|
-
|
|
523
|
+
let isFirst = true;
|
|
524
|
+
function emitHeader(controller, h, subgroupId) {
|
|
525
|
+
controller.enqueue({
|
|
526
|
+
type: "subgroup_header",
|
|
527
|
+
headerType: h.streamType,
|
|
528
|
+
trackAlias: h.trackAlias,
|
|
529
|
+
groupId: h.groupId,
|
|
530
|
+
subgroupId,
|
|
531
|
+
publisherPriority: h.publisherPriority,
|
|
532
|
+
...h.endOfGroup ? { endOfGroup: true } : {}
|
|
533
|
+
});
|
|
534
|
+
headerEmitted = true;
|
|
535
|
+
}
|
|
491
536
|
return new TransformStream({
|
|
492
537
|
transform(chunk, controller) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
498
|
-
newBuffer.set(buffer, 0);
|
|
499
|
-
newBuffer.set(chunk, buffer.length);
|
|
500
|
-
buffer = newBuffer;
|
|
501
|
-
if (!headerEmitted) {
|
|
538
|
+
b.append(chunk);
|
|
539
|
+
const view = b.written();
|
|
540
|
+
if (header === null) {
|
|
502
541
|
try {
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
controller.error(
|
|
507
|
-
new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
508
|
-
"CONSTRAINT_VIOLATION",
|
|
509
|
-
`Expected subgroup stream type, got 0x${streamType.toString(16)}`,
|
|
510
|
-
0
|
|
511
|
-
)
|
|
512
|
-
);
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
_extensionsPresent = (streamType & 1) !== 0;
|
|
516
|
-
const hasSubgroupField = (streamType & 4) !== 0;
|
|
517
|
-
_subgroupIsFirstObjId = (streamType & 2) !== 0 && !hasSubgroupField;
|
|
518
|
-
const hasPriority = streamType < 48;
|
|
519
|
-
const trackAlias = r.readVarInt();
|
|
520
|
-
const groupId = r.readVarInt();
|
|
521
|
-
let subgroupId = 0n;
|
|
522
|
-
if (hasSubgroupField) {
|
|
523
|
-
subgroupId = r.readVarInt();
|
|
524
|
-
}
|
|
525
|
-
let publisherPriority = 128;
|
|
526
|
-
if (hasPriority) {
|
|
527
|
-
publisherPriority = r.readUint8();
|
|
528
|
-
}
|
|
529
|
-
controller.enqueue({
|
|
530
|
-
type: "subgroup_header",
|
|
531
|
-
trackAlias,
|
|
532
|
-
groupId,
|
|
533
|
-
subgroupId,
|
|
534
|
-
publisherPriority
|
|
535
|
-
});
|
|
536
|
-
headerEmitted = true;
|
|
537
|
-
offset += r.offset;
|
|
542
|
+
const hr = new (0, _chunk5IMHJIAZcjs.BufferReader)(view, b.offset);
|
|
543
|
+
header = readSubgroupHeader(hr);
|
|
544
|
+
b.offset = hr.offset;
|
|
538
545
|
} catch (e) {
|
|
539
|
-
if (e instanceof
|
|
546
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
540
547
|
return;
|
|
541
548
|
}
|
|
542
549
|
controller.error(e);
|
|
543
550
|
return;
|
|
544
551
|
}
|
|
552
|
+
if (!header.subgroupIsFirstObjId) emitHeader(controller, header, header.subgroupId);
|
|
545
553
|
}
|
|
546
|
-
|
|
554
|
+
const h = header;
|
|
555
|
+
if (h === null) return;
|
|
556
|
+
const r = new (0, _chunk5IMHJIAZcjs.BufferReader)(view, b.offset);
|
|
557
|
+
while (r.remaining > 0) {
|
|
558
|
+
const start = r.offset;
|
|
559
|
+
let obj;
|
|
547
560
|
try {
|
|
548
|
-
|
|
549
|
-
const delta = r.readVarInt();
|
|
550
|
-
let objectId;
|
|
551
|
-
if (firstObject) {
|
|
552
|
-
objectId = delta;
|
|
553
|
-
firstObject = false;
|
|
554
|
-
} else {
|
|
555
|
-
objectId = prevObjectId + 1n + delta;
|
|
556
|
-
}
|
|
557
|
-
let extensionData = new Uint8Array(0);
|
|
558
|
-
if (_extensionsPresent) {
|
|
559
|
-
const extLen = Number(r.readVarInt());
|
|
560
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
561
|
-
}
|
|
562
|
-
const payloadLength = Number(r.readVarInt());
|
|
563
|
-
let payloadByteOffset;
|
|
564
|
-
let status;
|
|
565
|
-
if (payloadLength === 0) {
|
|
566
|
-
status = r.readVarInt();
|
|
567
|
-
payloadByteOffset = r.offset;
|
|
568
|
-
} else {
|
|
569
|
-
payloadByteOffset = r.offset;
|
|
570
|
-
}
|
|
571
|
-
const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
|
|
572
|
-
const obj = {
|
|
573
|
-
type: "object",
|
|
574
|
-
byteOffset: 0,
|
|
575
|
-
payloadByteOffset,
|
|
576
|
-
objectId,
|
|
577
|
-
payloadLength,
|
|
578
|
-
payload,
|
|
579
|
-
extensionData
|
|
580
|
-
};
|
|
581
|
-
if (status !== void 0) obj.status = status;
|
|
582
|
-
controller.enqueue(obj);
|
|
583
|
-
offset += r.offset;
|
|
584
|
-
prevObjectId = objectId;
|
|
561
|
+
obj = readSubgroupObject(r, h.extensionsPresent, isFirst, prevObjectId, b.base);
|
|
585
562
|
} catch (e) {
|
|
586
|
-
if (e instanceof
|
|
587
|
-
|
|
563
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
564
|
+
b.offset = start;
|
|
565
|
+
return;
|
|
588
566
|
}
|
|
589
567
|
controller.error(e);
|
|
590
568
|
return;
|
|
591
569
|
}
|
|
570
|
+
if (!headerEmitted) emitHeader(controller, h, obj.objectId);
|
|
571
|
+
isFirst = false;
|
|
572
|
+
b.offset = r.offset;
|
|
573
|
+
prevObjectId = obj.objectId;
|
|
574
|
+
controller.enqueue(obj);
|
|
592
575
|
}
|
|
593
576
|
},
|
|
594
577
|
flush(controller) {
|
|
595
|
-
if (
|
|
596
|
-
|
|
578
|
+
if (header !== null && !headerEmitted) emitHeader(controller, header, 0n);
|
|
579
|
+
if (b.unread > 0) {
|
|
580
|
+
controller.error(new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
|
|
597
581
|
}
|
|
598
582
|
}
|
|
599
583
|
});
|
|
600
584
|
}
|
|
601
585
|
function createFetchStreamDecoder() {
|
|
602
|
-
|
|
603
|
-
let offset = 0;
|
|
586
|
+
const b = new StreamBuffer();
|
|
604
587
|
let headerEmitted = false;
|
|
588
|
+
const st = newFetchObjectState();
|
|
605
589
|
return new TransformStream({
|
|
606
590
|
transform(chunk, controller) {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
offset = 0;
|
|
610
|
-
}
|
|
611
|
-
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
612
|
-
newBuffer.set(buffer, 0);
|
|
613
|
-
newBuffer.set(chunk, buffer.length);
|
|
614
|
-
buffer = newBuffer;
|
|
591
|
+
b.append(chunk);
|
|
592
|
+
const view = b.written();
|
|
615
593
|
if (!headerEmitted) {
|
|
616
594
|
try {
|
|
617
|
-
const
|
|
618
|
-
const streamType =
|
|
595
|
+
const r2 = new (0, _chunk5IMHJIAZcjs.BufferReader)(view, b.offset);
|
|
596
|
+
const streamType = r2.readVarInt();
|
|
619
597
|
if (streamType !== FETCH_STREAM_TYPE) {
|
|
620
598
|
controller.error(
|
|
621
|
-
new (0,
|
|
599
|
+
new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
622
600
|
"CONSTRAINT_VIOLATION",
|
|
623
601
|
`Expected fetch stream type 0x05, got 0x${streamType.toString(16)}`,
|
|
624
602
|
0
|
|
@@ -626,113 +604,96 @@ function createFetchStreamDecoder() {
|
|
|
626
604
|
);
|
|
627
605
|
return;
|
|
628
606
|
}
|
|
629
|
-
const requestId =
|
|
607
|
+
const requestId = r2.readVarInt();
|
|
630
608
|
controller.enqueue({ type: "fetch_header", requestId });
|
|
631
609
|
headerEmitted = true;
|
|
632
|
-
offset
|
|
610
|
+
b.offset = r2.offset;
|
|
633
611
|
} catch (e) {
|
|
634
|
-
if (e instanceof
|
|
612
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
635
613
|
return;
|
|
636
614
|
}
|
|
637
615
|
controller.error(e);
|
|
638
616
|
return;
|
|
639
617
|
}
|
|
640
618
|
}
|
|
641
|
-
|
|
619
|
+
const r = new (0, _chunk5IMHJIAZcjs.BufferReader)(view, b.offset);
|
|
620
|
+
while (r.remaining > 0) {
|
|
621
|
+
const start = r.offset;
|
|
622
|
+
let obj;
|
|
642
623
|
try {
|
|
643
|
-
|
|
644
|
-
const flags = Number(r.readVarInt());
|
|
645
|
-
const objectIdPresent = (flags & 4) !== 0;
|
|
646
|
-
const groupIdPresent = (flags & 8) !== 0;
|
|
647
|
-
const priorityPresent = (flags & 16) !== 0;
|
|
648
|
-
const extensionsPresent = (flags & 32) !== 0;
|
|
649
|
-
const subgroupEncoding = flags & 3;
|
|
650
|
-
if (groupIdPresent) r.readVarInt();
|
|
651
|
-
if (subgroupEncoding === 3) r.readVarInt();
|
|
652
|
-
let objectId = 0n;
|
|
653
|
-
if (objectIdPresent) objectId = r.readVarInt();
|
|
654
|
-
if (priorityPresent) r.readUint8();
|
|
655
|
-
let extensionData = new Uint8Array(0);
|
|
656
|
-
if (extensionsPresent) {
|
|
657
|
-
const extLen = Number(r.readVarInt());
|
|
658
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
659
|
-
}
|
|
660
|
-
const payloadLength = Number(r.readVarInt());
|
|
661
|
-
const payloadByteOffset = r.offset;
|
|
662
|
-
const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
|
|
663
|
-
controller.enqueue({
|
|
664
|
-
type: "object",
|
|
665
|
-
byteOffset: 0,
|
|
666
|
-
payloadByteOffset,
|
|
667
|
-
objectId,
|
|
668
|
-
payloadLength,
|
|
669
|
-
payload,
|
|
670
|
-
extensionData
|
|
671
|
-
});
|
|
672
|
-
offset += r.offset;
|
|
624
|
+
obj = readFetchObject(r, b.base, st);
|
|
673
625
|
} catch (e) {
|
|
674
|
-
if (e instanceof
|
|
675
|
-
|
|
626
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
627
|
+
b.offset = start;
|
|
628
|
+
return;
|
|
676
629
|
}
|
|
677
630
|
controller.error(e);
|
|
678
631
|
return;
|
|
679
632
|
}
|
|
633
|
+
b.offset = r.offset;
|
|
634
|
+
controller.enqueue(obj);
|
|
680
635
|
}
|
|
681
636
|
},
|
|
682
637
|
flush(controller) {
|
|
683
|
-
if (
|
|
684
|
-
controller.error(new (0,
|
|
638
|
+
if (b.unread > 0) {
|
|
639
|
+
controller.error(new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
|
|
685
640
|
}
|
|
686
641
|
}
|
|
687
642
|
});
|
|
688
643
|
}
|
|
689
644
|
function createDataStreamDecoder() {
|
|
690
|
-
let
|
|
691
|
-
let
|
|
692
|
-
let
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
if (
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
const decoder = createSubgroupStreamDecoder();
|
|
708
|
-
inner = decoder;
|
|
709
|
-
} else if (firstByte === 5) {
|
|
710
|
-
const decoder = createFetchStreamDecoder();
|
|
711
|
-
inner = decoder;
|
|
712
|
-
} else {
|
|
713
|
-
controller.error(
|
|
714
|
-
new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
715
|
-
"CONSTRAINT_VIOLATION",
|
|
716
|
-
`Unknown data stream type: 0x${firstByte.toString(16)}`,
|
|
717
|
-
0
|
|
718
|
-
)
|
|
719
|
-
);
|
|
720
|
-
return;
|
|
645
|
+
let writer = null;
|
|
646
|
+
let pump = Promise.resolve();
|
|
647
|
+
let broken = false;
|
|
648
|
+
function attach(inner, controller) {
|
|
649
|
+
writer = inner.writable.getWriter();
|
|
650
|
+
const reader = inner.readable.getReader();
|
|
651
|
+
pump = (async () => {
|
|
652
|
+
try {
|
|
653
|
+
for (; ; ) {
|
|
654
|
+
const { done, value } = await reader.read();
|
|
655
|
+
if (done) break;
|
|
656
|
+
controller.enqueue(value);
|
|
657
|
+
}
|
|
658
|
+
} catch (e) {
|
|
659
|
+
if (!broken) {
|
|
660
|
+
broken = true;
|
|
661
|
+
controller.error(e);
|
|
721
662
|
}
|
|
722
663
|
}
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
664
|
+
})();
|
|
665
|
+
}
|
|
666
|
+
async function feed(bytes) {
|
|
667
|
+
if (writer === null || broken || bytes.length === 0) return;
|
|
668
|
+
try {
|
|
669
|
+
await writer.write(bytes);
|
|
670
|
+
} catch (e2) {
|
|
671
|
+
broken = true;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return new TransformStream({
|
|
675
|
+
async transform(chunk, controller) {
|
|
676
|
+
if (broken) return;
|
|
677
|
+
if (writer !== null) {
|
|
678
|
+
await feed(chunk);
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
if (chunk.length === 0) return;
|
|
682
|
+
const firstByte = chunk[0];
|
|
729
683
|
if (firstByte >= 16 && firstByte <= 31 || firstByte >= 48 && firstByte <= 63) {
|
|
730
|
-
|
|
684
|
+
attach(
|
|
685
|
+
createSubgroupStreamDecoder(),
|
|
686
|
+
controller
|
|
687
|
+
);
|
|
731
688
|
} else if (firstByte === 5) {
|
|
732
|
-
|
|
689
|
+
attach(
|
|
690
|
+
createFetchStreamDecoder(),
|
|
691
|
+
controller
|
|
692
|
+
);
|
|
733
693
|
} else {
|
|
694
|
+
broken = true;
|
|
734
695
|
controller.error(
|
|
735
|
-
new (0,
|
|
696
|
+
new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
736
697
|
"CONSTRAINT_VIOLATION",
|
|
737
698
|
`Unknown data stream type: 0x${firstByte.toString(16)}`,
|
|
738
699
|
0
|
|
@@ -740,31 +701,15 @@ function createDataStreamDecoder() {
|
|
|
740
701
|
);
|
|
741
702
|
return;
|
|
742
703
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
type: "subgroup_header",
|
|
751
|
-
trackAlias: stream.trackAlias,
|
|
752
|
-
groupId: stream.groupId,
|
|
753
|
-
subgroupId: stream.subgroupId,
|
|
754
|
-
publisherPriority: stream.publisherPriority
|
|
755
|
-
});
|
|
756
|
-
for (const obj of stream.objects) {
|
|
757
|
-
controller.enqueue(obj);
|
|
758
|
-
}
|
|
759
|
-
} else if (stream.type === "fetch") {
|
|
760
|
-
controller.enqueue({
|
|
761
|
-
type: "fetch_header",
|
|
762
|
-
requestId: stream.requestId
|
|
763
|
-
});
|
|
764
|
-
for (const obj of stream.objects) {
|
|
765
|
-
controller.enqueue(obj);
|
|
766
|
-
}
|
|
704
|
+
await feed(chunk);
|
|
705
|
+
},
|
|
706
|
+
async flush() {
|
|
707
|
+
if (writer === null) return;
|
|
708
|
+
try {
|
|
709
|
+
await writer.close();
|
|
710
|
+
} catch (e3) {
|
|
767
711
|
}
|
|
712
|
+
await pump;
|
|
768
713
|
}
|
|
769
714
|
});
|
|
770
715
|
}
|
|
@@ -773,72 +718,96 @@ function createDataStreamDecoder() {
|
|
|
773
718
|
var textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
774
719
|
var textDecoder = /* @__PURE__ */ new TextDecoder();
|
|
775
720
|
function encodeSetupParams(params, writer) {
|
|
776
|
-
|
|
777
|
-
if (params.path !== void 0) count++;
|
|
778
|
-
if (params.max_request_id !== void 0) count++;
|
|
779
|
-
count += _nullishCoalesce(_optionalChain([params, 'access', _ => _.authorization_token, 'optionalAccess', _2 => _2.length]), () => ( 0));
|
|
780
|
-
if (params.max_auth_token_cache_size !== void 0) count++;
|
|
781
|
-
if (params.authority !== void 0) count++;
|
|
782
|
-
if (params.moqt_implementation !== void 0) count++;
|
|
783
|
-
if (params.unknown) count += params.unknown.length;
|
|
784
|
-
writer.writeVarInt(count);
|
|
721
|
+
const entries = [];
|
|
785
722
|
if (params.path !== void 0) {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
723
|
+
entries.push({
|
|
724
|
+
type: SETUP_PARAM_PATH,
|
|
725
|
+
encode: (w) => {
|
|
726
|
+
const encoded = textEncoder.encode(params.path);
|
|
727
|
+
w.writeVarInt(encoded.byteLength);
|
|
728
|
+
w.writeBytes(encoded);
|
|
729
|
+
}
|
|
730
|
+
});
|
|
790
731
|
}
|
|
791
732
|
if (params.max_request_id !== void 0) {
|
|
792
|
-
|
|
793
|
-
|
|
733
|
+
entries.push({
|
|
734
|
+
type: SETUP_PARAM_MAX_REQUEST_ID,
|
|
735
|
+
encode: (w) => w.writeVarInt(params.max_request_id)
|
|
736
|
+
});
|
|
794
737
|
}
|
|
795
738
|
for (const token of _nullishCoalesce(params.authorization_token, () => ( []))) {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
739
|
+
entries.push({
|
|
740
|
+
type: SETUP_PARAM_AUTHORIZATION_TOKEN,
|
|
741
|
+
encode: (w) => {
|
|
742
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(64);
|
|
743
|
+
encodeAuthorizationToken(token, tmpW);
|
|
744
|
+
const raw = tmpW.finish();
|
|
745
|
+
w.writeVarInt(raw.byteLength);
|
|
746
|
+
w.writeBytes(raw);
|
|
747
|
+
}
|
|
748
|
+
});
|
|
802
749
|
}
|
|
803
750
|
if (params.max_auth_token_cache_size !== void 0) {
|
|
804
|
-
|
|
805
|
-
|
|
751
|
+
entries.push({
|
|
752
|
+
type: SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE,
|
|
753
|
+
encode: (w) => w.writeVarInt(params.max_auth_token_cache_size)
|
|
754
|
+
});
|
|
806
755
|
}
|
|
807
756
|
if (params.authority !== void 0) {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
757
|
+
entries.push({
|
|
758
|
+
type: SETUP_PARAM_AUTHORITY,
|
|
759
|
+
encode: (w) => {
|
|
760
|
+
const encoded = textEncoder.encode(params.authority);
|
|
761
|
+
w.writeVarInt(encoded.byteLength);
|
|
762
|
+
w.writeBytes(encoded);
|
|
763
|
+
}
|
|
764
|
+
});
|
|
812
765
|
}
|
|
813
766
|
if (params.moqt_implementation !== void 0) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
767
|
+
entries.push({
|
|
768
|
+
type: SETUP_PARAM_MOQT_IMPLEMENTATION,
|
|
769
|
+
encode: (w) => {
|
|
770
|
+
const encoded = textEncoder.encode(params.moqt_implementation);
|
|
771
|
+
w.writeVarInt(encoded.byteLength);
|
|
772
|
+
w.writeBytes(encoded);
|
|
773
|
+
}
|
|
774
|
+
});
|
|
818
775
|
}
|
|
819
776
|
if (params.unknown) {
|
|
820
777
|
for (const u of params.unknown) {
|
|
821
778
|
const id = BigInt(u.id);
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
779
|
+
entries.push({
|
|
780
|
+
type: id,
|
|
781
|
+
encode: (w) => {
|
|
782
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
783
|
+
if (id % 2n === 0n) {
|
|
784
|
+
w.writeVarInt(new (0, _chunk5IMHJIAZcjs.BufferReader)(raw).readVarInt());
|
|
785
|
+
} else {
|
|
786
|
+
w.writeVarInt(raw.byteLength);
|
|
787
|
+
w.writeBytes(raw);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
});
|
|
833
791
|
}
|
|
834
792
|
}
|
|
793
|
+
entries.sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
|
|
794
|
+
writer.writeVarInt(entries.length);
|
|
795
|
+
let prevType = 0n;
|
|
796
|
+
for (const entry of entries) {
|
|
797
|
+
writer.writeVarInt(entry.type - prevType);
|
|
798
|
+
entry.encode(writer);
|
|
799
|
+
prevType = entry.type;
|
|
800
|
+
}
|
|
835
801
|
}
|
|
836
802
|
function decodeSetupParams(reader) {
|
|
837
803
|
const count = Number(reader.readVarInt());
|
|
838
804
|
const result = {};
|
|
839
805
|
const unknown = [];
|
|
806
|
+
let prevType = 0n;
|
|
840
807
|
for (let i = 0; i < count; i++) {
|
|
841
|
-
const
|
|
808
|
+
const delta = reader.readVarInt();
|
|
809
|
+
const paramType = prevType + delta;
|
|
810
|
+
prevType = paramType;
|
|
842
811
|
if (paramType % 2n === 0n) {
|
|
843
812
|
const value = reader.readVarInt();
|
|
844
813
|
if (paramType === SETUP_PARAM_MAX_REQUEST_ID) {
|
|
@@ -846,13 +815,13 @@ function decodeSetupParams(reader) {
|
|
|
846
815
|
} else if (paramType === SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE) {
|
|
847
816
|
result.max_auth_token_cache_size = value;
|
|
848
817
|
} else {
|
|
849
|
-
const tmpWriter = new (0,
|
|
818
|
+
const tmpWriter = new (0, _chunk5IMHJIAZcjs.BufferWriter)(16);
|
|
850
819
|
tmpWriter.writeVarInt(value);
|
|
851
820
|
const raw = tmpWriter.finish();
|
|
852
821
|
unknown.push({
|
|
853
822
|
id: `0x${paramType.toString(16)}`,
|
|
854
823
|
length: raw.byteLength,
|
|
855
|
-
raw_hex:
|
|
824
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, raw)
|
|
856
825
|
});
|
|
857
826
|
}
|
|
858
827
|
} else {
|
|
@@ -861,10 +830,9 @@ function decodeSetupParams(reader) {
|
|
|
861
830
|
if (paramType === SETUP_PARAM_PATH) {
|
|
862
831
|
result.path = textDecoder.decode(bytes);
|
|
863
832
|
} else if (paramType === SETUP_PARAM_AUTHORIZATION_TOKEN) {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
];
|
|
833
|
+
const token = decodeAuthorizationToken(new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes));
|
|
834
|
+
noteAuthTokenValue(reader.offset - length, length, token.token_value);
|
|
835
|
+
result.authorization_token = [..._nullishCoalesce(result.authorization_token, () => ( [])), token];
|
|
868
836
|
} else if (paramType === SETUP_PARAM_AUTHORITY) {
|
|
869
837
|
result.authority = textDecoder.decode(bytes);
|
|
870
838
|
} else if (paramType === SETUP_PARAM_MOQT_IMPLEMENTATION) {
|
|
@@ -873,7 +841,7 @@ function decodeSetupParams(reader) {
|
|
|
873
841
|
unknown.push({
|
|
874
842
|
id: `0x${paramType.toString(16)}`,
|
|
875
843
|
length,
|
|
876
|
-
raw_hex:
|
|
844
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, bytes)
|
|
877
845
|
});
|
|
878
846
|
}
|
|
879
847
|
}
|
|
@@ -941,12 +909,12 @@ function encodeTrackExtensions(ext, writer) {
|
|
|
941
909
|
const id = BigInt(u.id);
|
|
942
910
|
writer.writeVarInt(id);
|
|
943
911
|
if (id % 2n === 0n) {
|
|
944
|
-
const raw =
|
|
945
|
-
const tmpReader = new (0,
|
|
912
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
913
|
+
const tmpReader = new (0, _chunk5IMHJIAZcjs.BufferReader)(raw);
|
|
946
914
|
const value = tmpReader.readVarInt();
|
|
947
915
|
writer.writeVarInt(value);
|
|
948
916
|
} else {
|
|
949
|
-
const raw =
|
|
917
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
950
918
|
writer.writeVarInt(raw.byteLength);
|
|
951
919
|
writer.writeBytes(raw);
|
|
952
920
|
}
|
|
@@ -966,13 +934,13 @@ function decodeTrackExtensions(reader) {
|
|
|
966
934
|
result.default_publisher_priority = reader.readVarInt();
|
|
967
935
|
} else if (extType % 2n === 0n) {
|
|
968
936
|
const value = reader.readVarInt();
|
|
969
|
-
const tmpWriter = new (0,
|
|
937
|
+
const tmpWriter = new (0, _chunk5IMHJIAZcjs.BufferWriter)(16);
|
|
970
938
|
tmpWriter.writeVarInt(value);
|
|
971
939
|
const raw = tmpWriter.finish();
|
|
972
940
|
unknown.push({
|
|
973
941
|
id: `0x${extType.toString(16)}`,
|
|
974
942
|
length: raw.byteLength,
|
|
975
|
-
raw_hex:
|
|
943
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, raw)
|
|
976
944
|
});
|
|
977
945
|
} else {
|
|
978
946
|
const length = Number(reader.readVarInt());
|
|
@@ -980,7 +948,7 @@ function decodeTrackExtensions(reader) {
|
|
|
980
948
|
unknown.push({
|
|
981
949
|
id: `0x${extType.toString(16)}`,
|
|
982
950
|
length,
|
|
983
|
-
raw_hex:
|
|
951
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, bytes)
|
|
984
952
|
});
|
|
985
953
|
}
|
|
986
954
|
}
|
|
@@ -1001,7 +969,7 @@ function encodeParams(params, writer) {
|
|
|
1001
969
|
entries.push({
|
|
1002
970
|
type: PARAM_AUTHORIZATION_TOKEN,
|
|
1003
971
|
encode: (w) => {
|
|
1004
|
-
const tmpW = new (0,
|
|
972
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(64);
|
|
1005
973
|
encodeAuthorizationToken(token, tmpW);
|
|
1006
974
|
const raw = tmpW.finish();
|
|
1007
975
|
w.writeVarInt(raw.byteLength);
|
|
@@ -1026,7 +994,7 @@ function encodeParams(params, writer) {
|
|
|
1026
994
|
// replaced that with "the encoding is specified by each parameter
|
|
1027
995
|
// definition", which is where the same field loses its length.
|
|
1028
996
|
encode: (w) => {
|
|
1029
|
-
const tmpW = new (0,
|
|
997
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(16);
|
|
1030
998
|
tmpW.writeVarInt(params.largest_object.group);
|
|
1031
999
|
tmpW.writeVarInt(params.largest_object.object);
|
|
1032
1000
|
const raw = tmpW.finish();
|
|
@@ -1054,7 +1022,7 @@ function encodeParams(params, writer) {
|
|
|
1054
1022
|
entries.push({
|
|
1055
1023
|
type: PARAM_SUBSCRIPTION_FILTER,
|
|
1056
1024
|
encode: (w) => {
|
|
1057
|
-
const tmpW = new (0,
|
|
1025
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(32);
|
|
1058
1026
|
const f = params.subscription_filter;
|
|
1059
1027
|
tmpW.writeVarInt(f.filter_type);
|
|
1060
1028
|
if (f.filter_type === 3n || f.filter_type === 4n) {
|
|
@@ -1091,9 +1059,9 @@ function encodeParams(params, writer) {
|
|
|
1091
1059
|
entries.push({
|
|
1092
1060
|
type: id,
|
|
1093
1061
|
encode: (w) => {
|
|
1094
|
-
const raw =
|
|
1062
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
1095
1063
|
if (id % 2n === 0n) {
|
|
1096
|
-
w.writeVarInt(new (0,
|
|
1064
|
+
w.writeVarInt(new (0, _chunk5IMHJIAZcjs.BufferReader)(raw).readVarInt());
|
|
1097
1065
|
} else {
|
|
1098
1066
|
w.writeVarInt(raw.byteLength);
|
|
1099
1067
|
w.writeBytes(raw);
|
|
@@ -1124,10 +1092,9 @@ function decodeParams(reader) {
|
|
|
1124
1092
|
} else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
|
|
1125
1093
|
const length = Number(reader.readVarInt());
|
|
1126
1094
|
const tokenBytes = reader.readBytes(length);
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
];
|
|
1095
|
+
const token = decodeAuthorizationToken(new (0, _chunk5IMHJIAZcjs.BufferReader)(tokenBytes));
|
|
1096
|
+
noteAuthTokenValue(reader.offset - length, length, token.token_value);
|
|
1097
|
+
result.authorization_token = [..._nullishCoalesce(result.authorization_token, () => ( [])), token];
|
|
1131
1098
|
} else if (paramType === PARAM_MAX_CACHE_DURATION) {
|
|
1132
1099
|
result.max_cache_duration = reader.readVarInt();
|
|
1133
1100
|
} else if (paramType === PARAM_EXPIRES) {
|
|
@@ -1168,7 +1135,7 @@ function decodeParams(reader) {
|
|
|
1168
1135
|
if (consumed < length) reader.readBytes(length - consumed);
|
|
1169
1136
|
result.subscription_filter = filter;
|
|
1170
1137
|
} else {
|
|
1171
|
-
throw new (0,
|
|
1138
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
1172
1139
|
"INVALID_PARAMETER",
|
|
1173
1140
|
`Unknown Message Parameter type 0x${paramType.toString(16)}`,
|
|
1174
1141
|
reader.offset
|
|
@@ -1429,7 +1396,7 @@ function decodeFetchPayload(r) {
|
|
|
1429
1396
|
const fetch_type = r.readVarInt();
|
|
1430
1397
|
const ft = Number(fetch_type);
|
|
1431
1398
|
if (ft < 1 || ft > 3) {
|
|
1432
|
-
throw new (0,
|
|
1399
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${ft}`, r.offset);
|
|
1433
1400
|
}
|
|
1434
1401
|
let standalone;
|
|
1435
1402
|
let joining;
|
|
@@ -1560,13 +1527,13 @@ function encodeMessage(message) {
|
|
|
1560
1527
|
if (typeId === void 0) {
|
|
1561
1528
|
throw new Error(`Unknown message type: ${message.type}`);
|
|
1562
1529
|
}
|
|
1563
|
-
const payloadWriter = new (0,
|
|
1530
|
+
const payloadWriter = new (0, _chunk5IMHJIAZcjs.BufferWriter)();
|
|
1564
1531
|
encodePayload(message, payloadWriter);
|
|
1565
1532
|
const payload = payloadWriter.finishView();
|
|
1566
1533
|
if (payload.byteLength > 65535) {
|
|
1567
1534
|
throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
|
|
1568
1535
|
}
|
|
1569
|
-
const writer = new (0,
|
|
1536
|
+
const writer = new (0, _chunk5IMHJIAZcjs.BufferWriter)(payload.byteLength + 16);
|
|
1570
1537
|
writer.writeVarInt(typeId);
|
|
1571
1538
|
writer.writeUint8(payload.byteLength >> 8 & 255);
|
|
1572
1539
|
writer.writeUint8(payload.byteLength & 255);
|
|
@@ -1631,18 +1598,18 @@ function encodePayload(msg, w) {
|
|
|
1631
1598
|
}
|
|
1632
1599
|
function decodeMessage(bytes) {
|
|
1633
1600
|
try {
|
|
1634
|
-
const reader = new (0,
|
|
1601
|
+
const reader = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
1635
1602
|
const typeId = reader.readVarInt();
|
|
1636
1603
|
const lenHi = reader.readUint8();
|
|
1637
1604
|
const lenLo = reader.readUint8();
|
|
1638
1605
|
const payloadLength = lenHi << 8 | lenLo;
|
|
1639
1606
|
const payloadBytes = reader.readBytes(payloadLength);
|
|
1640
|
-
const payloadReader = new (0,
|
|
1607
|
+
const payloadReader = new (0, _chunk5IMHJIAZcjs.BufferReader)(payloadBytes);
|
|
1641
1608
|
const decoder = payloadDecoders.get(typeId);
|
|
1642
1609
|
if (!decoder) {
|
|
1643
1610
|
return {
|
|
1644
1611
|
ok: false,
|
|
1645
|
-
error: new (0,
|
|
1612
|
+
error: new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
1646
1613
|
"UNKNOWN_MESSAGE_TYPE",
|
|
1647
1614
|
`Unknown message type ID: 0x${typeId.toString(16)}`,
|
|
1648
1615
|
0
|
|
@@ -1652,7 +1619,7 @@ function decodeMessage(bytes) {
|
|
|
1652
1619
|
const message = decoder(payloadReader);
|
|
1653
1620
|
return { ok: true, value: message, bytesRead: reader.offset };
|
|
1654
1621
|
} catch (e) {
|
|
1655
|
-
if (e instanceof
|
|
1622
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError) {
|
|
1656
1623
|
return { ok: false, error: e };
|
|
1657
1624
|
}
|
|
1658
1625
|
throw e;
|
|
@@ -1687,7 +1654,7 @@ function createStreamDecoder() {
|
|
|
1687
1654
|
flush(controller) {
|
|
1688
1655
|
if (offset < buffer.length) {
|
|
1689
1656
|
controller.error(
|
|
1690
|
-
new (0,
|
|
1657
|
+
new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete message data", 0)
|
|
1691
1658
|
);
|
|
1692
1659
|
}
|
|
1693
1660
|
}
|
|
@@ -1711,6 +1678,24 @@ function createDraft16Codec() {
|
|
|
1711
1678
|
createDataStreamDecoder
|
|
1712
1679
|
};
|
|
1713
1680
|
}
|
|
1681
|
+
function noteAuthTokenValue(valueStart, valueLength, value) {
|
|
1682
|
+
if (value === void 0 || value.byteLength === 0) return;
|
|
1683
|
+
_chunk5IMHJIAZcjs.recordAuthValueSpan.call(void 0, valueStart + valueLength - value.byteLength, value.byteLength);
|
|
1684
|
+
}
|
|
1685
|
+
function redactAuthTokens(bytes) {
|
|
1686
|
+
let payloadStart;
|
|
1687
|
+
try {
|
|
1688
|
+
const probe = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
1689
|
+
probe.readVarInt();
|
|
1690
|
+
probe.readUint8();
|
|
1691
|
+
probe.readUint8();
|
|
1692
|
+
payloadStart = probe.offset;
|
|
1693
|
+
} catch (e4) {
|
|
1694
|
+
return { bytes, redacted: 0, incomplete: false, decoded: false };
|
|
1695
|
+
}
|
|
1696
|
+
return _chunk5IMHJIAZcjs.redactWith.call(void 0, bytes, payloadStart, () => decodeMessage(bytes).ok);
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1714
1699
|
|
|
1715
1700
|
|
|
1716
1701
|
|
|
@@ -1758,4 +1743,4 @@ function createDraft16Codec() {
|
|
|
1758
1743
|
|
|
1759
1744
|
|
|
1760
1745
|
|
|
1761
|
-
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_NAMESPACE_DONE = MSG_PUBLISH_NAMESPACE_DONE; exports.MSG_UNSUBSCRIBE = MSG_UNSUBSCRIBE; exports.MSG_PUBLISH_DONE = MSG_PUBLISH_DONE; exports.MSG_PUBLISH_NAMESPACE_CANCEL = MSG_PUBLISH_NAMESPACE_CANCEL; exports.MSG_TRACK_STATUS = MSG_TRACK_STATUS; exports.MSG_NAMESPACE_DONE = MSG_NAMESPACE_DONE; exports.MSG_GOAWAY = MSG_GOAWAY; exports.MSG_SUBSCRIBE_NAMESPACE = MSG_SUBSCRIBE_NAMESPACE; exports.MSG_MAX_REQUEST_ID = MSG_MAX_REQUEST_ID; exports.MSG_FETCH = MSG_FETCH; exports.MSG_FETCH_CANCEL = MSG_FETCH_CANCEL; exports.MSG_FETCH_OK = MSG_FETCH_OK; exports.MSG_REQUESTS_BLOCKED = MSG_REQUESTS_BLOCKED; exports.MSG_PUBLISH = MSG_PUBLISH; exports.MSG_PUBLISH_OK = MSG_PUBLISH_OK; exports.MSG_CLIENT_SETUP = MSG_CLIENT_SETUP; exports.MSG_SERVER_SETUP = MSG_SERVER_SETUP; exports.SETUP_PARAM_PATH = SETUP_PARAM_PATH; exports.SETUP_PARAM_MAX_REQUEST_ID = SETUP_PARAM_MAX_REQUEST_ID; exports.SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE = SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE; exports.SETUP_PARAM_AUTHORITY = SETUP_PARAM_AUTHORITY; exports.SETUP_PARAM_MOQT_IMPLEMENTATION = SETUP_PARAM_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.createDraft16Codec = createDraft16Codec;
|
|
1746
|
+
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_NAMESPACE_DONE = MSG_PUBLISH_NAMESPACE_DONE; exports.MSG_UNSUBSCRIBE = MSG_UNSUBSCRIBE; exports.MSG_PUBLISH_DONE = MSG_PUBLISH_DONE; exports.MSG_PUBLISH_NAMESPACE_CANCEL = MSG_PUBLISH_NAMESPACE_CANCEL; exports.MSG_TRACK_STATUS = MSG_TRACK_STATUS; exports.MSG_NAMESPACE_DONE = MSG_NAMESPACE_DONE; exports.MSG_GOAWAY = MSG_GOAWAY; exports.MSG_SUBSCRIBE_NAMESPACE = MSG_SUBSCRIBE_NAMESPACE; exports.MSG_MAX_REQUEST_ID = MSG_MAX_REQUEST_ID; exports.MSG_FETCH = MSG_FETCH; exports.MSG_FETCH_CANCEL = MSG_FETCH_CANCEL; exports.MSG_FETCH_OK = MSG_FETCH_OK; exports.MSG_REQUESTS_BLOCKED = MSG_REQUESTS_BLOCKED; exports.MSG_PUBLISH = MSG_PUBLISH; exports.MSG_PUBLISH_OK = MSG_PUBLISH_OK; exports.MSG_CLIENT_SETUP = MSG_CLIENT_SETUP; exports.MSG_SERVER_SETUP = MSG_SERVER_SETUP; exports.SETUP_PARAM_PATH = SETUP_PARAM_PATH; exports.SETUP_PARAM_MAX_REQUEST_ID = SETUP_PARAM_MAX_REQUEST_ID; exports.SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE = SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE; exports.SETUP_PARAM_AUTHORITY = SETUP_PARAM_AUTHORITY; exports.SETUP_PARAM_MOQT_IMPLEMENTATION = SETUP_PARAM_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.createDraft16Codec = createDraft16Codec; exports.redactAuthTokens = redactAuthTokens;
|