@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
|
@@ -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
|
-
if (params.authorization_token !== void 0) count++;
|
|
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
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
738
|
+
for (const token of _nullishCoalesce(params.authorization_token, () => ( []))) {
|
|
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,7 +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
|
-
|
|
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];
|
|
865
836
|
} else if (paramType === SETUP_PARAM_AUTHORITY) {
|
|
866
837
|
result.authority = textDecoder.decode(bytes);
|
|
867
838
|
} else if (paramType === SETUP_PARAM_MOQT_IMPLEMENTATION) {
|
|
@@ -870,7 +841,7 @@ function decodeSetupParams(reader) {
|
|
|
870
841
|
unknown.push({
|
|
871
842
|
id: `0x${paramType.toString(16)}`,
|
|
872
843
|
length,
|
|
873
|
-
raw_hex:
|
|
844
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, bytes)
|
|
874
845
|
});
|
|
875
846
|
}
|
|
876
847
|
}
|
|
@@ -938,12 +909,12 @@ function encodeTrackExtensions(ext, writer) {
|
|
|
938
909
|
const id = BigInt(u.id);
|
|
939
910
|
writer.writeVarInt(id);
|
|
940
911
|
if (id % 2n === 0n) {
|
|
941
|
-
const raw =
|
|
942
|
-
const tmpReader = new (0,
|
|
912
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
913
|
+
const tmpReader = new (0, _chunk5IMHJIAZcjs.BufferReader)(raw);
|
|
943
914
|
const value = tmpReader.readVarInt();
|
|
944
915
|
writer.writeVarInt(value);
|
|
945
916
|
} else {
|
|
946
|
-
const raw =
|
|
917
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
947
918
|
writer.writeVarInt(raw.byteLength);
|
|
948
919
|
writer.writeBytes(raw);
|
|
949
920
|
}
|
|
@@ -963,13 +934,13 @@ function decodeTrackExtensions(reader) {
|
|
|
963
934
|
result.default_publisher_priority = reader.readVarInt();
|
|
964
935
|
} else if (extType % 2n === 0n) {
|
|
965
936
|
const value = reader.readVarInt();
|
|
966
|
-
const tmpWriter = new (0,
|
|
937
|
+
const tmpWriter = new (0, _chunk5IMHJIAZcjs.BufferWriter)(16);
|
|
967
938
|
tmpWriter.writeVarInt(value);
|
|
968
939
|
const raw = tmpWriter.finish();
|
|
969
940
|
unknown.push({
|
|
970
941
|
id: `0x${extType.toString(16)}`,
|
|
971
942
|
length: raw.byteLength,
|
|
972
|
-
raw_hex:
|
|
943
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, raw)
|
|
973
944
|
});
|
|
974
945
|
} else {
|
|
975
946
|
const length = Number(reader.readVarInt());
|
|
@@ -977,7 +948,7 @@ function decodeTrackExtensions(reader) {
|
|
|
977
948
|
unknown.push({
|
|
978
949
|
id: `0x${extType.toString(16)}`,
|
|
979
950
|
length,
|
|
980
|
-
raw_hex:
|
|
951
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, bytes)
|
|
981
952
|
});
|
|
982
953
|
}
|
|
983
954
|
}
|
|
@@ -994,12 +965,12 @@ function encodeParams(params, writer) {
|
|
|
994
965
|
encode: (w) => w.writeVarInt(params.delivery_timeout)
|
|
995
966
|
});
|
|
996
967
|
}
|
|
997
|
-
|
|
968
|
+
for (const token of _nullishCoalesce(params.authorization_token, () => ( []))) {
|
|
998
969
|
entries.push({
|
|
999
970
|
type: PARAM_AUTHORIZATION_TOKEN,
|
|
1000
971
|
encode: (w) => {
|
|
1001
|
-
const tmpW = new (0,
|
|
1002
|
-
encodeAuthorizationToken(
|
|
972
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(64);
|
|
973
|
+
encodeAuthorizationToken(token, tmpW);
|
|
1003
974
|
const raw = tmpW.finish();
|
|
1004
975
|
w.writeVarInt(raw.byteLength);
|
|
1005
976
|
w.writeBytes(raw);
|
|
@@ -1023,7 +994,7 @@ function encodeParams(params, writer) {
|
|
|
1023
994
|
// replaced that with "the encoding is specified by each parameter
|
|
1024
995
|
// definition", which is where the same field loses its length.
|
|
1025
996
|
encode: (w) => {
|
|
1026
|
-
const tmpW = new (0,
|
|
997
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(16);
|
|
1027
998
|
tmpW.writeVarInt(params.largest_object.group);
|
|
1028
999
|
tmpW.writeVarInt(params.largest_object.object);
|
|
1029
1000
|
const raw = tmpW.finish();
|
|
@@ -1051,7 +1022,7 @@ function encodeParams(params, writer) {
|
|
|
1051
1022
|
entries.push({
|
|
1052
1023
|
type: PARAM_SUBSCRIPTION_FILTER,
|
|
1053
1024
|
encode: (w) => {
|
|
1054
|
-
const tmpW = new (0,
|
|
1025
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(32);
|
|
1055
1026
|
const f = params.subscription_filter;
|
|
1056
1027
|
tmpW.writeVarInt(f.filter_type);
|
|
1057
1028
|
if (f.filter_type === 3n || f.filter_type === 4n) {
|
|
@@ -1088,9 +1059,9 @@ function encodeParams(params, writer) {
|
|
|
1088
1059
|
entries.push({
|
|
1089
1060
|
type: id,
|
|
1090
1061
|
encode: (w) => {
|
|
1091
|
-
const raw =
|
|
1062
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
1092
1063
|
if (id % 2n === 0n) {
|
|
1093
|
-
w.writeVarInt(new (0,
|
|
1064
|
+
w.writeVarInt(new (0, _chunk5IMHJIAZcjs.BufferReader)(raw).readVarInt());
|
|
1094
1065
|
} else {
|
|
1095
1066
|
w.writeVarInt(raw.byteLength);
|
|
1096
1067
|
w.writeBytes(raw);
|
|
@@ -1121,7 +1092,9 @@ function decodeParams(reader) {
|
|
|
1121
1092
|
} else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
|
|
1122
1093
|
const length = Number(reader.readVarInt());
|
|
1123
1094
|
const tokenBytes = reader.readBytes(length);
|
|
1124
|
-
|
|
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];
|
|
1125
1098
|
} else if (paramType === PARAM_MAX_CACHE_DURATION) {
|
|
1126
1099
|
result.max_cache_duration = reader.readVarInt();
|
|
1127
1100
|
} else if (paramType === PARAM_EXPIRES) {
|
|
@@ -1162,7 +1135,7 @@ function decodeParams(reader) {
|
|
|
1162
1135
|
if (consumed < length) reader.readBytes(length - consumed);
|
|
1163
1136
|
result.subscription_filter = filter;
|
|
1164
1137
|
} else {
|
|
1165
|
-
throw new (0,
|
|
1138
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
1166
1139
|
"INVALID_PARAMETER",
|
|
1167
1140
|
`Unknown Message Parameter type 0x${paramType.toString(16)}`,
|
|
1168
1141
|
reader.offset
|
|
@@ -1423,7 +1396,7 @@ function decodeFetchPayload(r) {
|
|
|
1423
1396
|
const fetch_type = r.readVarInt();
|
|
1424
1397
|
const ft = Number(fetch_type);
|
|
1425
1398
|
if (ft < 1 || ft > 3) {
|
|
1426
|
-
throw new (0,
|
|
1399
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${ft}`, r.offset);
|
|
1427
1400
|
}
|
|
1428
1401
|
let standalone;
|
|
1429
1402
|
let joining;
|
|
@@ -1554,13 +1527,13 @@ function encodeMessage(message) {
|
|
|
1554
1527
|
if (typeId === void 0) {
|
|
1555
1528
|
throw new Error(`Unknown message type: ${message.type}`);
|
|
1556
1529
|
}
|
|
1557
|
-
const payloadWriter = new (0,
|
|
1530
|
+
const payloadWriter = new (0, _chunk5IMHJIAZcjs.BufferWriter)();
|
|
1558
1531
|
encodePayload(message, payloadWriter);
|
|
1559
1532
|
const payload = payloadWriter.finishView();
|
|
1560
1533
|
if (payload.byteLength > 65535) {
|
|
1561
1534
|
throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
|
|
1562
1535
|
}
|
|
1563
|
-
const writer = new (0,
|
|
1536
|
+
const writer = new (0, _chunk5IMHJIAZcjs.BufferWriter)(payload.byteLength + 16);
|
|
1564
1537
|
writer.writeVarInt(typeId);
|
|
1565
1538
|
writer.writeUint8(payload.byteLength >> 8 & 255);
|
|
1566
1539
|
writer.writeUint8(payload.byteLength & 255);
|
|
@@ -1625,18 +1598,18 @@ function encodePayload(msg, w) {
|
|
|
1625
1598
|
}
|
|
1626
1599
|
function decodeMessage(bytes) {
|
|
1627
1600
|
try {
|
|
1628
|
-
const reader = new (0,
|
|
1601
|
+
const reader = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
1629
1602
|
const typeId = reader.readVarInt();
|
|
1630
1603
|
const lenHi = reader.readUint8();
|
|
1631
1604
|
const lenLo = reader.readUint8();
|
|
1632
1605
|
const payloadLength = lenHi << 8 | lenLo;
|
|
1633
1606
|
const payloadBytes = reader.readBytes(payloadLength);
|
|
1634
|
-
const payloadReader = new (0,
|
|
1607
|
+
const payloadReader = new (0, _chunk5IMHJIAZcjs.BufferReader)(payloadBytes);
|
|
1635
1608
|
const decoder = payloadDecoders.get(typeId);
|
|
1636
1609
|
if (!decoder) {
|
|
1637
1610
|
return {
|
|
1638
1611
|
ok: false,
|
|
1639
|
-
error: new (0,
|
|
1612
|
+
error: new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
1640
1613
|
"UNKNOWN_MESSAGE_TYPE",
|
|
1641
1614
|
`Unknown message type ID: 0x${typeId.toString(16)}`,
|
|
1642
1615
|
0
|
|
@@ -1646,7 +1619,7 @@ function decodeMessage(bytes) {
|
|
|
1646
1619
|
const message = decoder(payloadReader);
|
|
1647
1620
|
return { ok: true, value: message, bytesRead: reader.offset };
|
|
1648
1621
|
} catch (e) {
|
|
1649
|
-
if (e instanceof
|
|
1622
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError) {
|
|
1650
1623
|
return { ok: false, error: e };
|
|
1651
1624
|
}
|
|
1652
1625
|
throw e;
|
|
@@ -1681,7 +1654,7 @@ function createStreamDecoder() {
|
|
|
1681
1654
|
flush(controller) {
|
|
1682
1655
|
if (offset < buffer.length) {
|
|
1683
1656
|
controller.error(
|
|
1684
|
-
new (0,
|
|
1657
|
+
new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete message data", 0)
|
|
1685
1658
|
);
|
|
1686
1659
|
}
|
|
1687
1660
|
}
|
|
@@ -1705,6 +1678,24 @@ function createDraft16Codec() {
|
|
|
1705
1678
|
createDataStreamDecoder
|
|
1706
1679
|
};
|
|
1707
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
|
+
|
|
1708
1699
|
|
|
1709
1700
|
|
|
1710
1701
|
|
|
@@ -1752,4 +1743,4 @@ function createDraft16Codec() {
|
|
|
1752
1743
|
|
|
1753
1744
|
|
|
1754
1745
|
|
|
1755
|
-
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;
|