@moqtap/codec 0.6.0 → 0.7.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/README.md +4 -2
- package/dist/{chunk-CXFAQKL3.js → chunk-23KRITJ6.js} +1 -1
- package/dist/{chunk-JL3NEW3O.cjs → chunk-4XLYCT5Q.cjs} +90 -1
- package/dist/{chunk-DLSGOZ6P.js → chunk-5XZKO2U5.js} +34 -34
- package/dist/{chunk-62LYLROG.js → chunk-APTV6F72.js} +35 -35
- package/dist/{chunk-JB5VDJ2V.cjs → chunk-B56AG5HU.cjs} +37 -37
- package/dist/{chunk-4HBKHNU2.cjs → chunk-CZNW3R5E.cjs} +37 -37
- package/dist/{chunk-Q5D6OW6Q.js → chunk-DORX55MO.js} +1 -1
- package/dist/{chunk-OGZTQA24.cjs → chunk-EQAYMCXO.cjs} +64 -64
- package/dist/{chunk-HYI6LFMD.js → chunk-HEO2JG6C.js} +1 -1
- package/dist/{chunk-UP4XPH4J.js → chunk-I55J3KXD.js} +31 -31
- package/dist/{chunk-HZHSO7EW.cjs → chunk-IDV2JYJ6.cjs} +39 -39
- package/dist/{chunk-BAG6YWCP.cjs → chunk-IEJULBKB.cjs} +63 -63
- package/dist/{chunk-Y6KCSM3V.js → chunk-IJAF6PAY.js} +1 -1
- package/dist/{chunk-WMJVSBBE.cjs → chunk-J3ASFPCX.cjs} +57 -57
- package/dist/{chunk-COWGGUL4.js → chunk-JKMYAUGY.js} +1 -1
- package/dist/{chunk-SIYYMFCC.cjs → chunk-KCH4BQXK.cjs} +37 -37
- package/dist/{chunk-VOU7PNHI.js → chunk-KLPWJU6W.js} +89 -0
- package/dist/{chunk-NZ7GYEMT.js → chunk-KNLPX3YA.js} +1 -1
- package/dist/{chunk-A33U4WVS.cjs → chunk-KTVN4P6J.cjs} +67 -67
- package/dist/{chunk-7KBAWOBA.js → chunk-KYVTM5VI.js} +1 -1
- package/dist/{chunk-RZ3UML47.js → chunk-MD2OA7SE.js} +1 -1
- package/dist/{chunk-MSG2FXJ2.cjs → chunk-MH7537FB.cjs} +68 -68
- package/dist/{chunk-SHMA4PBY.js → chunk-N2V7Z37J.js} +1 -1
- package/dist/{chunk-HO44OANK.cjs → chunk-QGIHC6BA.cjs} +36 -36
- package/dist/{chunk-PKEOQSSZ.cjs → chunk-RIIA4ALQ.cjs} +37 -37
- package/dist/{chunk-XZE5R57R.cjs → chunk-VZHL2U2N.cjs} +37 -37
- package/dist/{chunk-RW4UG7CN.js → chunk-XHAP2YST.js} +1 -1
- package/dist/{chunk-JTRU76JN.cjs → chunk-Y4FRXYX6.cjs} +59 -59
- package/dist/draft07.cjs +4 -4
- package/dist/draft07.js +2 -2
- package/dist/draft08.cjs +3 -3
- package/dist/draft08.js +2 -2
- package/dist/draft09.cjs +3 -3
- package/dist/draft09.js +2 -2
- package/dist/draft10.cjs +3 -3
- package/dist/draft10.js +2 -2
- package/dist/draft11.cjs +3 -3
- package/dist/draft11.js +2 -2
- package/dist/draft12.cjs +3 -3
- package/dist/draft12.js +2 -2
- package/dist/draft13.cjs +3 -3
- package/dist/draft13.js +2 -2
- package/dist/draft14.cjs +3 -3
- package/dist/draft14.js +2 -2
- package/dist/draft15.cjs +3 -3
- package/dist/draft15.js +2 -2
- package/dist/draft16.cjs +3 -3
- package/dist/draft16.js +2 -2
- package/dist/draft17.cjs +3 -3
- package/dist/draft17.js +2 -2
- package/dist/draft18.cjs +3 -3
- package/dist/draft18.js +2 -2
- package/dist/draft19.cjs +3 -3
- package/dist/draft19.js +2 -2
- package/dist/index.cjs +28 -28
- package/dist/index.js +14 -14
- package/package.json +2 -2
- package/src/core/buffer-reader.ts +74 -2
- package/src/core/buffer-writer.ts +56 -4
- package/src/drafts/draft17/codec.ts +2 -2
- package/src/drafts/draft17/data-streams.ts +2 -2
- package/src/drafts/draft18/codec.ts +2 -2
- package/src/drafts/draft18/data-streams.ts +2 -2
- package/src/drafts/draft19/codec.ts +2 -2
- package/src/drafts/draft19/data-streams.ts +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
MoQT (Media over QUIC Transport) wire-format codec and session state machine for JavaScript/TypeScript.
|
|
4
4
|
|
|
5
|
-
- Multi-draft support (drafts 07 through
|
|
5
|
+
- Multi-draft support (drafts 07 through 19)
|
|
6
6
|
- Stateless encode/decode of all MoQT control messages and data streams
|
|
7
7
|
- Protocol session state machine with FSM-based validation per draft
|
|
8
8
|
- Zero runtime dependencies
|
|
@@ -43,7 +43,7 @@ Or use the factory if your application supports multiple drafts:
|
|
|
43
43
|
```typescript
|
|
44
44
|
import { createCodec, DRAFT_VERSIONS } from '@moqtap/codec'
|
|
45
45
|
|
|
46
|
-
const codec = createCodec({ draft: '
|
|
46
|
+
const codec = createCodec({ draft: '19' }) // '07' through '19'
|
|
47
47
|
|
|
48
48
|
// DRAFT_VERSIONS provides wire version numbers under short aliases:
|
|
49
49
|
// DRAFT_VERSIONS['07'] — 0xff000007n
|
|
@@ -67,6 +67,8 @@ Each draft is available as a subpath import with its own codec and session state
|
|
|
67
67
|
| `@moqtap/codec/draft15` | Draft-15 codec |
|
|
68
68
|
| `@moqtap/codec/draft16` | Draft-16 codec |
|
|
69
69
|
| `@moqtap/codec/draft17` | Draft-17 codec |
|
|
70
|
+
| `@moqtap/codec/draft18` | Draft-18 codec |
|
|
71
|
+
| `@moqtap/codec/draft19` | Draft-19 codec |
|
|
70
72
|
| `@moqtap/codec/draft{N}/session` | Session state machine for draft N |
|
|
71
73
|
|
|
72
74
|
> **Note:** A default (versionless) codec will be available once the MoQT specification reaches RFC status. Until then, always specify a draft version.
|
|
@@ -124,6 +124,54 @@ var BufferReader = class {
|
|
|
124
124
|
return params;
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
+
var MoqtBufferReader = class extends BufferReader {
|
|
128
|
+
/** Draft-17 omits the 7-byte length; draft-18 restored it. */
|
|
129
|
+
get allowSevenByte() {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
readVarInt() {
|
|
133
|
+
if (this.remaining < 1) {
|
|
134
|
+
throw new DecodeError("UNEXPECTED_END", "Not enough bytes for varint", this.pos);
|
|
135
|
+
}
|
|
136
|
+
const first = this.view.getUint8(this.pos);
|
|
137
|
+
if (first === 255) {
|
|
138
|
+
if (this.remaining < 9) {
|
|
139
|
+
throw new DecodeError("UNEXPECTED_END", "Not enough bytes for 9-byte varint", this.pos);
|
|
140
|
+
}
|
|
141
|
+
const value2 = this.view.getBigUint64(this.pos + 1);
|
|
142
|
+
this.pos += 9;
|
|
143
|
+
return value2;
|
|
144
|
+
}
|
|
145
|
+
let leadingOnes = 0;
|
|
146
|
+
while (leadingOnes < 8 && (first & 128 >> leadingOnes) !== 0) leadingOnes++;
|
|
147
|
+
const length = leadingOnes + 1;
|
|
148
|
+
if (length === 7 && !this.allowSevenByte) {
|
|
149
|
+
throw new DecodeError(
|
|
150
|
+
"INVALID_VARINT",
|
|
151
|
+
"The 7-byte varint is not defined in draft-17",
|
|
152
|
+
this.pos
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (this.remaining < length) {
|
|
156
|
+
throw new DecodeError(
|
|
157
|
+
"UNEXPECTED_END",
|
|
158
|
+
`Not enough bytes for ${length}-byte varint`,
|
|
159
|
+
this.pos
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
let value = BigInt(first & (1 << 8 - length) - 1);
|
|
163
|
+
for (let i = 1; i < length; i++) {
|
|
164
|
+
value = value << 8n | BigInt(this.view.getUint8(this.pos + i));
|
|
165
|
+
}
|
|
166
|
+
this.pos += length;
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var Draft17BufferReader = class extends MoqtBufferReader {
|
|
171
|
+
get allowSevenByte() {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
127
175
|
|
|
128
176
|
// src/core/buffer-writer.ts
|
|
129
177
|
var textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
@@ -211,6 +259,43 @@ var BufferWriter = class {
|
|
|
211
259
|
return this.buffer.subarray(0, this.pos);
|
|
212
260
|
}
|
|
213
261
|
};
|
|
262
|
+
var MoqtBufferWriter = class extends BufferWriter {
|
|
263
|
+
/** Draft-17 omits the 7-byte length; draft-18 restored it. */
|
|
264
|
+
get allowSevenByte() {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
writeVarInt(value) {
|
|
268
|
+
const v = BigInt(value);
|
|
269
|
+
if (v < 0n) throw new Error("VarInt value must be non-negative");
|
|
270
|
+
if (v > 0xffffffffffffffffn) throw new Error("VarInt value exceeds 64-bit range");
|
|
271
|
+
let length = 9;
|
|
272
|
+
for (let n = 1; n <= 8; n++) {
|
|
273
|
+
if (n === 7 && !this.allowSevenByte) continue;
|
|
274
|
+
if (v < 1n << BigInt(7 * n)) {
|
|
275
|
+
length = n;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
this.ensureCapacity(length);
|
|
280
|
+
if (length === 9) {
|
|
281
|
+
this.view.setUint8(this.pos, 255);
|
|
282
|
+
this.view.setBigUint64(this.pos + 1, v);
|
|
283
|
+
this.pos += 9;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const prefix = BigInt((1 << length - 1) - 1 << 9 - length) & 0xffn;
|
|
287
|
+
const combined = prefix << BigInt(8 * (length - 1)) | v;
|
|
288
|
+
for (let i = 0; i < length; i++) {
|
|
289
|
+
this.view.setUint8(this.pos + i, Number(combined >> BigInt(8 * (length - 1 - i)) & 0xffn));
|
|
290
|
+
}
|
|
291
|
+
this.pos += length;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
var Draft17BufferWriter = class extends MoqtBufferWriter {
|
|
295
|
+
get allowSevenByte() {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
214
299
|
|
|
215
300
|
// src/core/hex.ts
|
|
216
301
|
var HEX_TABLE = /* @__PURE__ */ Array.from(
|
|
@@ -238,4 +323,8 @@ function hexToBytes(hex) {
|
|
|
238
323
|
|
|
239
324
|
|
|
240
325
|
|
|
241
|
-
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
exports.DecodeError = DecodeError; exports.BufferReader = BufferReader; exports.MoqtBufferReader = MoqtBufferReader; exports.Draft17BufferReader = Draft17BufferReader; exports.BufferWriter = BufferWriter; exports.MoqtBufferWriter = MoqtBufferWriter; exports.Draft17BufferWriter = Draft17BufferWriter; exports.bytesToHex = bytesToHex; exports.hexToBytes = hexToBytes;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
BufferReader,
|
|
3
|
-
BufferWriter,
|
|
4
2
|
DecodeError,
|
|
3
|
+
MoqtBufferReader,
|
|
4
|
+
MoqtBufferWriter,
|
|
5
5
|
bytesToHex,
|
|
6
6
|
hexToBytes
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-KLPWJU6W.js";
|
|
8
8
|
|
|
9
9
|
// src/drafts/draft18/messages.ts
|
|
10
10
|
var MSG_REQUEST_UPDATE = 0x02n;
|
|
@@ -108,7 +108,7 @@ function isValidSubgroupType(streamType) {
|
|
|
108
108
|
return (streamType & 6) !== 6;
|
|
109
109
|
}
|
|
110
110
|
function encodeSubgroupStream(stream) {
|
|
111
|
-
const w = new
|
|
111
|
+
const w = new MoqtBufferWriter();
|
|
112
112
|
const streamType = stream.headerType;
|
|
113
113
|
w.writeUint8(streamType);
|
|
114
114
|
const propertiesPresent = (streamType & 1) !== 0;
|
|
@@ -129,7 +129,7 @@ function encodeSubgroupStream(stream) {
|
|
|
129
129
|
w.writeVarInt(delta);
|
|
130
130
|
if (propertiesPresent) {
|
|
131
131
|
if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
|
|
132
|
-
const tmpW = new
|
|
132
|
+
const tmpW = new MoqtBufferWriter(32);
|
|
133
133
|
encodeObjectProperties(obj.objectProperties, tmpW);
|
|
134
134
|
const raw = tmpW.finish();
|
|
135
135
|
w.writeVarInt(BigInt(raw.byteLength));
|
|
@@ -149,7 +149,7 @@ function encodeSubgroupStream(stream) {
|
|
|
149
149
|
return w.finish();
|
|
150
150
|
}
|
|
151
151
|
function encodeDatagram(dg) {
|
|
152
|
-
const w = new
|
|
152
|
+
const w = new MoqtBufferWriter();
|
|
153
153
|
const dgType = dg.datagramType;
|
|
154
154
|
w.writeUint8(dgType);
|
|
155
155
|
w.writeVarInt(dg.trackAlias);
|
|
@@ -166,7 +166,7 @@ function encodeDatagram(dg) {
|
|
|
166
166
|
}
|
|
167
167
|
if (propertiesPresent) {
|
|
168
168
|
if (dg.objectProperties && Object.keys(dg.objectProperties).length > 0) {
|
|
169
|
-
const tmpW = new
|
|
169
|
+
const tmpW = new MoqtBufferWriter(32);
|
|
170
170
|
encodeObjectProperties(dg.objectProperties, tmpW);
|
|
171
171
|
const raw = tmpW.finish();
|
|
172
172
|
w.writeVarInt(BigInt(raw.byteLength));
|
|
@@ -183,7 +183,7 @@ function encodeDatagram(dg) {
|
|
|
183
183
|
return w.finish();
|
|
184
184
|
}
|
|
185
185
|
function encodeFetchStream(stream) {
|
|
186
|
-
const w = new
|
|
186
|
+
const w = new MoqtBufferWriter();
|
|
187
187
|
w.writeVarInt(FETCH_STREAM_TYPE);
|
|
188
188
|
w.writeVarInt(stream.requestId);
|
|
189
189
|
let prevGroupId = 0n;
|
|
@@ -205,7 +205,7 @@ function encodeFetchStream(stream) {
|
|
|
205
205
|
if (flags & 16) w.writeUint8(obj.publisherPriority);
|
|
206
206
|
if (flags & 32) {
|
|
207
207
|
if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
|
|
208
|
-
const tmpW = new
|
|
208
|
+
const tmpW = new MoqtBufferWriter(32);
|
|
209
209
|
encodeObjectProperties(obj.objectProperties, tmpW);
|
|
210
210
|
const raw = tmpW.finish();
|
|
211
211
|
w.writeVarInt(BigInt(raw.byteLength));
|
|
@@ -229,7 +229,7 @@ function encodeFetchStream(stream) {
|
|
|
229
229
|
if (flags & 16) w.writeUint8(obj.publisherPriority);
|
|
230
230
|
if (flags & 32) {
|
|
231
231
|
if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
|
|
232
|
-
const tmpW = new
|
|
232
|
+
const tmpW = new MoqtBufferWriter(32);
|
|
233
233
|
encodeObjectProperties(obj.objectProperties, tmpW);
|
|
234
234
|
const raw = tmpW.finish();
|
|
235
235
|
w.writeVarInt(BigInt(raw.byteLength));
|
|
@@ -252,7 +252,7 @@ function encodeFetchStream(stream) {
|
|
|
252
252
|
}
|
|
253
253
|
function decodeSubgroupStream(bytes) {
|
|
254
254
|
try {
|
|
255
|
-
const r = new
|
|
255
|
+
const r = new MoqtBufferReader(bytes);
|
|
256
256
|
const streamType = r.readUint8();
|
|
257
257
|
if (!isValidSubgroupType(streamType)) {
|
|
258
258
|
return {
|
|
@@ -355,7 +355,7 @@ function decodeSubgroupStream(bytes) {
|
|
|
355
355
|
}
|
|
356
356
|
function decodeDatagram(bytes) {
|
|
357
357
|
try {
|
|
358
|
-
const r = new
|
|
358
|
+
const r = new MoqtBufferReader(bytes);
|
|
359
359
|
const dgType = r.readUint8();
|
|
360
360
|
const objectIdAbsent = (dgType & 4) !== 0;
|
|
361
361
|
const endOfGroup = (dgType & 2) !== 0;
|
|
@@ -411,7 +411,7 @@ function decodeDatagram(bytes) {
|
|
|
411
411
|
}
|
|
412
412
|
function decodeFetchStream(bytes) {
|
|
413
413
|
try {
|
|
414
|
-
const r = new
|
|
414
|
+
const r = new MoqtBufferReader(bytes);
|
|
415
415
|
const streamType = r.readVarInt();
|
|
416
416
|
if (streamType !== FETCH_STREAM_TYPE) {
|
|
417
417
|
return {
|
|
@@ -659,7 +659,7 @@ function createSubgroupStreamDecoder() {
|
|
|
659
659
|
buffer = newBuffer;
|
|
660
660
|
if (!headerEmitted) {
|
|
661
661
|
try {
|
|
662
|
-
const r = new
|
|
662
|
+
const r = new MoqtBufferReader(buffer.subarray(offset));
|
|
663
663
|
const streamType = r.readUint8();
|
|
664
664
|
if (!isValidSubgroupType(streamType)) {
|
|
665
665
|
controller.error(
|
|
@@ -704,7 +704,7 @@ function createSubgroupStreamDecoder() {
|
|
|
704
704
|
}
|
|
705
705
|
while (offset < buffer.length) {
|
|
706
706
|
try {
|
|
707
|
-
const r = new
|
|
707
|
+
const r = new MoqtBufferReader(buffer.subarray(offset));
|
|
708
708
|
const delta = r.readVarInt();
|
|
709
709
|
let objectId;
|
|
710
710
|
if (firstObject) {
|
|
@@ -764,7 +764,7 @@ function createFetchStreamDecoder() {
|
|
|
764
764
|
buffer = newBuffer;
|
|
765
765
|
if (!headerEmitted) {
|
|
766
766
|
try {
|
|
767
|
-
const r = new
|
|
767
|
+
const r = new MoqtBufferReader(buffer.subarray(offset));
|
|
768
768
|
const streamType = r.readVarInt();
|
|
769
769
|
if (streamType !== FETCH_STREAM_TYPE) {
|
|
770
770
|
controller.error(
|
|
@@ -790,7 +790,7 @@ function createFetchStreamDecoder() {
|
|
|
790
790
|
}
|
|
791
791
|
while (offset < buffer.length) {
|
|
792
792
|
try {
|
|
793
|
-
const r = new
|
|
793
|
+
const r = new MoqtBufferReader(buffer.subarray(offset));
|
|
794
794
|
const flags = Number(r.readVarInt());
|
|
795
795
|
const objectIdPresent = (flags & 4) !== 0;
|
|
796
796
|
const groupIdPresent = (flags & 8) !== 0;
|
|
@@ -939,7 +939,7 @@ function encodeSetupOptions(opts, writer) {
|
|
|
939
939
|
entries.push({
|
|
940
940
|
type: SETUP_OPT_AUTHORIZATION_TOKEN,
|
|
941
941
|
encode: (w) => {
|
|
942
|
-
const tmpW = new
|
|
942
|
+
const tmpW = new MoqtBufferWriter(64);
|
|
943
943
|
encodeAuthorizationToken(opts.authorization_token, tmpW);
|
|
944
944
|
const raw = tmpW.finish();
|
|
945
945
|
w.writeVarInt(BigInt(raw.byteLength));
|
|
@@ -981,7 +981,7 @@ function encodeSetupOptions(opts, writer) {
|
|
|
981
981
|
encode: (w) => {
|
|
982
982
|
if (id % 2n === 0n) {
|
|
983
983
|
const raw = hexToBytes(u.raw_hex);
|
|
984
|
-
const tmpReader = new
|
|
984
|
+
const tmpReader = new MoqtBufferReader(raw);
|
|
985
985
|
w.writeVarInt(tmpReader.readVarInt());
|
|
986
986
|
} else {
|
|
987
987
|
const raw = hexToBytes(u.raw_hex);
|
|
@@ -1013,7 +1013,7 @@ function decodeSetupOptions(reader, payloadEnd) {
|
|
|
1013
1013
|
if (optType === SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE) {
|
|
1014
1014
|
result.max_auth_token_cache_size = value;
|
|
1015
1015
|
} else {
|
|
1016
|
-
const tmpWriter = new
|
|
1016
|
+
const tmpWriter = new MoqtBufferWriter(16);
|
|
1017
1017
|
tmpWriter.writeVarInt(value);
|
|
1018
1018
|
const raw = tmpWriter.finish();
|
|
1019
1019
|
unknown.push({
|
|
@@ -1028,7 +1028,7 @@ function decodeSetupOptions(reader, payloadEnd) {
|
|
|
1028
1028
|
if (optType === SETUP_OPT_PATH) {
|
|
1029
1029
|
result.path = textDecoder.decode(bytes);
|
|
1030
1030
|
} else if (optType === SETUP_OPT_AUTHORIZATION_TOKEN) {
|
|
1031
|
-
result.authorization_token = decodeAuthorizationToken(new
|
|
1031
|
+
result.authorization_token = decodeAuthorizationToken(new MoqtBufferReader(bytes));
|
|
1032
1032
|
} else if (optType === SETUP_OPT_AUTHORITY) {
|
|
1033
1033
|
result.authority = textDecoder.decode(bytes);
|
|
1034
1034
|
} else if (optType === SETUP_OPT_MOQT_IMPLEMENTATION) {
|
|
@@ -1115,7 +1115,7 @@ function encodeParams(params, writer) {
|
|
|
1115
1115
|
entries.push({
|
|
1116
1116
|
type: PARAM_AUTHORIZATION_TOKEN,
|
|
1117
1117
|
encode: (w) => {
|
|
1118
|
-
const tmpW = new
|
|
1118
|
+
const tmpW = new MoqtBufferWriter(64);
|
|
1119
1119
|
encodeAuthorizationToken(params.authorization_token, tmpW);
|
|
1120
1120
|
const raw = tmpW.finish();
|
|
1121
1121
|
w.writeVarInt(BigInt(raw.byteLength));
|
|
@@ -1145,7 +1145,7 @@ function encodeParams(params, writer) {
|
|
|
1145
1145
|
entries.push({
|
|
1146
1146
|
type: PARAM_LARGEST_OBJECT,
|
|
1147
1147
|
encode: (w) => {
|
|
1148
|
-
const tmpW = new
|
|
1148
|
+
const tmpW = new MoqtBufferWriter(16);
|
|
1149
1149
|
tmpW.writeVarInt(params.largest_object.group);
|
|
1150
1150
|
tmpW.writeVarInt(params.largest_object.object);
|
|
1151
1151
|
const raw = tmpW.finish();
|
|
@@ -1177,7 +1177,7 @@ function encodeParams(params, writer) {
|
|
|
1177
1177
|
type: PARAM_SUBSCRIPTION_FILTER,
|
|
1178
1178
|
encode: (w) => {
|
|
1179
1179
|
const f = params.subscription_filter;
|
|
1180
|
-
const tmpW = new
|
|
1180
|
+
const tmpW = new MoqtBufferWriter(32);
|
|
1181
1181
|
tmpW.writeVarInt(f.filter_type);
|
|
1182
1182
|
if (f.filter_type === 3n || f.filter_type === 4n) {
|
|
1183
1183
|
tmpW.writeVarInt(f.start_group);
|
|
@@ -1208,7 +1208,7 @@ function encodeParams(params, writer) {
|
|
|
1208
1208
|
entries.push({
|
|
1209
1209
|
type: PARAM_TRACK_NAMESPACE_PREFIX,
|
|
1210
1210
|
encode: (w) => {
|
|
1211
|
-
const tmpW = new
|
|
1211
|
+
const tmpW = new MoqtBufferWriter(32);
|
|
1212
1212
|
encodeNamespaceTuple(params.track_namespace_prefix, tmpW);
|
|
1213
1213
|
const raw = tmpW.finish();
|
|
1214
1214
|
w.writeVarInt(BigInt(raw.byteLength));
|
|
@@ -1251,7 +1251,7 @@ function decodeParams(reader) {
|
|
|
1251
1251
|
} else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
|
|
1252
1252
|
const length = Number(reader.readVarInt());
|
|
1253
1253
|
const bytes = reader.readBytes(length);
|
|
1254
|
-
result.authorization_token = decodeAuthorizationToken(new
|
|
1254
|
+
result.authorization_token = decodeAuthorizationToken(new MoqtBufferReader(bytes));
|
|
1255
1255
|
} else if (paramType === PARAM_RENDEZVOUS_TIMEOUT) {
|
|
1256
1256
|
result.rendezvous_timeout = reader.readVarInt();
|
|
1257
1257
|
} else if (paramType === PARAM_SUBGROUP_DELIVERY_TIMEOUT) {
|
|
@@ -1294,11 +1294,11 @@ function decodeParams(reader) {
|
|
|
1294
1294
|
} else if (paramType === PARAM_TRACK_NAMESPACE_PREFIX) {
|
|
1295
1295
|
const length = Number(reader.readVarInt());
|
|
1296
1296
|
const bytes = reader.readBytes(length);
|
|
1297
|
-
result.track_namespace_prefix = decodeNamespaceTuple(new
|
|
1297
|
+
result.track_namespace_prefix = decodeNamespaceTuple(new MoqtBufferReader(bytes));
|
|
1298
1298
|
} else {
|
|
1299
1299
|
if (paramType % 2n === 0n) {
|
|
1300
1300
|
const value = reader.readVarInt();
|
|
1301
|
-
const tmpWriter = new
|
|
1301
|
+
const tmpWriter = new MoqtBufferWriter(16);
|
|
1302
1302
|
tmpWriter.writeVarInt(value);
|
|
1303
1303
|
const raw = tmpWriter.finish();
|
|
1304
1304
|
unknown.push({
|
|
@@ -1383,7 +1383,7 @@ function encodeTrackProperties(props, writer) {
|
|
|
1383
1383
|
encode: (w) => {
|
|
1384
1384
|
if (id % 2n === 0n) {
|
|
1385
1385
|
const raw = hexToBytes(u.raw_hex);
|
|
1386
|
-
const tmpReader = new
|
|
1386
|
+
const tmpReader = new MoqtBufferReader(raw);
|
|
1387
1387
|
w.writeVarInt(tmpReader.readVarInt());
|
|
1388
1388
|
} else {
|
|
1389
1389
|
const raw = hexToBytes(u.raw_hex);
|
|
@@ -1425,7 +1425,7 @@ function decodeTrackProperties(reader, payloadEnd) {
|
|
|
1425
1425
|
} else if (propType === TPROP_DYNAMIC_GROUPS) {
|
|
1426
1426
|
result.dynamic_groups = value;
|
|
1427
1427
|
} else {
|
|
1428
|
-
const tmpWriter = new
|
|
1428
|
+
const tmpWriter = new MoqtBufferWriter(16);
|
|
1429
1429
|
tmpWriter.writeVarInt(value);
|
|
1430
1430
|
const raw = tmpWriter.finish();
|
|
1431
1431
|
unknown.push({
|
|
@@ -1774,13 +1774,13 @@ function encodeMessage(message) {
|
|
|
1774
1774
|
if (typeId === void 0) {
|
|
1775
1775
|
throw new Error(`Unknown message type: ${message.type}`);
|
|
1776
1776
|
}
|
|
1777
|
-
const payloadWriter = new
|
|
1777
|
+
const payloadWriter = new MoqtBufferWriter();
|
|
1778
1778
|
encodePayload(message, payloadWriter);
|
|
1779
1779
|
const payload = payloadWriter.finishView();
|
|
1780
1780
|
if (payload.byteLength > 65535) {
|
|
1781
1781
|
throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
|
|
1782
1782
|
}
|
|
1783
|
-
const writer = new
|
|
1783
|
+
const writer = new MoqtBufferWriter(payload.byteLength + 16);
|
|
1784
1784
|
writer.writeVarInt(typeId);
|
|
1785
1785
|
writer.writeUint8(payload.byteLength >> 8 & 255);
|
|
1786
1786
|
writer.writeUint8(payload.byteLength & 255);
|
|
@@ -1833,13 +1833,13 @@ function encodePayload(msg, w) {
|
|
|
1833
1833
|
}
|
|
1834
1834
|
function decodeMessage(bytes) {
|
|
1835
1835
|
try {
|
|
1836
|
-
const reader = new
|
|
1836
|
+
const reader = new MoqtBufferReader(bytes);
|
|
1837
1837
|
const typeId = reader.readVarInt();
|
|
1838
1838
|
const lenHi = reader.readUint8();
|
|
1839
1839
|
const lenLo = reader.readUint8();
|
|
1840
1840
|
const payloadLength = lenHi << 8 | lenLo;
|
|
1841
1841
|
const payloadBytes = reader.readBytes(payloadLength);
|
|
1842
|
-
const payloadReader = new
|
|
1842
|
+
const payloadReader = new MoqtBufferReader(payloadBytes);
|
|
1843
1843
|
let message;
|
|
1844
1844
|
if (typeId === MSG_SETUP) {
|
|
1845
1845
|
message = decodeSetupPayload(payloadReader, payloadLength);
|