@moqtap/codec 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +173 -0
- package/dist/auth-redaction-DsdLq4Qs.d.cts +102 -0
- package/dist/auth-redaction-DsdLq4Qs.d.ts +102 -0
- package/dist/{chunk-PU2KV7VP.cjs → chunk-27K5BUAG.cjs} +485 -515
- package/dist/{chunk-BV6MITLO.js → chunk-3RNQMGKA.js} +365 -390
- package/dist/{chunk-2XH6PHXR.js → chunk-5AWIXOLB.js} +442 -467
- package/dist/{chunk-4XLYCT5Q.cjs → chunk-5IMHJIAZ.cjs} +52 -2
- package/dist/{chunk-TVSFDQYE.cjs → chunk-5JGZCKJO.cjs} +513 -531
- package/dist/{chunk-IADVBKEJ.cjs → chunk-73K4OSAN.cjs} +407 -432
- package/dist/{chunk-N2V7Z37J.js → chunk-7VQKRGRD.js} +19 -3
- package/dist/{chunk-UZO5Z2XT.cjs → chunk-A3UCQOIB.cjs} +490 -515
- package/dist/{chunk-JKMYAUGY.js → chunk-A7PDMVXM.js} +35 -11
- package/dist/{chunk-VZHL2U2N.cjs → chunk-A7VQO6YC.cjs} +54 -38
- package/dist/{chunk-KCH4BQXK.cjs → chunk-ACQHZLRZ.cjs} +73 -47
- package/dist/{chunk-H6DTAIWM.js → chunk-BBICOMW6.js} +47 -19
- package/dist/{chunk-MAXEHYVB.cjs → chunk-BNIUVOCJ.cjs} +554 -612
- package/dist/{chunk-QGIHC6BA.cjs → chunk-CNC6ANS4.cjs} +70 -46
- package/dist/{chunk-NH4L6NIY.js → chunk-FDLQSWHK.js} +437 -467
- package/dist/{chunk-IJAF6PAY.js → chunk-FFNOE4UR.js} +19 -3
- package/dist/{chunk-CZNW3R5E.cjs → chunk-GMENT63T.cjs} +54 -38
- package/dist/{chunk-7ENEWAMZ.cjs → chunk-HM7BLRVP.cjs} +305 -305
- package/dist/{chunk-XHAP2YST.js → chunk-HZONHFNO.js} +19 -3
- package/dist/{chunk-EVCPBFSR.cjs → chunk-ILYABWDK.cjs} +83 -55
- package/dist/{chunk-IDV2JYJ6.cjs → chunk-KRSFTZVO.cjs} +56 -40
- package/dist/{chunk-RIIA4ALQ.cjs → chunk-KSPH6KMH.cjs} +54 -38
- package/dist/{chunk-UA5XFP4O.cjs → chunk-KTY4LAUV.cjs} +485 -494
- package/dist/{chunk-RZTLQAKF.js → chunk-OJNLJT5D.js} +0 -1
- package/dist/{chunk-YJGOD3Y4.js → chunk-PJK2ZS3I.js} +492 -550
- package/dist/{chunk-TMXRYOBS.js → chunk-PSMZKHOC.js} +444 -453
- package/dist/{chunk-7RE6KSIY.cjs → chunk-Q5JQGHWY.cjs} +0 -1
- package/dist/{chunk-23KRITJ6.js → chunk-SQTUQY5E.js} +37 -11
- package/dist/{chunk-XQGEOFGE.js → chunk-WCRLAKDW.js} +253 -253
- package/dist/{chunk-KYVTM5VI.js → chunk-WL2YUEXH.js} +19 -3
- package/dist/{chunk-Q7NSUXXB.js → chunk-YCNIVZS7.js} +464 -482
- package/dist/{chunk-KLPWJU6W.js → chunk-YRZQVNZO.js} +50 -0
- package/dist/{codec-Bym-K2q2.d.cts → codec-76xzrLTL.d.cts} +21 -2
- package/dist/{codec-BKsVu3Fr.d.ts → codec-8p40WdLg.d.ts} +21 -2
- package/dist/{codec-Dl_QIXMz.d.ts → codec-BN2Bu0KI.d.ts} +20 -1
- package/dist/{codec-D4RvFQmu.d.ts → codec-Bb6GKTrv.d.ts} +21 -2
- package/dist/{codec-DAyiF5sq.d.cts → codec-BgpfHoAd.d.cts} +21 -2
- package/dist/{codec-CA6nbbEk.d.ts → codec-BkheTXO7.d.ts} +21 -2
- package/dist/{codec-DchsPfr3.d.cts → codec-BwVDkokh.d.cts} +21 -2
- package/dist/{codec-CgZdadPt.d.cts → codec-C5s1eBJX.d.cts} +21 -2
- package/dist/codec-CM5yd6n3.d.ts +38 -0
- package/dist/{codec-DJmqoIsp.d.cts → codec-Cb8HC3XV.d.cts} +21 -2
- package/dist/codec-Clu_skx8.d.cts +38 -0
- package/dist/{codec-DzkdW4kO.d.cts → codec-CpOpemR8.d.cts} +20 -1
- package/dist/{codec-CXCjya_G.d.cts → codec-Cshdl9Tt.d.cts} +20 -1
- package/dist/{codec-CSBFdPgP.d.cts → codec-DELe00w_.d.cts} +21 -2
- package/dist/{codec-C_xxsbKy.d.cts → codec-DHzKAUCa.d.cts} +21 -2
- package/dist/{codec--CVeqGQv.d.ts → codec-DdVBtvx7.d.ts} +20 -1
- package/dist/{codec-CviAa4lp.d.ts → codec-DlxGuYMv.d.ts} +21 -2
- package/dist/{codec-BNy5syCU.d.ts → codec-DxtgPxJS.d.ts} +20 -1
- package/dist/{codec-CtvFK4aV.d.cts → codec-GAY4lybi.d.cts} +21 -2
- package/dist/{codec-Cfo_z5ET.d.cts → codec-I8u2pfS4.d.cts} +20 -1
- package/dist/{codec-vddqy0KY.d.cts → codec-XLrnreeu.d.cts} +21 -2
- package/dist/{codec-O-1Js7h4.d.ts → codec-c0YEwwWn.d.ts} +21 -2
- package/dist/{codec-Cl73EfRW.d.ts → codec-ejDu-va6.d.ts} +21 -2
- package/dist/{codec-C006F75E.d.ts → codec-kaBUzdpV.d.ts} +21 -2
- package/dist/{codec-C5evFHL-.d.ts → codec-mVYqkIUF.d.ts} +21 -2
- package/dist/{codec-BMwgZIgG.d.ts → codec-qSbO5nOa.d.ts} +21 -2
- package/dist/{codec-BQa6Qsav.d.ts → codec-yYKGOipj.d.ts} +21 -2
- package/dist/{codec-DzLvG8Wb.d.cts → codec-zfzg9uiy.d.cts} +21 -2
- package/dist/draft07.cjs +48 -4
- package/dist/draft07.d.cts +42 -2
- package/dist/draft07.d.ts +42 -2
- package/dist/draft07.js +49 -5
- package/dist/draft08.cjs +76 -3
- package/dist/draft08.d.cts +70 -2
- package/dist/draft08.d.ts +70 -2
- package/dist/draft08.js +77 -4
- package/dist/draft09.cjs +76 -3
- package/dist/draft09.d.cts +70 -2
- package/dist/draft09.d.ts +70 -2
- package/dist/draft09.js +77 -4
- package/dist/draft10.cjs +76 -3
- package/dist/draft10.d.cts +70 -2
- package/dist/draft10.d.ts +70 -2
- package/dist/draft10.js +77 -4
- package/dist/draft11-session.d.cts +1 -1
- package/dist/draft11-session.d.ts +1 -1
- package/dist/draft11.cjs +104 -3
- package/dist/draft11.d.cts +100 -4
- package/dist/draft11.d.ts +100 -4
- package/dist/draft11.js +105 -4
- package/dist/draft12-session.d.cts +1 -1
- package/dist/draft12-session.d.ts +1 -1
- package/dist/draft12.cjs +113 -3
- package/dist/draft12.d.cts +109 -4
- package/dist/draft12.d.ts +109 -4
- package/dist/draft12.js +114 -4
- package/dist/draft13-session.d.cts +1 -1
- package/dist/draft13-session.d.ts +1 -1
- package/dist/draft13.cjs +105 -3
- package/dist/draft13.d.cts +101 -4
- package/dist/draft13.d.ts +101 -4
- package/dist/draft13.js +106 -4
- package/dist/draft14-session.d.cts +1 -1
- package/dist/draft14-session.d.ts +1 -1
- package/dist/draft14.cjs +107 -3
- package/dist/draft14.d.cts +103 -30
- package/dist/draft14.d.ts +103 -30
- package/dist/draft14.js +108 -4
- package/dist/draft15-session.d.cts +1 -1
- package/dist/draft15-session.d.ts +1 -1
- package/dist/draft15.cjs +69 -3
- package/dist/draft15.d.cts +65 -22
- package/dist/draft15.d.ts +65 -22
- package/dist/draft15.js +70 -4
- package/dist/draft16-session.cjs +2 -2
- package/dist/draft16-session.d.cts +1 -1
- package/dist/draft16-session.d.ts +1 -1
- package/dist/draft16-session.js +1 -1
- package/dist/draft16.cjs +76 -8
- package/dist/draft16.d.cts +67 -13
- package/dist/draft16.d.ts +67 -13
- package/dist/draft16.js +73 -5
- package/dist/draft17-session.d.cts +1 -1
- package/dist/draft17-session.d.ts +1 -1
- package/dist/draft17.cjs +77 -3
- package/dist/draft17.d.cts +73 -4
- package/dist/draft17.d.ts +73 -4
- package/dist/draft17.js +78 -4
- package/dist/draft18-session.d.cts +1 -1
- package/dist/draft18-session.d.ts +1 -1
- package/dist/draft18.cjs +8 -3
- package/dist/draft18.d.cts +4 -3
- package/dist/draft18.d.ts +4 -3
- package/dist/draft18.js +9 -4
- package/dist/draft19-session.d.cts +1 -1
- package/dist/draft19-session.d.ts +1 -1
- package/dist/draft19.cjs +11 -4
- package/dist/draft19.d.cts +4 -3
- package/dist/draft19.d.ts +4 -3
- package/dist/draft19.js +12 -5
- package/dist/draft20-session.d.cts +1 -1
- package/dist/draft20-session.d.ts +1 -1
- package/dist/draft20.cjs +8 -3
- package/dist/draft20.d.cts +4 -3
- package/dist/draft20.d.ts +4 -3
- package/dist/draft20.js +9 -4
- package/dist/index.cjs +30 -30
- package/dist/index.d.cts +25 -24
- package/dist/index.d.ts +25 -24
- package/dist/index.js +15 -15
- package/dist/session.cjs +2 -2
- package/dist/session.d.cts +10 -10
- package/dist/session.d.ts +10 -10
- package/dist/session.js +1 -1
- package/dist/{types-zHgCS6o5.d.cts → types-Btp416jt.d.cts} +15 -7
- package/dist/{types-zHgCS6o5.d.ts → types-Btp416jt.d.ts} +15 -7
- package/dist/{types-Cm9fjeYC.d.cts → types-BxTL1NXw.d.cts} +9 -2
- package/dist/{types-Cm9fjeYC.d.ts → types-BxTL1NXw.d.ts} +9 -2
- package/dist/{types-Bio-91Rt.d.cts → types-CI_SX4Xe.d.cts} +2 -2
- package/dist/{types-Bio-91Rt.d.ts → types-CI_SX4Xe.d.ts} +2 -2
- package/dist/{types-HI_bbXka.d.cts → types-CmqT0jUf.d.cts} +1 -1
- package/dist/{types-HI_bbXka.d.ts → types-CmqT0jUf.d.ts} +1 -1
- package/dist/{types-CPaYBsMG.d.cts → types-CuibHYcf.d.cts} +9 -2
- package/dist/{types-CPaYBsMG.d.ts → types-CuibHYcf.d.ts} +9 -2
- package/dist/{types-CWCQwuvy.d.cts → types-CwN7AEoL.d.cts} +24 -12
- package/dist/{types-CWCQwuvy.d.ts → types-CwN7AEoL.d.ts} +24 -12
- package/dist/{types-Ck45Ex5S.d.cts → types-D0kTgUuL.d.cts} +1 -1
- package/dist/{types-Ck45Ex5S.d.ts → types-D0kTgUuL.d.ts} +1 -1
- package/dist/{types-D9eiB_9A.d.cts → types-DAnalt5K.d.cts} +9 -2
- package/dist/{types-D9eiB_9A.d.ts → types-DAnalt5K.d.ts} +9 -2
- package/dist/{types-CXlSn0I9.d.cts → types-DjxexghA.d.cts} +2 -2
- package/dist/{types-CXlSn0I9.d.ts → types-DjxexghA.d.ts} +2 -2
- package/dist/{types-Cqp10JtB.d.cts → types-DxXNP32l.d.cts} +10 -2
- package/dist/{types-Cqp10JtB.d.ts → types-DxXNP32l.d.ts} +10 -2
- package/package.json +3 -3
- package/src/core/auth-redaction.ts +192 -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 +71 -8
- package/src/drafts/draft11/error-codes.ts +106 -0
- package/src/drafts/draft11/index.ts +23 -0
- package/src/drafts/draft11/types.ts +1 -1
- package/src/drafts/draft12/codec.ts +83 -16
- package/src/drafts/draft12/error-codes.ts +116 -0
- package/src/drafts/draft12/index.ts +25 -0
- package/src/drafts/draft12/types.ts +2 -2
- package/src/drafts/draft13/codec.ts +75 -11
- package/src/drafts/draft13/error-codes.ts +107 -0
- package/src/drafts/draft13/index.ts +23 -0
- package/src/drafts/draft13/types.ts +3 -3
- package/src/drafts/draft14/codec.ts +79 -12
- 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/draft14/types.ts +1 -1
- package/src/drafts/draft15/codec.ts +71 -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 +9 -2
- package/src/drafts/draft16/codec.ts +149 -49
- 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 +24 -10
- package/src/drafts/draft17/codec.ts +77 -10
- package/src/drafts/draft17/data-streams.ts +567 -488
- package/src/drafts/draft17/index.ts +15 -0
- package/src/drafts/draft17/types.ts +9 -2
- package/src/drafts/draft18/codec.ts +70 -7
- package/src/drafts/draft18/data-streams.ts +570 -482
- package/src/drafts/draft18/index.ts +3 -0
- package/src/drafts/draft18/types.ts +18 -10
- package/src/drafts/draft19/codec.ts +95 -23
- 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 +32 -18
- package/src/drafts/draft20/codec.ts +115 -36
- package/src/drafts/draft20/data-streams.ts +610 -563
- package/src/drafts/draft20/index.ts +3 -0
- package/src/drafts/draft20/types.ts +31 -13
- package/dist/codec-BJ7BHuiZ.d.ts +0 -18
- package/dist/codec-C6Mx4bwz.d.cts +0 -18
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
BufferWriter,
|
|
4
4
|
DecodeError,
|
|
5
5
|
bytesToHex,
|
|
6
|
-
hexToBytes
|
|
7
|
-
|
|
6
|
+
hexToBytes,
|
|
7
|
+
recordAuthValueSpan,
|
|
8
|
+
redactWith
|
|
9
|
+
} from "./chunk-YRZQVNZO.js";
|
|
8
10
|
|
|
9
11
|
// src/drafts/draft15/messages.ts
|
|
10
12
|
var MSG_SUBSCRIBE_UPDATE = 0x02n;
|
|
@@ -153,87 +155,99 @@ function encodeFetchStream(stream) {
|
|
|
153
155
|
}
|
|
154
156
|
return w.finish();
|
|
155
157
|
}
|
|
158
|
+
function readSubgroupHeader(r) {
|
|
159
|
+
const streamType = Number(r.readVarInt());
|
|
160
|
+
if (!(streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63) || (streamType & 6) === 6) {
|
|
161
|
+
throw new DecodeError(
|
|
162
|
+
"CONSTRAINT_VIOLATION",
|
|
163
|
+
`Expected subgroup stream type 0x10-0x1F/0x30-0x3F, got 0x${streamType.toString(16)}`,
|
|
164
|
+
0
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
const extensionsPresent = (streamType & 1) !== 0;
|
|
168
|
+
const endOfGroup = (streamType & 8) !== 0;
|
|
169
|
+
const hasSubgroupField = (streamType & 4) !== 0;
|
|
170
|
+
const hasPriority = streamType < 48;
|
|
171
|
+
const subgroupIsFirstObjId = false;
|
|
172
|
+
const trackAlias = r.readVarInt();
|
|
173
|
+
const groupId = r.readVarInt();
|
|
174
|
+
let subgroupId = 0n;
|
|
175
|
+
if (hasSubgroupField) {
|
|
176
|
+
subgroupId = r.readVarInt();
|
|
177
|
+
}
|
|
178
|
+
let publisherPriority = 128;
|
|
179
|
+
if (hasPriority) {
|
|
180
|
+
publisherPriority = r.readUint8();
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
streamType,
|
|
184
|
+
extensionsPresent,
|
|
185
|
+
subgroupIsFirstObjId,
|
|
186
|
+
endOfGroup,
|
|
187
|
+
trackAlias,
|
|
188
|
+
groupId,
|
|
189
|
+
subgroupId,
|
|
190
|
+
publisherPriority
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function readSubgroupObject(r, extensionsPresent, isFirst, prevObjectId, base) {
|
|
194
|
+
const byteOffset = base + r.offset;
|
|
195
|
+
const delta = r.readVarInt();
|
|
196
|
+
const objectId = isFirst ? delta : prevObjectId + 1n + delta;
|
|
197
|
+
let extensionData = new Uint8Array(0);
|
|
198
|
+
if (extensionsPresent) {
|
|
199
|
+
const extLen = Number(r.readVarInt());
|
|
200
|
+
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
201
|
+
}
|
|
202
|
+
const payloadLength = Number(r.readVarInt());
|
|
203
|
+
let payload;
|
|
204
|
+
let status;
|
|
205
|
+
let payloadByteOffset;
|
|
206
|
+
if (payloadLength === 0) {
|
|
207
|
+
status = r.readVarInt();
|
|
208
|
+
payloadByteOffset = base + r.offset;
|
|
209
|
+
payload = new Uint8Array(0);
|
|
210
|
+
} else {
|
|
211
|
+
payloadByteOffset = base + r.offset;
|
|
212
|
+
payload = r.readBytesView(payloadLength);
|
|
213
|
+
}
|
|
214
|
+
const obj = {
|
|
215
|
+
type: "object",
|
|
216
|
+
byteOffset,
|
|
217
|
+
payloadByteOffset,
|
|
218
|
+
objectId,
|
|
219
|
+
payloadLength,
|
|
220
|
+
payload,
|
|
221
|
+
extensionData
|
|
222
|
+
};
|
|
223
|
+
if (status !== void 0) obj.status = status;
|
|
224
|
+
return obj;
|
|
225
|
+
}
|
|
156
226
|
function decodeSubgroupStream(bytes) {
|
|
157
227
|
try {
|
|
158
228
|
const r = new BufferReader(bytes);
|
|
159
|
-
const
|
|
160
|
-
if (!(streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63) || (streamType & 6) === 6) {
|
|
161
|
-
return {
|
|
162
|
-
ok: false,
|
|
163
|
-
error: new DecodeError(
|
|
164
|
-
"CONSTRAINT_VIOLATION",
|
|
165
|
-
`Expected subgroup stream type 0x10-0x1F/0x30-0x3F, got 0x${streamType.toString(16)}`,
|
|
166
|
-
0
|
|
167
|
-
)
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
const extensionsPresent = (streamType & 1) !== 0;
|
|
171
|
-
const endOfGroup = (streamType & 8) !== 0;
|
|
172
|
-
const hasSubgroupField = (streamType & 4) !== 0;
|
|
173
|
-
const hasPriority = streamType < 48;
|
|
174
|
-
const trackAlias = r.readVarInt();
|
|
175
|
-
const groupId = r.readVarInt();
|
|
176
|
-
let subgroupId = 0n;
|
|
177
|
-
if (hasSubgroupField) {
|
|
178
|
-
subgroupId = r.readVarInt();
|
|
179
|
-
}
|
|
180
|
-
let publisherPriority = 128;
|
|
181
|
-
if (hasPriority) {
|
|
182
|
-
publisherPriority = r.readUint8();
|
|
183
|
-
}
|
|
229
|
+
const h = readSubgroupHeader(r);
|
|
184
230
|
const objects = [];
|
|
185
231
|
let prevObjectId = -1n;
|
|
186
|
-
let
|
|
232
|
+
let isFirst = true;
|
|
233
|
+
let subgroupId = h.subgroupId;
|
|
187
234
|
while (r.remaining > 0) {
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (firstObject) {
|
|
192
|
-
objectId = delta;
|
|
193
|
-
firstObject = false;
|
|
194
|
-
} else {
|
|
195
|
-
objectId = prevObjectId + 1n + delta;
|
|
196
|
-
}
|
|
197
|
-
let extensionData = new Uint8Array(0);
|
|
198
|
-
if (extensionsPresent) {
|
|
199
|
-
const extLen = Number(r.readVarInt());
|
|
200
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
201
|
-
}
|
|
202
|
-
const payloadLength = Number(r.readVarInt());
|
|
203
|
-
let payload;
|
|
204
|
-
let status;
|
|
205
|
-
let payloadByteOffset;
|
|
206
|
-
if (payloadLength === 0) {
|
|
207
|
-
status = r.readVarInt();
|
|
208
|
-
payloadByteOffset = r.offset;
|
|
209
|
-
payload = new Uint8Array(0);
|
|
210
|
-
} else {
|
|
211
|
-
payloadByteOffset = r.offset;
|
|
212
|
-
payload = r.readBytesView(payloadLength);
|
|
213
|
-
}
|
|
214
|
-
const obj = {
|
|
215
|
-
type: "object",
|
|
216
|
-
byteOffset,
|
|
217
|
-
payloadByteOffset,
|
|
218
|
-
objectId,
|
|
219
|
-
payloadLength,
|
|
220
|
-
extensionData,
|
|
221
|
-
payload
|
|
222
|
-
};
|
|
223
|
-
if (status !== void 0) obj.status = status;
|
|
235
|
+
const obj = readSubgroupObject(r, h.extensionsPresent, isFirst, prevObjectId, 0);
|
|
236
|
+
if (isFirst && h.subgroupIsFirstObjId) subgroupId = obj.objectId;
|
|
237
|
+
isFirst = false;
|
|
224
238
|
objects.push(obj);
|
|
225
|
-
prevObjectId = objectId;
|
|
239
|
+
prevObjectId = obj.objectId;
|
|
226
240
|
}
|
|
227
241
|
const result = {
|
|
228
242
|
type: "subgroup",
|
|
229
|
-
headerType: streamType,
|
|
230
|
-
trackAlias,
|
|
231
|
-
groupId,
|
|
243
|
+
headerType: h.streamType,
|
|
244
|
+
trackAlias: h.trackAlias,
|
|
245
|
+
groupId: h.groupId,
|
|
232
246
|
subgroupId,
|
|
233
|
-
publisherPriority,
|
|
234
|
-
objects
|
|
247
|
+
publisherPriority: h.publisherPriority,
|
|
248
|
+
objects,
|
|
249
|
+
...h.endOfGroup ? { endOfGroup: true } : {}
|
|
235
250
|
};
|
|
236
|
-
if (endOfGroup) result.endOfGroup = true;
|
|
237
251
|
return {
|
|
238
252
|
ok: true,
|
|
239
253
|
value: result,
|
|
@@ -298,6 +312,108 @@ function decodeDatagram(bytes) {
|
|
|
298
312
|
throw e;
|
|
299
313
|
}
|
|
300
314
|
}
|
|
315
|
+
function newFetchObjectState() {
|
|
316
|
+
return { prevGroupId: 0n, prevSubgroupId: 0n, prevObjectId: 0n, prevPriority: 128, first: true };
|
|
317
|
+
}
|
|
318
|
+
function readFetchObject(r, base, st) {
|
|
319
|
+
const byteOffset = base + r.offset;
|
|
320
|
+
const flags = r.readUint8();
|
|
321
|
+
const subgroupEncoding = flags & 3;
|
|
322
|
+
const objectIdPresent = (flags & 4) !== 0;
|
|
323
|
+
const groupIdPresent = (flags & 8) !== 0;
|
|
324
|
+
const priorityPresent = (flags & 16) !== 0;
|
|
325
|
+
const extensionsPresent = (flags & 32) !== 0;
|
|
326
|
+
if (flags & 192) {
|
|
327
|
+
throw new DecodeError(
|
|
328
|
+
"CONSTRAINT_VIOLATION",
|
|
329
|
+
"Reserved bits set in fetch object flags",
|
|
330
|
+
r.offset
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
let groupId = st.prevGroupId;
|
|
334
|
+
if (groupIdPresent) {
|
|
335
|
+
groupId = r.readVarInt();
|
|
336
|
+
} else if (st.first) {
|
|
337
|
+
throw new DecodeError(
|
|
338
|
+
"CONSTRAINT_VIOLATION",
|
|
339
|
+
"First fetch object must include groupId",
|
|
340
|
+
r.offset
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
let subgroupId;
|
|
344
|
+
if (subgroupEncoding === 0) {
|
|
345
|
+
subgroupId = 0n;
|
|
346
|
+
} else if (subgroupEncoding === 1) {
|
|
347
|
+
if (st.first) {
|
|
348
|
+
throw new DecodeError(
|
|
349
|
+
"CONSTRAINT_VIOLATION",
|
|
350
|
+
"First fetch object cannot reference prior subgroupId",
|
|
351
|
+
r.offset
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
subgroupId = st.prevSubgroupId;
|
|
355
|
+
} else if (subgroupEncoding === 2) {
|
|
356
|
+
if (st.first) {
|
|
357
|
+
throw new DecodeError(
|
|
358
|
+
"CONSTRAINT_VIOLATION",
|
|
359
|
+
"First fetch object cannot reference prior subgroupId",
|
|
360
|
+
r.offset
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
subgroupId = st.prevSubgroupId + 1n;
|
|
364
|
+
} else {
|
|
365
|
+
subgroupId = r.readVarInt();
|
|
366
|
+
}
|
|
367
|
+
let objectId = st.prevObjectId + 1n;
|
|
368
|
+
if (objectIdPresent) {
|
|
369
|
+
objectId = r.readVarInt();
|
|
370
|
+
} else if (st.first) {
|
|
371
|
+
throw new DecodeError(
|
|
372
|
+
"CONSTRAINT_VIOLATION",
|
|
373
|
+
"First fetch object must include objectId",
|
|
374
|
+
r.offset
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
if (priorityPresent) {
|
|
378
|
+
st.prevPriority = r.readUint8();
|
|
379
|
+
}
|
|
380
|
+
let extensionData = new Uint8Array(0);
|
|
381
|
+
if (extensionsPresent) {
|
|
382
|
+
const extLen = Number(r.readVarInt());
|
|
383
|
+
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
384
|
+
}
|
|
385
|
+
const payloadLength = Number(r.readVarInt());
|
|
386
|
+
let payload;
|
|
387
|
+
let status;
|
|
388
|
+
let payloadByteOffset;
|
|
389
|
+
if (payloadLength > 0) {
|
|
390
|
+
payloadByteOffset = base + r.offset;
|
|
391
|
+
payload = r.readBytesView(payloadLength);
|
|
392
|
+
} else {
|
|
393
|
+
status = r.readVarInt();
|
|
394
|
+
payloadByteOffset = base + r.offset;
|
|
395
|
+
payload = new Uint8Array(0);
|
|
396
|
+
}
|
|
397
|
+
const obj = {
|
|
398
|
+
type: "object",
|
|
399
|
+
byteOffset,
|
|
400
|
+
payloadByteOffset,
|
|
401
|
+
serializationFlags: flags,
|
|
402
|
+
groupId,
|
|
403
|
+
subgroupId,
|
|
404
|
+
objectId,
|
|
405
|
+
publisherPriority: st.prevPriority,
|
|
406
|
+
payloadLength,
|
|
407
|
+
extensionData,
|
|
408
|
+
payload
|
|
409
|
+
};
|
|
410
|
+
if (status !== void 0) obj.status = status;
|
|
411
|
+
st.prevGroupId = groupId;
|
|
412
|
+
st.prevSubgroupId = subgroupId;
|
|
413
|
+
st.prevObjectId = objectId;
|
|
414
|
+
st.first = false;
|
|
415
|
+
return obj;
|
|
416
|
+
}
|
|
301
417
|
function decodeFetchStream(bytes) {
|
|
302
418
|
try {
|
|
303
419
|
const r = new BufferReader(bytes);
|
|
@@ -314,124 +430,9 @@ function decodeFetchStream(bytes) {
|
|
|
314
430
|
}
|
|
315
431
|
const requestId = r.readVarInt();
|
|
316
432
|
const objects = [];
|
|
317
|
-
|
|
318
|
-
let prevSubgroupId = 0n;
|
|
319
|
-
let prevObjectId = 0n;
|
|
320
|
-
let prevPriority = 128;
|
|
321
|
-
let first = true;
|
|
433
|
+
const st = newFetchObjectState();
|
|
322
434
|
while (r.remaining > 0) {
|
|
323
|
-
|
|
324
|
-
const flags = r.readUint8();
|
|
325
|
-
const subgroupEncoding = flags & 3;
|
|
326
|
-
const objectIdPresent = (flags & 4) !== 0;
|
|
327
|
-
const groupIdPresent = (flags & 8) !== 0;
|
|
328
|
-
const priorityPresent = (flags & 16) !== 0;
|
|
329
|
-
const extensionsPresent = (flags & 32) !== 0;
|
|
330
|
-
if (flags & 192) {
|
|
331
|
-
return {
|
|
332
|
-
ok: false,
|
|
333
|
-
error: new DecodeError(
|
|
334
|
-
"CONSTRAINT_VIOLATION",
|
|
335
|
-
"Reserved bits set in fetch object flags",
|
|
336
|
-
r.offset
|
|
337
|
-
)
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
let groupId = prevGroupId;
|
|
341
|
-
if (groupIdPresent) {
|
|
342
|
-
groupId = r.readVarInt();
|
|
343
|
-
} else if (first) {
|
|
344
|
-
return {
|
|
345
|
-
ok: false,
|
|
346
|
-
error: new DecodeError(
|
|
347
|
-
"CONSTRAINT_VIOLATION",
|
|
348
|
-
"First fetch object must include groupId",
|
|
349
|
-
r.offset
|
|
350
|
-
)
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
let subgroupId;
|
|
354
|
-
if (subgroupEncoding === 0) {
|
|
355
|
-
subgroupId = 0n;
|
|
356
|
-
} else if (subgroupEncoding === 1) {
|
|
357
|
-
if (first) {
|
|
358
|
-
return {
|
|
359
|
-
ok: false,
|
|
360
|
-
error: new DecodeError(
|
|
361
|
-
"CONSTRAINT_VIOLATION",
|
|
362
|
-
"First fetch object cannot reference prior subgroupId",
|
|
363
|
-
r.offset
|
|
364
|
-
)
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
subgroupId = prevSubgroupId;
|
|
368
|
-
} else if (subgroupEncoding === 2) {
|
|
369
|
-
if (first) {
|
|
370
|
-
return {
|
|
371
|
-
ok: false,
|
|
372
|
-
error: new DecodeError(
|
|
373
|
-
"CONSTRAINT_VIOLATION",
|
|
374
|
-
"First fetch object cannot reference prior subgroupId",
|
|
375
|
-
r.offset
|
|
376
|
-
)
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
subgroupId = prevSubgroupId + 1n;
|
|
380
|
-
} else {
|
|
381
|
-
subgroupId = r.readVarInt();
|
|
382
|
-
}
|
|
383
|
-
let objectId = prevObjectId + 1n;
|
|
384
|
-
if (objectIdPresent) {
|
|
385
|
-
objectId = r.readVarInt();
|
|
386
|
-
} else if (first) {
|
|
387
|
-
return {
|
|
388
|
-
ok: false,
|
|
389
|
-
error: new DecodeError(
|
|
390
|
-
"CONSTRAINT_VIOLATION",
|
|
391
|
-
"First fetch object must include objectId",
|
|
392
|
-
r.offset
|
|
393
|
-
)
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
if (priorityPresent) {
|
|
397
|
-
prevPriority = r.readUint8();
|
|
398
|
-
}
|
|
399
|
-
let extensionData = new Uint8Array(0);
|
|
400
|
-
if (extensionsPresent) {
|
|
401
|
-
const extLen = Number(r.readVarInt());
|
|
402
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
403
|
-
}
|
|
404
|
-
const payloadLength = Number(r.readVarInt());
|
|
405
|
-
let payload;
|
|
406
|
-
let status;
|
|
407
|
-
let payloadByteOffset;
|
|
408
|
-
if (payloadLength > 0) {
|
|
409
|
-
payloadByteOffset = r.offset;
|
|
410
|
-
payload = r.readBytesView(payloadLength);
|
|
411
|
-
} else {
|
|
412
|
-
status = r.readVarInt();
|
|
413
|
-
payloadByteOffset = r.offset;
|
|
414
|
-
payload = new Uint8Array(0);
|
|
415
|
-
}
|
|
416
|
-
const obj = {
|
|
417
|
-
type: "object",
|
|
418
|
-
byteOffset,
|
|
419
|
-
payloadByteOffset,
|
|
420
|
-
serializationFlags: flags,
|
|
421
|
-
groupId,
|
|
422
|
-
subgroupId,
|
|
423
|
-
objectId,
|
|
424
|
-
publisherPriority: prevPriority,
|
|
425
|
-
payloadLength,
|
|
426
|
-
extensionData,
|
|
427
|
-
payload
|
|
428
|
-
};
|
|
429
|
-
if (status !== void 0) obj.status = status;
|
|
430
|
-
objects.push(obj);
|
|
431
|
-
prevGroupId = groupId;
|
|
432
|
-
prevSubgroupId = subgroupId;
|
|
433
|
-
prevObjectId = objectId;
|
|
434
|
-
first = false;
|
|
435
|
+
objects.push(readFetchObject(r, 0, st));
|
|
435
436
|
}
|
|
436
437
|
return {
|
|
437
438
|
ok: true,
|
|
@@ -457,61 +458,69 @@ function decodeDataStream(streamType, bytes) {
|
|
|
457
458
|
}
|
|
458
459
|
}
|
|
459
460
|
}
|
|
461
|
+
var StreamBuffer = class {
|
|
462
|
+
buf = new Uint8Array(0);
|
|
463
|
+
/** Bytes written into `buf`. */
|
|
464
|
+
len = 0;
|
|
465
|
+
/** Consumed prefix of `buf`; `base + offset` is the position in the stream. */
|
|
466
|
+
offset = 0;
|
|
467
|
+
/** Absolute position of `buf[0]` within the stream. */
|
|
468
|
+
base = 0;
|
|
469
|
+
get unread() {
|
|
470
|
+
return this.len - this.offset;
|
|
471
|
+
}
|
|
472
|
+
append(chunk) {
|
|
473
|
+
if (this.len + chunk.length > this.buf.length) {
|
|
474
|
+
const live = this.len - this.offset;
|
|
475
|
+
const needed = live + chunk.length;
|
|
476
|
+
let cap = Math.max(4096, this.buf.length);
|
|
477
|
+
while (cap < needed * 2) cap *= 2;
|
|
478
|
+
const next = new Uint8Array(cap);
|
|
479
|
+
next.set(this.buf.subarray(this.offset, this.len), 0);
|
|
480
|
+
this.buf = next;
|
|
481
|
+
this.base += this.offset;
|
|
482
|
+
this.len = live;
|
|
483
|
+
this.offset = 0;
|
|
484
|
+
}
|
|
485
|
+
this.buf.set(chunk, this.len);
|
|
486
|
+
this.len += chunk.length;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* The written bytes, for a reader positioned at `offset`. Bounded by `len`
|
|
490
|
+
* rather than by capacity, so `BufferReader.remaining` counts real bytes and
|
|
491
|
+
* not the spare room after them.
|
|
492
|
+
*/
|
|
493
|
+
written() {
|
|
494
|
+
return this.buf.subarray(0, this.len);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
460
497
|
function createSubgroupStreamDecoder() {
|
|
461
|
-
|
|
462
|
-
let
|
|
498
|
+
const b = new StreamBuffer();
|
|
499
|
+
let header = null;
|
|
463
500
|
let headerEmitted = false;
|
|
464
501
|
let prevObjectId = -1n;
|
|
465
|
-
let
|
|
466
|
-
|
|
467
|
-
|
|
502
|
+
let isFirst = true;
|
|
503
|
+
function emitHeader(controller, h, subgroupId) {
|
|
504
|
+
controller.enqueue({
|
|
505
|
+
type: "subgroup_header",
|
|
506
|
+
headerType: h.streamType,
|
|
507
|
+
trackAlias: h.trackAlias,
|
|
508
|
+
groupId: h.groupId,
|
|
509
|
+
subgroupId,
|
|
510
|
+
publisherPriority: h.publisherPriority,
|
|
511
|
+
...h.endOfGroup ? { endOfGroup: true } : {}
|
|
512
|
+
});
|
|
513
|
+
headerEmitted = true;
|
|
514
|
+
}
|
|
468
515
|
return new TransformStream({
|
|
469
516
|
transform(chunk, controller) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
475
|
-
newBuffer.set(buffer, 0);
|
|
476
|
-
newBuffer.set(chunk, buffer.length);
|
|
477
|
-
buffer = newBuffer;
|
|
478
|
-
if (!headerEmitted) {
|
|
517
|
+
b.append(chunk);
|
|
518
|
+
const view = b.written();
|
|
519
|
+
if (header === null) {
|
|
479
520
|
try {
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
controller.error(
|
|
484
|
-
new DecodeError(
|
|
485
|
-
"CONSTRAINT_VIOLATION",
|
|
486
|
-
`Expected subgroup stream type, got 0x${streamType.toString(16)}`,
|
|
487
|
-
0
|
|
488
|
-
)
|
|
489
|
-
);
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
_extensionsPresent = (streamType & 1) !== 0;
|
|
493
|
-
const hasSubgroupField = (streamType & 4) !== 0;
|
|
494
|
-
_subgroupIsFirstObjId = false;
|
|
495
|
-
const hasPriority = streamType < 48;
|
|
496
|
-
const trackAlias = r.readVarInt();
|
|
497
|
-
const groupId = r.readVarInt();
|
|
498
|
-
let subgroupId = 0n;
|
|
499
|
-
if (hasSubgroupField) {
|
|
500
|
-
subgroupId = r.readVarInt();
|
|
501
|
-
}
|
|
502
|
-
let publisherPriority = 128;
|
|
503
|
-
if (hasPriority) {
|
|
504
|
-
publisherPriority = r.readUint8();
|
|
505
|
-
}
|
|
506
|
-
controller.enqueue({
|
|
507
|
-
type: "subgroup_header",
|
|
508
|
-
trackAlias,
|
|
509
|
-
groupId,
|
|
510
|
-
subgroupId,
|
|
511
|
-
publisherPriority
|
|
512
|
-
});
|
|
513
|
-
headerEmitted = true;
|
|
514
|
-
offset += r.offset;
|
|
521
|
+
const hr = new BufferReader(view, b.offset);
|
|
522
|
+
header = readSubgroupHeader(hr);
|
|
523
|
+
b.offset = hr.offset;
|
|
515
524
|
} catch (e) {
|
|
516
525
|
if (e instanceof DecodeError && e.code === "UNEXPECTED_END") {
|
|
517
526
|
return;
|
|
@@ -519,72 +528,51 @@ function createSubgroupStreamDecoder() {
|
|
|
519
528
|
controller.error(e);
|
|
520
529
|
return;
|
|
521
530
|
}
|
|
531
|
+
if (!header.subgroupIsFirstObjId) emitHeader(controller, header, header.subgroupId);
|
|
522
532
|
}
|
|
523
|
-
|
|
533
|
+
const h = header;
|
|
534
|
+
if (h === null) return;
|
|
535
|
+
const r = new BufferReader(view, b.offset);
|
|
536
|
+
while (r.remaining > 0) {
|
|
537
|
+
const start = r.offset;
|
|
538
|
+
let obj;
|
|
524
539
|
try {
|
|
525
|
-
|
|
526
|
-
const byteOffset = r.offset;
|
|
527
|
-
const delta = r.readVarInt();
|
|
528
|
-
let objectId;
|
|
529
|
-
if (firstObject) {
|
|
530
|
-
objectId = delta;
|
|
531
|
-
firstObject = false;
|
|
532
|
-
} else {
|
|
533
|
-
objectId = prevObjectId + 1n + delta;
|
|
534
|
-
}
|
|
535
|
-
let extensionData = new Uint8Array(0);
|
|
536
|
-
if (_extensionsPresent) {
|
|
537
|
-
const extLen = Number(r.readVarInt());
|
|
538
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
539
|
-
}
|
|
540
|
-
const payloadLength = Number(r.readVarInt());
|
|
541
|
-
const payloadByteOffset = r.offset;
|
|
542
|
-
const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
|
|
543
|
-
controller.enqueue({
|
|
544
|
-
type: "object",
|
|
545
|
-
byteOffset,
|
|
546
|
-
payloadByteOffset,
|
|
547
|
-
objectId,
|
|
548
|
-
payloadLength,
|
|
549
|
-
extensionData,
|
|
550
|
-
payload
|
|
551
|
-
});
|
|
552
|
-
offset += r.offset;
|
|
553
|
-
prevObjectId = objectId;
|
|
540
|
+
obj = readSubgroupObject(r, h.extensionsPresent, isFirst, prevObjectId, b.base);
|
|
554
541
|
} catch (e) {
|
|
555
542
|
if (e instanceof DecodeError && e.code === "UNEXPECTED_END") {
|
|
556
|
-
|
|
543
|
+
b.offset = start;
|
|
544
|
+
return;
|
|
557
545
|
}
|
|
558
546
|
controller.error(e);
|
|
559
547
|
return;
|
|
560
548
|
}
|
|
549
|
+
if (!headerEmitted) emitHeader(controller, h, obj.objectId);
|
|
550
|
+
isFirst = false;
|
|
551
|
+
b.offset = r.offset;
|
|
552
|
+
prevObjectId = obj.objectId;
|
|
553
|
+
controller.enqueue(obj);
|
|
561
554
|
}
|
|
562
555
|
},
|
|
563
556
|
flush(controller) {
|
|
564
|
-
if (
|
|
557
|
+
if (header !== null && !headerEmitted) emitHeader(controller, header, 0n);
|
|
558
|
+
if (b.unread > 0) {
|
|
565
559
|
controller.error(new DecodeError("UNEXPECTED_END", "Stream ended with incomplete data", 0));
|
|
566
560
|
}
|
|
567
561
|
}
|
|
568
562
|
});
|
|
569
563
|
}
|
|
570
564
|
function createFetchStreamDecoder() {
|
|
571
|
-
|
|
572
|
-
let offset = 0;
|
|
565
|
+
const b = new StreamBuffer();
|
|
573
566
|
let headerEmitted = false;
|
|
567
|
+
const st = newFetchObjectState();
|
|
574
568
|
return new TransformStream({
|
|
575
569
|
transform(chunk, controller) {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
offset = 0;
|
|
579
|
-
}
|
|
580
|
-
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
581
|
-
newBuffer.set(buffer, 0);
|
|
582
|
-
newBuffer.set(chunk, buffer.length);
|
|
583
|
-
buffer = newBuffer;
|
|
570
|
+
b.append(chunk);
|
|
571
|
+
const view = b.written();
|
|
584
572
|
if (!headerEmitted) {
|
|
585
573
|
try {
|
|
586
|
-
const
|
|
587
|
-
const streamType =
|
|
574
|
+
const r2 = new BufferReader(view, b.offset);
|
|
575
|
+
const streamType = r2.readVarInt();
|
|
588
576
|
if (streamType !== FETCH_STREAM_TYPE) {
|
|
589
577
|
controller.error(
|
|
590
578
|
new DecodeError(
|
|
@@ -595,10 +583,10 @@ function createFetchStreamDecoder() {
|
|
|
595
583
|
);
|
|
596
584
|
return;
|
|
597
585
|
}
|
|
598
|
-
const requestId =
|
|
586
|
+
const requestId = r2.readVarInt();
|
|
599
587
|
controller.enqueue({ type: "fetch_header", requestId });
|
|
600
588
|
headerEmitted = true;
|
|
601
|
-
offset
|
|
589
|
+
b.offset = r2.offset;
|
|
602
590
|
} catch (e) {
|
|
603
591
|
if (e instanceof DecodeError && e.code === "UNEXPECTED_END") {
|
|
604
592
|
return;
|
|
@@ -607,101 +595,82 @@ function createFetchStreamDecoder() {
|
|
|
607
595
|
return;
|
|
608
596
|
}
|
|
609
597
|
}
|
|
610
|
-
|
|
598
|
+
const r = new BufferReader(view, b.offset);
|
|
599
|
+
while (r.remaining > 0) {
|
|
600
|
+
const start = r.offset;
|
|
601
|
+
let obj;
|
|
611
602
|
try {
|
|
612
|
-
|
|
613
|
-
const flags = r.readUint8();
|
|
614
|
-
const objectIdPresent = (flags & 4) !== 0;
|
|
615
|
-
const groupIdPresent = (flags & 8) !== 0;
|
|
616
|
-
const priorityPresent = (flags & 16) !== 0;
|
|
617
|
-
const extensionsPresent = (flags & 32) !== 0;
|
|
618
|
-
const subgroupEncoding = flags & 3;
|
|
619
|
-
if (groupIdPresent) r.readVarInt();
|
|
620
|
-
if (subgroupEncoding === 3) r.readVarInt();
|
|
621
|
-
let objectId = 0n;
|
|
622
|
-
if (objectIdPresent) objectId = r.readVarInt();
|
|
623
|
-
if (priorityPresent) r.readUint8();
|
|
624
|
-
let extensionData = new Uint8Array(0);
|
|
625
|
-
if (extensionsPresent) {
|
|
626
|
-
const extLen = Number(r.readVarInt());
|
|
627
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
628
|
-
}
|
|
629
|
-
const payloadLength = Number(r.readVarInt());
|
|
630
|
-
const payloadByteOffset = r.offset;
|
|
631
|
-
const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
|
|
632
|
-
controller.enqueue({
|
|
633
|
-
type: "object",
|
|
634
|
-
objectId,
|
|
635
|
-
payloadLength,
|
|
636
|
-
extensionData,
|
|
637
|
-
payload,
|
|
638
|
-
byteOffset: 0,
|
|
639
|
-
payloadByteOffset
|
|
640
|
-
});
|
|
641
|
-
offset += r.offset;
|
|
603
|
+
obj = readFetchObject(r, b.base, st);
|
|
642
604
|
} catch (e) {
|
|
643
605
|
if (e instanceof DecodeError && e.code === "UNEXPECTED_END") {
|
|
644
|
-
|
|
606
|
+
b.offset = start;
|
|
607
|
+
return;
|
|
645
608
|
}
|
|
646
609
|
controller.error(e);
|
|
647
610
|
return;
|
|
648
611
|
}
|
|
612
|
+
b.offset = r.offset;
|
|
613
|
+
controller.enqueue(obj);
|
|
649
614
|
}
|
|
650
615
|
},
|
|
651
616
|
flush(controller) {
|
|
652
|
-
if (
|
|
617
|
+
if (b.unread > 0) {
|
|
653
618
|
controller.error(new DecodeError("UNEXPECTED_END", "Stream ended with incomplete data", 0));
|
|
654
619
|
}
|
|
655
620
|
}
|
|
656
621
|
});
|
|
657
622
|
}
|
|
658
623
|
function createDataStreamDecoder() {
|
|
659
|
-
let
|
|
660
|
-
let
|
|
661
|
-
let
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
const firstByte = buffer[offset];
|
|
677
|
-
if (firstByte >= 16 && firstByte <= 31 || firstByte >= 48 && firstByte <= 63) {
|
|
678
|
-
const decoder = createSubgroupStreamDecoder();
|
|
679
|
-
inner = decoder;
|
|
680
|
-
} else if (firstByte === 5) {
|
|
681
|
-
const decoder = createFetchStreamDecoder();
|
|
682
|
-
inner = decoder;
|
|
683
|
-
} else {
|
|
684
|
-
controller.error(
|
|
685
|
-
new DecodeError(
|
|
686
|
-
"CONSTRAINT_VIOLATION",
|
|
687
|
-
`Unknown data stream type: 0x${firstByte.toString(16)}`,
|
|
688
|
-
0
|
|
689
|
-
)
|
|
690
|
-
);
|
|
691
|
-
return;
|
|
624
|
+
let writer = null;
|
|
625
|
+
let pump = Promise.resolve();
|
|
626
|
+
let broken = false;
|
|
627
|
+
function attach(inner, controller) {
|
|
628
|
+
writer = inner.writable.getWriter();
|
|
629
|
+
const reader = inner.readable.getReader();
|
|
630
|
+
pump = (async () => {
|
|
631
|
+
try {
|
|
632
|
+
for (; ; ) {
|
|
633
|
+
const { done, value } = await reader.read();
|
|
634
|
+
if (done) break;
|
|
635
|
+
controller.enqueue(value);
|
|
636
|
+
}
|
|
637
|
+
} catch (e) {
|
|
638
|
+
if (!broken) {
|
|
639
|
+
broken = true;
|
|
640
|
+
controller.error(e);
|
|
692
641
|
}
|
|
693
642
|
}
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
643
|
+
})();
|
|
644
|
+
}
|
|
645
|
+
async function feed(bytes) {
|
|
646
|
+
if (writer === null || broken || bytes.length === 0) return;
|
|
647
|
+
try {
|
|
648
|
+
await writer.write(bytes);
|
|
649
|
+
} catch {
|
|
650
|
+
broken = true;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return new TransformStream({
|
|
654
|
+
async transform(chunk, controller) {
|
|
655
|
+
if (broken) return;
|
|
656
|
+
if (writer !== null) {
|
|
657
|
+
await feed(chunk);
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (chunk.length === 0) return;
|
|
661
|
+
const firstByte = chunk[0];
|
|
700
662
|
if (firstByte >= 16 && firstByte <= 31 || firstByte >= 48 && firstByte <= 63) {
|
|
701
|
-
|
|
663
|
+
attach(
|
|
664
|
+
createSubgroupStreamDecoder(),
|
|
665
|
+
controller
|
|
666
|
+
);
|
|
702
667
|
} else if (firstByte === 5) {
|
|
703
|
-
|
|
668
|
+
attach(
|
|
669
|
+
createFetchStreamDecoder(),
|
|
670
|
+
controller
|
|
671
|
+
);
|
|
704
672
|
} else {
|
|
673
|
+
broken = true;
|
|
705
674
|
controller.error(
|
|
706
675
|
new DecodeError(
|
|
707
676
|
"CONSTRAINT_VIOLATION",
|
|
@@ -711,31 +680,15 @@ function createDataStreamDecoder() {
|
|
|
711
680
|
);
|
|
712
681
|
return;
|
|
713
682
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
type: "subgroup_header",
|
|
722
|
-
trackAlias: stream.trackAlias,
|
|
723
|
-
groupId: stream.groupId,
|
|
724
|
-
subgroupId: stream.subgroupId,
|
|
725
|
-
publisherPriority: stream.publisherPriority
|
|
726
|
-
});
|
|
727
|
-
for (const obj of stream.objects) {
|
|
728
|
-
controller.enqueue(obj);
|
|
729
|
-
}
|
|
730
|
-
} else if (stream.type === "fetch") {
|
|
731
|
-
controller.enqueue({
|
|
732
|
-
type: "fetch_header",
|
|
733
|
-
requestId: stream.requestId
|
|
734
|
-
});
|
|
735
|
-
for (const obj of stream.objects) {
|
|
736
|
-
controller.enqueue(obj);
|
|
737
|
-
}
|
|
683
|
+
await feed(chunk);
|
|
684
|
+
},
|
|
685
|
+
async flush() {
|
|
686
|
+
if (writer === null) return;
|
|
687
|
+
try {
|
|
688
|
+
await writer.close();
|
|
689
|
+
} catch {
|
|
738
690
|
}
|
|
691
|
+
await pump;
|
|
739
692
|
}
|
|
740
693
|
});
|
|
741
694
|
}
|
|
@@ -747,7 +700,7 @@ function encodeSetupParams(params, writer) {
|
|
|
747
700
|
let count = 0;
|
|
748
701
|
if (params.path !== void 0) count++;
|
|
749
702
|
if (params.max_request_id !== void 0) count++;
|
|
750
|
-
|
|
703
|
+
count += params.authorization_token?.length ?? 0;
|
|
751
704
|
if (params.max_auth_token_cache_size !== void 0) count++;
|
|
752
705
|
if (params.authority !== void 0) count++;
|
|
753
706
|
if (params.moqt_implementation !== void 0) count++;
|
|
@@ -763,10 +716,10 @@ function encodeSetupParams(params, writer) {
|
|
|
763
716
|
writer.writeVarInt(SETUP_PARAM_MAX_REQUEST_ID);
|
|
764
717
|
writer.writeVarInt(params.max_request_id);
|
|
765
718
|
}
|
|
766
|
-
|
|
719
|
+
for (const token of params.authorization_token ?? []) {
|
|
767
720
|
writer.writeVarInt(SETUP_PARAM_AUTHORIZATION_TOKEN);
|
|
768
721
|
const tmpW = new BufferWriter(64);
|
|
769
|
-
encodeAuthorizationToken(
|
|
722
|
+
encodeAuthorizationToken(token, tmpW);
|
|
770
723
|
const raw = tmpW.finish();
|
|
771
724
|
writer.writeVarInt(raw.byteLength);
|
|
772
725
|
writer.writeBytes(raw);
|
|
@@ -832,7 +785,9 @@ function decodeSetupParams(reader) {
|
|
|
832
785
|
if (paramType === SETUP_PARAM_PATH) {
|
|
833
786
|
result.path = textDecoder.decode(bytes);
|
|
834
787
|
} else if (paramType === SETUP_PARAM_AUTHORIZATION_TOKEN) {
|
|
835
|
-
|
|
788
|
+
const token = decodeAuthorizationToken(new BufferReader(bytes));
|
|
789
|
+
noteAuthTokenValue(reader.offset - length, length, token.token_value);
|
|
790
|
+
result.authorization_token = [...result.authorization_token ?? [], token];
|
|
836
791
|
} else if (paramType === SETUP_PARAM_AUTHORITY) {
|
|
837
792
|
result.authority = textDecoder.decode(bytes);
|
|
838
793
|
} else if (paramType === SETUP_PARAM_MOQT_IMPLEMENTATION) {
|
|
@@ -890,7 +845,7 @@ var PARAM_NEW_GROUP_REQUEST = 0x32n;
|
|
|
890
845
|
function encodeParams(params, writer) {
|
|
891
846
|
let count = params.unknown ? params.unknown.length : 0;
|
|
892
847
|
if (params.delivery_timeout !== void 0) count++;
|
|
893
|
-
|
|
848
|
+
count += params.authorization_token?.length ?? 0;
|
|
894
849
|
if (params.max_cache_duration !== void 0) count++;
|
|
895
850
|
if (params.expires !== void 0) count++;
|
|
896
851
|
if (params.largest_object !== void 0) count++;
|
|
@@ -906,10 +861,10 @@ function encodeParams(params, writer) {
|
|
|
906
861
|
writer.writeVarInt(PARAM_DELIVERY_TIMEOUT);
|
|
907
862
|
writer.writeVarInt(params.delivery_timeout);
|
|
908
863
|
}
|
|
909
|
-
|
|
864
|
+
for (const token of params.authorization_token ?? []) {
|
|
910
865
|
writer.writeVarInt(PARAM_AUTHORIZATION_TOKEN);
|
|
911
866
|
const tmpW = new BufferWriter(64);
|
|
912
|
-
encodeAuthorizationToken(
|
|
867
|
+
encodeAuthorizationToken(token, tmpW);
|
|
913
868
|
const raw = tmpW.finish();
|
|
914
869
|
writer.writeVarInt(raw.byteLength);
|
|
915
870
|
writer.writeBytes(raw);
|
|
@@ -999,7 +954,9 @@ function decodeParams(reader) {
|
|
|
999
954
|
} else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
|
|
1000
955
|
const length = Number(reader.readVarInt());
|
|
1001
956
|
const tokenBytes = reader.readBytes(length);
|
|
1002
|
-
|
|
957
|
+
const token = decodeAuthorizationToken(new BufferReader(tokenBytes));
|
|
958
|
+
noteAuthTokenValue(reader.offset - length, length, token.token_value);
|
|
959
|
+
result.authorization_token = [...result.authorization_token ?? [], token];
|
|
1003
960
|
} else if (paramType === PARAM_MAX_CACHE_DURATION) {
|
|
1004
961
|
result.max_cache_duration = reader.readVarInt();
|
|
1005
962
|
} else if (paramType === PARAM_EXPIRES) {
|
|
@@ -1562,6 +1519,23 @@ function createDraft15Codec() {
|
|
|
1562
1519
|
createDataStreamDecoder
|
|
1563
1520
|
};
|
|
1564
1521
|
}
|
|
1522
|
+
function noteAuthTokenValue(valueStart, valueLength, value) {
|
|
1523
|
+
if (value === void 0 || value.byteLength === 0) return;
|
|
1524
|
+
recordAuthValueSpan(valueStart + valueLength - value.byteLength, value.byteLength);
|
|
1525
|
+
}
|
|
1526
|
+
function redactAuthTokens(bytes) {
|
|
1527
|
+
let payloadStart;
|
|
1528
|
+
try {
|
|
1529
|
+
const probe = new BufferReader(bytes);
|
|
1530
|
+
probe.readVarInt();
|
|
1531
|
+
probe.readUint8();
|
|
1532
|
+
probe.readUint8();
|
|
1533
|
+
payloadStart = probe.offset;
|
|
1534
|
+
} catch {
|
|
1535
|
+
return { bytes, redacted: 0, incomplete: false, decoded: false };
|
|
1536
|
+
}
|
|
1537
|
+
return redactWith(bytes, payloadStart, () => decodeMessage(bytes).ok);
|
|
1538
|
+
}
|
|
1565
1539
|
|
|
1566
1540
|
export {
|
|
1567
1541
|
MSG_SUBSCRIBE_UPDATE,
|
|
@@ -1607,5 +1581,6 @@ export {
|
|
|
1607
1581
|
encodeMessage,
|
|
1608
1582
|
decodeMessage,
|
|
1609
1583
|
createStreamDecoder,
|
|
1610
|
-
createDraft15Codec
|
|
1584
|
+
createDraft15Codec,
|
|
1585
|
+
redactAuthTokens
|
|
1611
1586
|
};
|