@moqtap/codec 0.1.0 → 0.2.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 +99 -95
- package/dist/chunk-4RIXXEII.js +1275 -0
- package/dist/chunk-4XYGE53S.cjs +698 -0
- package/dist/chunk-4YJANAXU.cjs +1109 -0
- package/dist/chunk-6AEHWULA.cjs +641 -0
- package/dist/chunk-7DUBLRXC.js +680 -0
- package/dist/{chunk-WNTXF3DE.cjs → chunk-7IVGHMKJ.cjs} +164 -62
- package/dist/{chunk-YBSEOSSP.js → chunk-A27S7HW7.js} +5 -1
- package/dist/chunk-BISI45MN.cjs +680 -0
- package/dist/{chunk-3BSZ55L3.cjs → chunk-BPNL5YFQ.cjs} +158 -24
- package/dist/chunk-CXDHOMHG.js +1097 -0
- package/dist/chunk-DUBCL3WF.cjs +749 -0
- package/dist/chunk-DWK5ZQZ4.js +642 -0
- package/dist/chunk-E6E3NQYU.js +680 -0
- package/dist/chunk-EFM5T7OM.js +698 -0
- package/dist/chunk-ENURAVHI.cjs +680 -0
- package/dist/{chunk-5WFXFLL4.cjs → chunk-FUFTMAQD.cjs} +96 -63
- package/dist/{chunk-2NARXGVA.cjs → chunk-FWISIR26.cjs} +5 -1
- package/dist/{chunk-YPXLV5YK.js → chunk-FXZ2MYKJ.js} +376 -38
- package/dist/chunk-G26SJ6XS.cjs +1341 -0
- package/dist/chunk-G7GI7LJA.js +737 -0
- package/dist/chunk-GXEW4COZ.cjs +737 -0
- package/dist/chunk-HSVYF6XX.cjs +1361 -0
- package/dist/chunk-IBVM4DMJ.cjs +1097 -0
- package/dist/chunk-IV2H5CFI.cjs +1275 -0
- package/dist/chunk-IV2HRJVT.js +1198 -0
- package/dist/chunk-JSQM2MG3.js +680 -0
- package/dist/chunk-K4OLITS2.cjs +1055 -0
- package/dist/{chunk-UOBWHJA5.js → chunk-KFTCU2P6.js} +2 -3
- package/dist/chunk-LH4NTURO.js +1361 -0
- package/dist/{chunk-DC4L6ZIT.js → chunk-MFAP7R6L.js} +154 -20
- package/dist/chunk-NGVE2RZT.js +1097 -0
- package/dist/chunk-NUX5BHWO.js +1341 -0
- package/dist/chunk-PJRA2TQ5.js +1055 -0
- package/dist/chunk-RVJAGE4S.cjs +1198 -0
- package/dist/{chunk-QYG6KGOV.cjs → chunk-RWQ43Z4F.cjs} +2 -3
- package/dist/chunk-RZHAPEXO.js +749 -0
- package/dist/chunk-ST24APEO.js +1109 -0
- package/dist/chunk-SYHW3FLI.cjs +642 -0
- package/dist/chunk-TLYNOOQP.cjs +432 -0
- package/dist/{chunk-23YG7F46.js → chunk-TMNGRIPL.js} +153 -51
- package/dist/{chunk-IQPDRQVC.js → chunk-U2B3B42P.js} +62 -29
- package/dist/chunk-UNS34PTA.cjs +680 -0
- package/dist/chunk-UR6JKS56.js +432 -0
- package/dist/{chunk-GDRGWFEK.cjs → chunk-UYXTY6ZQ.cjs} +376 -38
- package/dist/chunk-XUUCOLWU.cjs +1097 -0
- package/dist/chunk-YG5KJESI.js +641 -0
- package/dist/chunk-ZBKE2QRQ.js +1401 -0
- package/dist/chunk-ZSPO2GF2.cjs +1401 -0
- package/dist/codec-95k8CAu5.d.cts +35 -0
- package/dist/codec-AFuOxfsO.d.ts +60 -0
- package/dist/codec-B-UJ5Iow.d.cts +75 -0
- package/dist/codec-BC5jfvMb.d.ts +35 -0
- package/dist/codec-BECYPfY8.d.ts +35 -0
- package/dist/codec-BsPU1vNC.d.ts +39 -0
- package/dist/codec-BvpuF-6u.d.cts +39 -0
- package/dist/codec-C8jZI5Cx.d.cts +39 -0
- package/dist/codec-CAevkgf5.d.cts +33 -0
- package/dist/codec-CSUqCrRs.d.ts +39 -0
- package/dist/codec-C_HMXNK_.d.ts +33 -0
- package/dist/{codec-CTvFtQQI.d.cts → codec-CpuvYTSV.d.cts} +5 -5
- package/dist/codec-D0x8-SCw.d.cts +35 -0
- package/dist/codec-D7ARhpG1.d.ts +75 -0
- package/dist/codec-DNAUGshO.d.cts +60 -0
- package/dist/codec-DPx_QNn0.d.ts +31 -0
- package/dist/{codec-qPzfmLNu.d.ts → codec-DRhCx_hw.d.ts} +5 -5
- package/dist/codec-Db7YPe3l.d.ts +31 -0
- package/dist/codec-axkJpb7D.d.cts +31 -0
- package/dist/codec-ujAbFaep.d.cts +31 -0
- package/dist/draft10-session.cjs +6 -0
- package/dist/draft10-session.d.cts +8 -0
- package/dist/draft10-session.d.ts +8 -0
- package/dist/draft10-session.js +6 -0
- package/dist/draft10.cjs +115 -0
- package/dist/draft10.d.cts +95 -0
- package/dist/draft10.d.ts +95 -0
- package/dist/draft10.js +115 -0
- package/dist/draft11-session.cjs +6 -0
- package/dist/draft11-session.d.cts +8 -0
- package/dist/draft11-session.d.ts +8 -0
- package/dist/draft11-session.js +6 -0
- package/dist/draft11.cjs +109 -0
- package/dist/draft11.d.cts +99 -0
- package/dist/draft11.d.ts +99 -0
- package/dist/draft11.js +109 -0
- package/dist/draft12-session.cjs +6 -0
- package/dist/draft12-session.d.cts +8 -0
- package/dist/draft12-session.d.ts +8 -0
- package/dist/draft12-session.js +6 -0
- package/dist/draft12.cjs +117 -0
- package/dist/draft12.d.cts +106 -0
- package/dist/draft12.d.ts +106 -0
- package/dist/draft12.js +117 -0
- package/dist/draft13-session.cjs +6 -0
- package/dist/draft13-session.d.cts +8 -0
- package/dist/draft13-session.d.ts +8 -0
- package/dist/draft13-session.js +6 -0
- package/dist/draft13.cjs +119 -0
- package/dist/draft13.d.cts +108 -0
- package/dist/draft13.d.ts +108 -0
- package/dist/draft13.js +119 -0
- package/dist/draft14-session.cjs +2 -2
- package/dist/draft14-session.d.cts +4 -4
- package/dist/draft14-session.d.ts +4 -4
- package/dist/draft14-session.js +1 -1
- package/dist/draft14.cjs +4 -4
- package/dist/draft14.d.cts +27 -15
- package/dist/draft14.d.ts +27 -15
- package/dist/draft14.js +3 -3
- package/dist/draft15-session.cjs +6 -0
- package/dist/draft15-session.d.cts +8 -0
- package/dist/draft15-session.d.ts +8 -0
- package/dist/draft15-session.js +6 -0
- package/dist/draft15.cjs +111 -0
- package/dist/draft15.d.cts +93 -0
- package/dist/draft15.d.ts +93 -0
- package/dist/draft15.js +111 -0
- package/dist/draft16-session.cjs +6 -0
- package/dist/draft16-session.d.cts +8 -0
- package/dist/draft16-session.d.ts +8 -0
- package/dist/draft16-session.js +6 -0
- package/dist/draft16.cjs +113 -0
- package/dist/draft16.d.cts +94 -0
- package/dist/draft16.d.ts +94 -0
- package/dist/draft16.js +113 -0
- package/dist/draft17-session.cjs +8 -0
- package/dist/draft17-session.d.cts +51 -0
- package/dist/draft17-session.d.ts +51 -0
- package/dist/draft17-session.js +8 -0
- package/dist/draft17.cjs +99 -0
- package/dist/draft17.d.cts +40 -0
- package/dist/draft17.d.ts +40 -0
- package/dist/draft17.js +99 -0
- package/dist/draft7-session.cjs +3 -3
- package/dist/draft7-session.d.cts +3 -3
- package/dist/draft7-session.d.ts +3 -3
- package/dist/draft7-session.js +2 -2
- package/dist/draft7.cjs +6 -6
- package/dist/draft7.d.cts +10 -10
- package/dist/draft7.d.ts +10 -10
- package/dist/draft7.js +3 -3
- package/dist/draft8-session.cjs +6 -0
- package/dist/draft8-session.d.cts +8 -0
- package/dist/draft8-session.d.ts +8 -0
- package/dist/draft8-session.js +6 -0
- package/dist/draft8.cjs +115 -0
- package/dist/draft8.d.cts +95 -0
- package/dist/draft8.d.ts +95 -0
- package/dist/draft8.js +115 -0
- package/dist/draft9-session.cjs +6 -0
- package/dist/draft9-session.d.cts +8 -0
- package/dist/draft9-session.d.ts +8 -0
- package/dist/draft9-session.js +6 -0
- package/dist/draft9.cjs +115 -0
- package/dist/draft9.d.cts +95 -0
- package/dist/draft9.d.ts +95 -0
- package/dist/draft9.js +115 -0
- package/dist/index.cjs +79 -7
- package/dist/index.d.cts +71 -8
- package/dist/index.d.ts +71 -8
- package/dist/index.js +77 -5
- package/dist/{session-types-B9NIf7_F.d.ts → session-types-CJIFbTPd.d.ts} +20 -20
- package/dist/{session-types-CCo-oA-d.d.cts → session-types-Cbq8IGCP.d.cts} +20 -20
- package/dist/session.cjs +5 -5
- package/dist/session.d.cts +3 -3
- package/dist/session.d.ts +3 -3
- package/dist/session.js +5 -5
- package/dist/types-4VxSL2Ho.d.cts +261 -0
- package/dist/types-4VxSL2Ho.d.ts +261 -0
- package/dist/types-B2afJZM-.d.cts +236 -0
- package/dist/types-B2afJZM-.d.ts +236 -0
- package/dist/{types-CIk5W10V.d.ts → types-BTFeKYCb.d.cts} +37 -37
- package/dist/{types-CIk5W10V.d.cts → types-BTFeKYCb.d.ts} +37 -37
- package/dist/types-Bg6QYNVt.d.cts +290 -0
- package/dist/types-Bg6QYNVt.d.ts +290 -0
- package/dist/types-C_1HrqBl.d.cts +306 -0
- package/dist/types-C_1HrqBl.d.ts +306 -0
- package/dist/types-Cw4WE9dh.d.cts +261 -0
- package/dist/types-Cw4WE9dh.d.ts +261 -0
- package/dist/types-D5gNQiDj.d.cts +261 -0
- package/dist/types-D5gNQiDj.d.ts +261 -0
- package/dist/types-DqCDFqgB.d.cts +230 -0
- package/dist/types-DqCDFqgB.d.ts +230 -0
- package/dist/types-ERexTpT8.d.cts +217 -0
- package/dist/types-ERexTpT8.d.ts +217 -0
- package/dist/{types-ClXELFGN.d.cts → types-QNXoxC9Y.d.cts} +36 -41
- package/dist/{types-ClXELFGN.d.ts → types-QNXoxC9Y.d.ts} +36 -41
- package/dist/types-r-CasCf1.d.cts +262 -0
- package/dist/types-r-CasCf1.d.ts +262 -0
- package/package.json +116 -8
- package/src/core/buffer-reader.ts +16 -9
- package/src/core/buffer-writer.ts +2 -2
- package/src/core/errors.ts +1 -1
- package/src/core/session-types.ts +28 -41
- package/src/core/types.ts +92 -75
- package/src/drafts/draft07/announce-fsm.ts +1 -1
- package/src/drafts/draft07/codec.ts +235 -118
- package/src/drafts/draft07/index.ts +43 -44
- package/src/drafts/draft07/messages.ts +1 -1
- package/src/drafts/draft07/parameters.ts +2 -2
- package/src/drafts/draft07/rules.ts +67 -38
- package/src/drafts/draft07/session-fsm.ts +330 -117
- package/src/drafts/draft07/session.ts +10 -10
- package/src/drafts/draft07/subscription-fsm.ts +1 -1
- package/src/drafts/draft07/varint.ts +4 -4
- package/src/drafts/draft08/codec.ts +1254 -0
- package/src/drafts/draft08/index.ts +125 -0
- package/src/drafts/draft08/messages.ts +72 -0
- package/src/drafts/draft08/rules.ts +91 -0
- package/src/drafts/draft08/session-fsm.ts +718 -0
- package/src/drafts/draft08/session.ts +26 -0
- package/src/drafts/draft08/types.ts +377 -0
- package/src/drafts/draft09/codec.ts +1235 -0
- package/src/drafts/draft09/index.ts +125 -0
- package/src/drafts/draft09/messages.ts +72 -0
- package/src/drafts/draft09/rules.ts +91 -0
- package/src/drafts/draft09/session-fsm.ts +718 -0
- package/src/drafts/draft09/session.ts +26 -0
- package/src/drafts/draft09/types.ts +376 -0
- package/src/drafts/draft10/codec.ts +1235 -0
- package/src/drafts/draft10/index.ts +125 -0
- package/src/drafts/draft10/messages.ts +72 -0
- package/src/drafts/draft10/rules.ts +91 -0
- package/src/drafts/draft10/session-fsm.ts +718 -0
- package/src/drafts/draft10/session.ts +26 -0
- package/src/drafts/draft10/types.ts +376 -0
- package/src/drafts/draft11/codec.ts +1198 -0
- package/src/drafts/draft11/index.ts +123 -0
- package/src/drafts/draft11/messages.ts +71 -0
- package/src/drafts/draft11/rules.ts +100 -0
- package/src/drafts/draft11/session-fsm.ts +758 -0
- package/src/drafts/draft11/session.ts +26 -0
- package/src/drafts/draft11/types.ts +375 -0
- package/src/drafts/draft12/codec.ts +1354 -0
- package/src/drafts/draft12/index.ts +130 -0
- package/src/drafts/draft12/messages.ts +84 -0
- package/src/drafts/draft12/rules.ts +106 -0
- package/src/drafts/draft12/session-fsm.ts +805 -0
- package/src/drafts/draft12/session.ts +26 -0
- package/src/drafts/draft12/types.ts +414 -0
- package/src/drafts/draft13/codec.ts +1438 -0
- package/src/drafts/draft13/index.ts +132 -0
- package/src/drafts/draft13/messages.ts +86 -0
- package/src/drafts/draft13/rules.ts +108 -0
- package/src/drafts/draft13/session-fsm.ts +819 -0
- package/src/drafts/draft13/session.ts +26 -0
- package/src/drafts/draft13/types.ts +433 -0
- package/src/drafts/draft14/codec.ts +339 -189
- package/src/drafts/draft14/index.ts +103 -108
- package/src/drafts/draft14/messages.ts +61 -61
- package/src/drafts/draft14/rules.ts +77 -34
- package/src/drafts/draft14/session-fsm.ts +640 -147
- package/src/drafts/draft14/session.ts +13 -13
- package/src/drafts/draft14/types.ts +68 -68
- package/src/drafts/draft15/codec.ts +1661 -0
- package/src/drafts/draft15/index.ts +121 -0
- package/src/drafts/draft15/messages.ts +64 -0
- package/src/drafts/draft15/rules.ts +95 -0
- package/src/drafts/draft15/session-fsm.ts +687 -0
- package/src/drafts/draft15/session.ts +26 -0
- package/src/drafts/draft15/types.ts +336 -0
- package/src/drafts/draft16/codec.ts +1623 -0
- package/src/drafts/draft16/index.ts +123 -0
- package/src/drafts/draft16/messages.ts +67 -0
- package/src/drafts/draft16/rules.ts +96 -0
- package/src/drafts/draft16/session-fsm.ts +682 -0
- package/src/drafts/draft16/session.ts +26 -0
- package/src/drafts/draft16/types.ts +354 -0
- package/src/drafts/draft17/codec.ts +1621 -0
- package/src/drafts/draft17/index.ts +105 -0
- package/src/drafts/draft17/messages.ts +53 -0
- package/src/drafts/draft17/rules.ts +85 -0
- package/src/drafts/draft17/session-fsm.ts +437 -0
- package/src/drafts/draft17/session.ts +15 -0
- package/src/drafts/draft17/types.ts +310 -0
- package/src/index.ts +283 -33
- package/src/session.ts +20 -20
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { BufferReader } from
|
|
2
|
-
import { BufferWriter } from
|
|
3
|
-
import { DecodeError } from '../../core/types.js';
|
|
1
|
+
import { BufferReader } from "../../core/buffer-reader.js";
|
|
2
|
+
import { BufferWriter } from "../../core/buffer-writer.js";
|
|
4
3
|
import type {
|
|
4
|
+
Announce,
|
|
5
|
+
AnnounceCancel,
|
|
6
|
+
AnnounceError,
|
|
7
|
+
AnnounceOk,
|
|
8
|
+
ClientSetup,
|
|
5
9
|
Codec,
|
|
6
10
|
DecodeResult,
|
|
11
|
+
Fetch,
|
|
12
|
+
FetchCancel,
|
|
13
|
+
FetchError,
|
|
14
|
+
FetchOk,
|
|
7
15
|
FilterType,
|
|
16
|
+
GoAway,
|
|
8
17
|
GroupOrderValue,
|
|
18
|
+
MaxSubscribeId,
|
|
9
19
|
MoqtMessage,
|
|
10
20
|
MoqtMessageType,
|
|
11
|
-
ClientSetup,
|
|
12
|
-
ServerSetup,
|
|
13
|
-
Subscribe,
|
|
14
|
-
SubscribeOk,
|
|
15
|
-
SubscribeError,
|
|
16
|
-
SubscribeDone,
|
|
17
|
-
SubscribeUpdate,
|
|
18
|
-
Unsubscribe,
|
|
19
|
-
Announce,
|
|
20
|
-
AnnounceOk,
|
|
21
|
-
AnnounceError,
|
|
22
|
-
AnnounceCancel,
|
|
23
|
-
Unannounce,
|
|
24
|
-
TrackStatusRequest,
|
|
25
|
-
TrackStatus,
|
|
26
|
-
ObjectStream,
|
|
27
21
|
ObjectDatagram,
|
|
28
|
-
|
|
22
|
+
ObjectStream,
|
|
23
|
+
ServerSetup,
|
|
29
24
|
StreamHeaderGroup,
|
|
30
25
|
StreamHeaderSubgroup,
|
|
31
|
-
|
|
26
|
+
StreamHeaderTrack,
|
|
27
|
+
Subscribe,
|
|
32
28
|
SubscribeAnnounces,
|
|
33
|
-
SubscribeAnnouncesOk,
|
|
34
29
|
SubscribeAnnouncesError,
|
|
30
|
+
SubscribeAnnouncesOk,
|
|
31
|
+
SubscribeDone,
|
|
32
|
+
SubscribeError,
|
|
33
|
+
SubscribeOk,
|
|
34
|
+
SubscribeUpdate,
|
|
35
|
+
TrackStatus,
|
|
36
|
+
TrackStatusRequest,
|
|
37
|
+
Unannounce,
|
|
38
|
+
Unsubscribe,
|
|
35
39
|
UnsubscribeAnnounces,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
FetchCancel,
|
|
41
|
-
} from '../../core/types.js';
|
|
42
|
-
import { MESSAGE_TYPE_IDS } from './messages.js';
|
|
43
|
-
import { encodeVarInt, decodeVarInt } from './varint.js';
|
|
40
|
+
} from "../../core/types.js";
|
|
41
|
+
import { DecodeError } from "../../core/types.js";
|
|
42
|
+
import { MESSAGE_TYPE_IDS } from "./messages.js";
|
|
43
|
+
import { decodeVarInt, encodeVarInt } from "./varint.js";
|
|
44
44
|
|
|
45
45
|
// --- FilterType mapping ---
|
|
46
46
|
|
|
@@ -52,10 +52,10 @@ const FILTER_TYPE_TO_WIRE: Record<FilterType, bigint> = {
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
const WIRE_TO_FILTER_TYPE: Map<bigint, FilterType> = new Map([
|
|
55
|
-
[1n,
|
|
56
|
-
[2n,
|
|
57
|
-
[3n,
|
|
58
|
-
[4n,
|
|
55
|
+
[1n, "latest_group"],
|
|
56
|
+
[2n, "latest_object"],
|
|
57
|
+
[3n, "absolute_start"],
|
|
58
|
+
[4n, "absolute_range"],
|
|
59
59
|
]);
|
|
60
60
|
|
|
61
61
|
// --- GroupOrderValue mapping ---
|
|
@@ -67,9 +67,9 @@ const GROUP_ORDER_TO_WIRE: Record<GroupOrderValue, number> = {
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
const WIRE_TO_GROUP_ORDER: Map<number, GroupOrderValue> = new Map([
|
|
70
|
-
[0,
|
|
71
|
-
[1,
|
|
72
|
-
[2,
|
|
70
|
+
[0, "original"],
|
|
71
|
+
[1, "ascending"],
|
|
72
|
+
[2, "descending"],
|
|
73
73
|
]);
|
|
74
74
|
|
|
75
75
|
// --- Encode helpers ---
|
|
@@ -83,7 +83,11 @@ function readGroupOrder(reader: BufferReader): GroupOrderValue {
|
|
|
83
83
|
const wire = reader.readUint8();
|
|
84
84
|
const value = WIRE_TO_GROUP_ORDER.get(wire);
|
|
85
85
|
if (value === undefined) {
|
|
86
|
-
throw new DecodeError(
|
|
86
|
+
throw new DecodeError(
|
|
87
|
+
"CONSTRAINT_VIOLATION",
|
|
88
|
+
`Invalid group order value: ${wire}`,
|
|
89
|
+
reader.offset - 1,
|
|
90
|
+
);
|
|
87
91
|
}
|
|
88
92
|
return value;
|
|
89
93
|
}
|
|
@@ -101,7 +105,11 @@ const DATA_STREAM_TYPE_IDS: ReadonlySet<bigint> = new Set([
|
|
|
101
105
|
// --- Control message type (excludes data stream types) ---
|
|
102
106
|
type ControlMessageType = Exclude<
|
|
103
107
|
MoqtMessageType,
|
|
104
|
-
|
|
108
|
+
| "object_stream"
|
|
109
|
+
| "object_datagram"
|
|
110
|
+
| "stream_header_track"
|
|
111
|
+
| "stream_header_group"
|
|
112
|
+
| "stream_header_subgroup"
|
|
105
113
|
>;
|
|
106
114
|
|
|
107
115
|
// --- Encode functions for each message type (payload only, no type ID) ---
|
|
@@ -127,11 +135,11 @@ function encodeSubscribe(msg: Subscribe, writer: BufferWriter): void {
|
|
|
127
135
|
writer.writeUint8(msg.subscriberPriority);
|
|
128
136
|
writeGroupOrder(writer, msg.groupOrder);
|
|
129
137
|
writer.writeVarInt(FILTER_TYPE_TO_WIRE[msg.filterType]);
|
|
130
|
-
if (msg.filterType ===
|
|
138
|
+
if (msg.filterType === "absolute_start" || msg.filterType === "absolute_range") {
|
|
131
139
|
writer.writeVarInt(msg.startGroup!);
|
|
132
140
|
writer.writeVarInt(msg.startObject!);
|
|
133
141
|
}
|
|
134
|
-
if (msg.filterType ===
|
|
142
|
+
if (msg.filterType === "absolute_range") {
|
|
135
143
|
writer.writeVarInt(msg.endGroup!);
|
|
136
144
|
writer.writeVarInt(msg.endObject!);
|
|
137
145
|
}
|
|
@@ -280,46 +288,45 @@ function encodeFetchCancel(msg: FetchCancel, writer: BufferWriter): void {
|
|
|
280
288
|
}
|
|
281
289
|
|
|
282
290
|
// Data stream encoders (no type+length framing)
|
|
291
|
+
function encodeObjectPayload(
|
|
292
|
+
msg: { objectStatus?: number; payload: Uint8Array },
|
|
293
|
+
writer: BufferWriter,
|
|
294
|
+
): void {
|
|
295
|
+
if (msg.payload.byteLength === 0) {
|
|
296
|
+
writer.writeVarInt(0); // payloadLength = 0 signals objectStatus follows
|
|
297
|
+
writer.writeVarInt(msg.objectStatus ?? 0);
|
|
298
|
+
} else {
|
|
299
|
+
writer.writeVarInt(msg.payload.byteLength);
|
|
300
|
+
writer.writeBytes(msg.payload);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
283
304
|
function encodeObjectStream(msg: ObjectStream, writer: BufferWriter): void {
|
|
284
305
|
writer.writeVarInt(MESSAGE_TYPE_IDS.object_stream);
|
|
285
|
-
writer.writeVarInt(msg.subscribeId);
|
|
286
306
|
writer.writeVarInt(msg.trackAlias);
|
|
287
307
|
writer.writeVarInt(msg.groupId);
|
|
288
308
|
writer.writeVarInt(msg.objectId);
|
|
289
309
|
writer.writeUint8(msg.publisherPriority);
|
|
290
|
-
|
|
291
|
-
writer.writeVarInt(msg.objectStatus);
|
|
292
|
-
} else {
|
|
293
|
-
writer.writeVarInt(0);
|
|
294
|
-
}
|
|
295
|
-
writer.writeBytes(msg.payload);
|
|
310
|
+
encodeObjectPayload(msg, writer);
|
|
296
311
|
}
|
|
297
312
|
|
|
298
313
|
function encodeObjectDatagram(msg: ObjectDatagram, writer: BufferWriter): void {
|
|
299
314
|
writer.writeVarInt(MESSAGE_TYPE_IDS.object_datagram);
|
|
300
|
-
writer.writeVarInt(msg.subscribeId);
|
|
301
315
|
writer.writeVarInt(msg.trackAlias);
|
|
302
316
|
writer.writeVarInt(msg.groupId);
|
|
303
317
|
writer.writeVarInt(msg.objectId);
|
|
304
318
|
writer.writeUint8(msg.publisherPriority);
|
|
305
|
-
|
|
306
|
-
writer.writeVarInt(msg.objectStatus);
|
|
307
|
-
} else {
|
|
308
|
-
writer.writeVarInt(0);
|
|
309
|
-
}
|
|
310
|
-
writer.writeBytes(msg.payload);
|
|
319
|
+
encodeObjectPayload(msg, writer);
|
|
311
320
|
}
|
|
312
321
|
|
|
313
322
|
function encodeStreamHeaderTrack(msg: StreamHeaderTrack, writer: BufferWriter): void {
|
|
314
323
|
writer.writeVarInt(MESSAGE_TYPE_IDS.stream_header_track);
|
|
315
|
-
writer.writeVarInt(msg.subscribeId);
|
|
316
324
|
writer.writeVarInt(msg.trackAlias);
|
|
317
325
|
writer.writeUint8(msg.publisherPriority);
|
|
318
326
|
}
|
|
319
327
|
|
|
320
328
|
function encodeStreamHeaderGroup(msg: StreamHeaderGroup, writer: BufferWriter): void {
|
|
321
329
|
writer.writeVarInt(MESSAGE_TYPE_IDS.stream_header_group);
|
|
322
|
-
writer.writeVarInt(msg.subscribeId);
|
|
323
330
|
writer.writeVarInt(msg.trackAlias);
|
|
324
331
|
writer.writeVarInt(msg.groupId);
|
|
325
332
|
writer.writeUint8(msg.publisherPriority);
|
|
@@ -327,7 +334,6 @@ function encodeStreamHeaderGroup(msg: StreamHeaderGroup, writer: BufferWriter):
|
|
|
327
334
|
|
|
328
335
|
function encodeStreamHeaderSubgroup(msg: StreamHeaderSubgroup, writer: BufferWriter): void {
|
|
329
336
|
writer.writeVarInt(MESSAGE_TYPE_IDS.stream_header_subgroup);
|
|
330
|
-
writer.writeVarInt(msg.subscribeId);
|
|
331
337
|
writer.writeVarInt(msg.trackAlias);
|
|
332
338
|
writer.writeVarInt(msg.groupId);
|
|
333
339
|
writer.writeVarInt(msg.subgroupId);
|
|
@@ -356,7 +362,10 @@ const controlEncoders: Record<ControlMessageType, (msg: never, writer: BufferWri
|
|
|
356
362
|
goaway: encodeGoAway as (msg: never, writer: BufferWriter) => void,
|
|
357
363
|
subscribe_announces: encodeSubscribeAnnounces as (msg: never, writer: BufferWriter) => void,
|
|
358
364
|
subscribe_announces_ok: encodeSubscribeAnnouncesOk as (msg: never, writer: BufferWriter) => void,
|
|
359
|
-
subscribe_announces_error: encodeSubscribeAnnouncesError as (
|
|
365
|
+
subscribe_announces_error: encodeSubscribeAnnouncesError as (
|
|
366
|
+
msg: never,
|
|
367
|
+
writer: BufferWriter,
|
|
368
|
+
) => void,
|
|
360
369
|
unsubscribe_announces: encodeUnsubscribeAnnounces as (msg: never, writer: BufferWriter) => void,
|
|
361
370
|
max_subscribe_id: encodeMaxSubscribeId as (msg: never, writer: BufferWriter) => void,
|
|
362
371
|
fetch: encodeFetch as (msg: never, writer: BufferWriter) => void,
|
|
@@ -366,7 +375,9 @@ const controlEncoders: Record<ControlMessageType, (msg: never, writer: BufferWri
|
|
|
366
375
|
};
|
|
367
376
|
|
|
368
377
|
// Data stream encoders (write type + fields directly, no length framing)
|
|
369
|
-
const dataStreamEncoders: Partial<
|
|
378
|
+
const dataStreamEncoders: Partial<
|
|
379
|
+
Record<MoqtMessageType, (msg: never, writer: BufferWriter) => void>
|
|
380
|
+
> = {
|
|
370
381
|
object_stream: encodeObjectStream as (msg: never, writer: BufferWriter) => void,
|
|
371
382
|
object_datagram: encodeObjectDatagram as (msg: never, writer: BufferWriter) => void,
|
|
372
383
|
stream_header_track: encodeStreamHeaderTrack as (msg: never, writer: BufferWriter) => void,
|
|
@@ -379,20 +390,24 @@ const dataStreamEncoders: Partial<Record<MoqtMessageType, (msg: never, writer: B
|
|
|
379
390
|
function decodeClientSetup(reader: BufferReader): ClientSetup {
|
|
380
391
|
const numVersions = reader.readVarInt();
|
|
381
392
|
if (numVersions === 0n) {
|
|
382
|
-
throw new DecodeError(
|
|
393
|
+
throw new DecodeError(
|
|
394
|
+
"CONSTRAINT_VIOLATION",
|
|
395
|
+
"supported_versions must not be empty",
|
|
396
|
+
reader.offset,
|
|
397
|
+
);
|
|
383
398
|
}
|
|
384
399
|
const supportedVersions: bigint[] = [];
|
|
385
400
|
for (let i = 0n; i < numVersions; i++) {
|
|
386
401
|
supportedVersions.push(reader.readVarInt());
|
|
387
402
|
}
|
|
388
403
|
const parameters = reader.readParameters();
|
|
389
|
-
return { type:
|
|
404
|
+
return { type: "client_setup", supportedVersions, parameters };
|
|
390
405
|
}
|
|
391
406
|
|
|
392
407
|
function decodeServerSetup(reader: BufferReader): ServerSetup {
|
|
393
408
|
const selectedVersion = reader.readVarInt();
|
|
394
409
|
const parameters = reader.readParameters();
|
|
395
|
-
return { type:
|
|
410
|
+
return { type: "server_setup", selectedVersion, parameters };
|
|
396
411
|
}
|
|
397
412
|
|
|
398
413
|
function decodeSubscribe(reader: BufferReader): Subscribe {
|
|
@@ -405,11 +420,15 @@ function decodeSubscribe(reader: BufferReader): Subscribe {
|
|
|
405
420
|
const filterTypeWire = reader.readVarInt();
|
|
406
421
|
const filterType = WIRE_TO_FILTER_TYPE.get(filterTypeWire);
|
|
407
422
|
if (filterType === undefined) {
|
|
408
|
-
throw new DecodeError(
|
|
423
|
+
throw new DecodeError(
|
|
424
|
+
"CONSTRAINT_VIOLATION",
|
|
425
|
+
`Invalid filter type: ${filterTypeWire}`,
|
|
426
|
+
reader.offset,
|
|
427
|
+
);
|
|
409
428
|
}
|
|
410
429
|
|
|
411
430
|
const base = {
|
|
412
|
-
type:
|
|
431
|
+
type: "subscribe" as const,
|
|
413
432
|
subscribeId,
|
|
414
433
|
trackAlias,
|
|
415
434
|
trackNamespace,
|
|
@@ -420,13 +439,13 @@ function decodeSubscribe(reader: BufferReader): Subscribe {
|
|
|
420
439
|
parameters: undefined as unknown as Map<bigint, Uint8Array>,
|
|
421
440
|
};
|
|
422
441
|
|
|
423
|
-
if (filterType ===
|
|
442
|
+
if (filterType === "absolute_start") {
|
|
424
443
|
const startGroup = reader.readVarInt();
|
|
425
444
|
const startObject = reader.readVarInt();
|
|
426
445
|
base.parameters = reader.readParameters();
|
|
427
446
|
return { ...base, startGroup, startObject };
|
|
428
447
|
}
|
|
429
|
-
if (filterType ===
|
|
448
|
+
if (filterType === "absolute_range") {
|
|
430
449
|
const startGroup = reader.readVarInt();
|
|
431
450
|
const startObject = reader.readVarInt();
|
|
432
451
|
const endGroup = reader.readVarInt();
|
|
@@ -450,11 +469,27 @@ function decodeSubscribeOk(reader: BufferReader): SubscribeOk {
|
|
|
450
469
|
const largestGroupId = reader.readVarInt();
|
|
451
470
|
const largestObjectId = reader.readVarInt();
|
|
452
471
|
const parameters = reader.readParameters();
|
|
453
|
-
return {
|
|
472
|
+
return {
|
|
473
|
+
type: "subscribe_ok" as const,
|
|
474
|
+
subscribeId,
|
|
475
|
+
expires,
|
|
476
|
+
groupOrder,
|
|
477
|
+
contentExists,
|
|
478
|
+
largestGroupId,
|
|
479
|
+
largestObjectId,
|
|
480
|
+
parameters,
|
|
481
|
+
};
|
|
454
482
|
}
|
|
455
483
|
|
|
456
484
|
const parameters = reader.readParameters();
|
|
457
|
-
return {
|
|
485
|
+
return {
|
|
486
|
+
type: "subscribe_ok" as const,
|
|
487
|
+
subscribeId,
|
|
488
|
+
expires,
|
|
489
|
+
groupOrder,
|
|
490
|
+
contentExists,
|
|
491
|
+
parameters,
|
|
492
|
+
};
|
|
458
493
|
}
|
|
459
494
|
|
|
460
495
|
function decodeSubscribeError(reader: BufferReader): SubscribeError {
|
|
@@ -462,7 +497,7 @@ function decodeSubscribeError(reader: BufferReader): SubscribeError {
|
|
|
462
497
|
const errorCode = reader.readVarInt();
|
|
463
498
|
const reasonPhrase = reader.readString();
|
|
464
499
|
const trackAlias = reader.readVarInt();
|
|
465
|
-
return { type:
|
|
500
|
+
return { type: "subscribe_error", subscribeId, errorCode, reasonPhrase, trackAlias };
|
|
466
501
|
}
|
|
467
502
|
|
|
468
503
|
function decodeSubscribeDone(reader: BufferReader): SubscribeDone {
|
|
@@ -475,10 +510,18 @@ function decodeSubscribeDone(reader: BufferReader): SubscribeDone {
|
|
|
475
510
|
if (contentExists) {
|
|
476
511
|
const finalGroupId = reader.readVarInt();
|
|
477
512
|
const finalObjectId = reader.readVarInt();
|
|
478
|
-
return {
|
|
513
|
+
return {
|
|
514
|
+
type: "subscribe_done" as const,
|
|
515
|
+
subscribeId,
|
|
516
|
+
statusCode,
|
|
517
|
+
reasonPhrase,
|
|
518
|
+
contentExists,
|
|
519
|
+
finalGroupId,
|
|
520
|
+
finalObjectId,
|
|
521
|
+
};
|
|
479
522
|
}
|
|
480
523
|
|
|
481
|
-
return { type:
|
|
524
|
+
return { type: "subscribe_done" as const, subscribeId, statusCode, reasonPhrase, contentExists };
|
|
482
525
|
}
|
|
483
526
|
|
|
484
527
|
function decodeSubscribeUpdate(reader: BufferReader): SubscribeUpdate {
|
|
@@ -489,48 +532,57 @@ function decodeSubscribeUpdate(reader: BufferReader): SubscribeUpdate {
|
|
|
489
532
|
const endObject = reader.readVarInt();
|
|
490
533
|
const subscriberPriority = reader.readUint8();
|
|
491
534
|
const parameters = reader.readParameters();
|
|
492
|
-
return {
|
|
535
|
+
return {
|
|
536
|
+
type: "subscribe_update",
|
|
537
|
+
subscribeId,
|
|
538
|
+
startGroup,
|
|
539
|
+
startObject,
|
|
540
|
+
endGroup,
|
|
541
|
+
endObject,
|
|
542
|
+
subscriberPriority,
|
|
543
|
+
parameters,
|
|
544
|
+
};
|
|
493
545
|
}
|
|
494
546
|
|
|
495
547
|
function decodeUnsubscribe(reader: BufferReader): Unsubscribe {
|
|
496
548
|
const subscribeId = reader.readVarInt();
|
|
497
|
-
return { type:
|
|
549
|
+
return { type: "unsubscribe", subscribeId };
|
|
498
550
|
}
|
|
499
551
|
|
|
500
552
|
function decodeAnnounce(reader: BufferReader): Announce {
|
|
501
553
|
const trackNamespace = reader.readTuple();
|
|
502
554
|
const parameters = reader.readParameters();
|
|
503
|
-
return { type:
|
|
555
|
+
return { type: "announce", trackNamespace, parameters };
|
|
504
556
|
}
|
|
505
557
|
|
|
506
558
|
function decodeAnnounceOk(reader: BufferReader): AnnounceOk {
|
|
507
559
|
const trackNamespace = reader.readTuple();
|
|
508
|
-
return { type:
|
|
560
|
+
return { type: "announce_ok", trackNamespace };
|
|
509
561
|
}
|
|
510
562
|
|
|
511
563
|
function decodeAnnounceError(reader: BufferReader): AnnounceError {
|
|
512
564
|
const trackNamespace = reader.readTuple();
|
|
513
565
|
const errorCode = reader.readVarInt();
|
|
514
566
|
const reasonPhrase = reader.readString();
|
|
515
|
-
return { type:
|
|
567
|
+
return { type: "announce_error", trackNamespace, errorCode, reasonPhrase };
|
|
516
568
|
}
|
|
517
569
|
|
|
518
570
|
function decodeAnnounceCancel(reader: BufferReader): AnnounceCancel {
|
|
519
571
|
const trackNamespace = reader.readTuple();
|
|
520
572
|
const errorCode = reader.readVarInt();
|
|
521
573
|
const reasonPhrase = reader.readString();
|
|
522
|
-
return { type:
|
|
574
|
+
return { type: "announce_cancel", trackNamespace, errorCode, reasonPhrase };
|
|
523
575
|
}
|
|
524
576
|
|
|
525
577
|
function decodeUnannounce(reader: BufferReader): Unannounce {
|
|
526
578
|
const trackNamespace = reader.readTuple();
|
|
527
|
-
return { type:
|
|
579
|
+
return { type: "unannounce", trackNamespace };
|
|
528
580
|
}
|
|
529
581
|
|
|
530
582
|
function decodeTrackStatusRequest(reader: BufferReader): TrackStatusRequest {
|
|
531
583
|
const trackNamespace = reader.readTuple();
|
|
532
584
|
const trackName = reader.readString();
|
|
533
|
-
return { type:
|
|
585
|
+
return { type: "track_status_request", trackNamespace, trackName };
|
|
534
586
|
}
|
|
535
587
|
|
|
536
588
|
function decodeTrackStatus(reader: BufferReader): TrackStatus {
|
|
@@ -539,40 +591,40 @@ function decodeTrackStatus(reader: BufferReader): TrackStatus {
|
|
|
539
591
|
const statusCode = reader.readVarInt();
|
|
540
592
|
const lastGroupId = reader.readVarInt();
|
|
541
593
|
const lastObjectId = reader.readVarInt();
|
|
542
|
-
return { type:
|
|
594
|
+
return { type: "track_status", trackNamespace, trackName, statusCode, lastGroupId, lastObjectId };
|
|
543
595
|
}
|
|
544
596
|
|
|
545
597
|
function decodeGoAway(reader: BufferReader): GoAway {
|
|
546
598
|
const newSessionUri = reader.readString();
|
|
547
|
-
return { type:
|
|
599
|
+
return { type: "goaway", newSessionUri };
|
|
548
600
|
}
|
|
549
601
|
|
|
550
602
|
function decodeSubscribeAnnounces(reader: BufferReader): SubscribeAnnounces {
|
|
551
603
|
const trackNamespace = reader.readTuple();
|
|
552
604
|
const parameters = reader.readParameters();
|
|
553
|
-
return { type:
|
|
605
|
+
return { type: "subscribe_announces", trackNamespace, parameters };
|
|
554
606
|
}
|
|
555
607
|
|
|
556
608
|
function decodeSubscribeAnnouncesOk(reader: BufferReader): SubscribeAnnouncesOk {
|
|
557
609
|
const trackNamespace = reader.readTuple();
|
|
558
|
-
return { type:
|
|
610
|
+
return { type: "subscribe_announces_ok", trackNamespace };
|
|
559
611
|
}
|
|
560
612
|
|
|
561
613
|
function decodeSubscribeAnnouncesError(reader: BufferReader): SubscribeAnnouncesError {
|
|
562
614
|
const trackNamespace = reader.readTuple();
|
|
563
615
|
const errorCode = reader.readVarInt();
|
|
564
616
|
const reasonPhrase = reader.readString();
|
|
565
|
-
return { type:
|
|
617
|
+
return { type: "subscribe_announces_error", trackNamespace, errorCode, reasonPhrase };
|
|
566
618
|
}
|
|
567
619
|
|
|
568
620
|
function decodeUnsubscribeAnnounces(reader: BufferReader): UnsubscribeAnnounces {
|
|
569
621
|
const trackNamespace = reader.readTuple();
|
|
570
|
-
return { type:
|
|
622
|
+
return { type: "unsubscribe_announces", trackNamespace };
|
|
571
623
|
}
|
|
572
624
|
|
|
573
625
|
function decodeMaxSubscribeId(reader: BufferReader): MaxSubscribeId {
|
|
574
626
|
const subscribeId = reader.readVarInt();
|
|
575
|
-
return { type:
|
|
627
|
+
return { type: "max_subscribe_id", subscribeId };
|
|
576
628
|
}
|
|
577
629
|
|
|
578
630
|
function decodeFetch(reader: BufferReader): Fetch {
|
|
@@ -586,7 +638,19 @@ function decodeFetch(reader: BufferReader): Fetch {
|
|
|
586
638
|
const endGroup = reader.readVarInt();
|
|
587
639
|
const endObject = reader.readVarInt();
|
|
588
640
|
const parameters = reader.readParameters();
|
|
589
|
-
return {
|
|
641
|
+
return {
|
|
642
|
+
type: "fetch" as const,
|
|
643
|
+
subscribeId,
|
|
644
|
+
trackNamespace,
|
|
645
|
+
trackName,
|
|
646
|
+
subscriberPriority,
|
|
647
|
+
groupOrder,
|
|
648
|
+
startGroup,
|
|
649
|
+
startObject,
|
|
650
|
+
endGroup,
|
|
651
|
+
endObject,
|
|
652
|
+
parameters,
|
|
653
|
+
};
|
|
590
654
|
}
|
|
591
655
|
|
|
592
656
|
function decodeFetchOk(reader: BufferReader): FetchOk {
|
|
@@ -597,73 +661,114 @@ function decodeFetchOk(reader: BufferReader): FetchOk {
|
|
|
597
661
|
const largestGroupId = reader.readVarInt();
|
|
598
662
|
const largestObjectId = reader.readVarInt();
|
|
599
663
|
const parameters = reader.readParameters();
|
|
600
|
-
return {
|
|
664
|
+
return {
|
|
665
|
+
type: "fetch_ok" as const,
|
|
666
|
+
subscribeId,
|
|
667
|
+
groupOrder,
|
|
668
|
+
endOfTrack,
|
|
669
|
+
largestGroupId,
|
|
670
|
+
largestObjectId,
|
|
671
|
+
parameters,
|
|
672
|
+
};
|
|
601
673
|
}
|
|
602
674
|
|
|
603
675
|
function decodeFetchError(reader: BufferReader): FetchError {
|
|
604
676
|
const subscribeId = reader.readVarInt();
|
|
605
677
|
const errorCode = reader.readVarInt();
|
|
606
678
|
const reasonPhrase = reader.readString();
|
|
607
|
-
return { type:
|
|
679
|
+
return { type: "fetch_error", subscribeId, errorCode, reasonPhrase };
|
|
608
680
|
}
|
|
609
681
|
|
|
610
682
|
function decodeFetchCancel(reader: BufferReader): FetchCancel {
|
|
611
683
|
const subscribeId = reader.readVarInt();
|
|
612
|
-
return { type:
|
|
684
|
+
return { type: "fetch_cancel", subscribeId };
|
|
613
685
|
}
|
|
614
686
|
|
|
615
687
|
function decodeObjectStream(reader: BufferReader): ObjectStream {
|
|
616
|
-
const subscribeId = reader.readVarInt();
|
|
617
688
|
const trackAlias = reader.readVarInt();
|
|
618
689
|
const groupId = reader.readVarInt();
|
|
619
690
|
const objectId = reader.readVarInt();
|
|
620
691
|
const publisherPriority = reader.readUint8();
|
|
621
|
-
const
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
return {
|
|
692
|
+
const payloadLength = Number(reader.readVarInt());
|
|
693
|
+
if (payloadLength === 0) {
|
|
694
|
+
// Object Status follows when payload length is 0
|
|
695
|
+
const objectStatus = reader.remaining > 0 ? Number(reader.readVarInt()) : 0;
|
|
696
|
+
return {
|
|
697
|
+
type: "object_stream" as const,
|
|
698
|
+
trackAlias,
|
|
699
|
+
groupId,
|
|
700
|
+
objectId,
|
|
701
|
+
publisherPriority,
|
|
702
|
+
objectStatus,
|
|
703
|
+
payload: new Uint8Array(0),
|
|
704
|
+
};
|
|
626
705
|
}
|
|
627
|
-
|
|
706
|
+
const payload = reader.readBytes(payloadLength);
|
|
707
|
+
return {
|
|
708
|
+
type: "object_stream" as const,
|
|
709
|
+
trackAlias,
|
|
710
|
+
groupId,
|
|
711
|
+
objectId,
|
|
712
|
+
publisherPriority,
|
|
713
|
+
payload,
|
|
714
|
+
};
|
|
628
715
|
}
|
|
629
716
|
|
|
630
717
|
function decodeObjectDatagram(reader: BufferReader): ObjectDatagram {
|
|
631
|
-
const subscribeId = reader.readVarInt();
|
|
632
718
|
const trackAlias = reader.readVarInt();
|
|
633
719
|
const groupId = reader.readVarInt();
|
|
634
720
|
const objectId = reader.readVarInt();
|
|
635
721
|
const publisherPriority = reader.readUint8();
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
return {
|
|
722
|
+
const payloadLength = Number(reader.readVarInt());
|
|
723
|
+
if (payloadLength === 0) {
|
|
724
|
+
// Object Status follows when payload length is 0
|
|
725
|
+
const objectStatus = reader.remaining > 0 ? Number(reader.readVarInt()) : 0;
|
|
726
|
+
return {
|
|
727
|
+
type: "object_datagram" as const,
|
|
728
|
+
trackAlias,
|
|
729
|
+
groupId,
|
|
730
|
+
objectId,
|
|
731
|
+
publisherPriority,
|
|
732
|
+
objectStatus,
|
|
733
|
+
payload: new Uint8Array(0),
|
|
734
|
+
};
|
|
641
735
|
}
|
|
642
|
-
|
|
736
|
+
const payload = reader.readBytes(payloadLength);
|
|
737
|
+
return {
|
|
738
|
+
type: "object_datagram" as const,
|
|
739
|
+
trackAlias,
|
|
740
|
+
groupId,
|
|
741
|
+
objectId,
|
|
742
|
+
publisherPriority,
|
|
743
|
+
payload,
|
|
744
|
+
};
|
|
643
745
|
}
|
|
644
746
|
|
|
645
747
|
function decodeStreamHeaderTrack(reader: BufferReader): StreamHeaderTrack {
|
|
646
|
-
const subscribeId = reader.readVarInt();
|
|
647
748
|
const trackAlias = reader.readVarInt();
|
|
648
749
|
const publisherPriority = reader.readUint8();
|
|
649
|
-
return { type:
|
|
750
|
+
return { type: "stream_header_track", trackAlias, publisherPriority };
|
|
650
751
|
}
|
|
651
752
|
|
|
652
753
|
function decodeStreamHeaderGroup(reader: BufferReader): StreamHeaderGroup {
|
|
653
|
-
const subscribeId = reader.readVarInt();
|
|
654
754
|
const trackAlias = reader.readVarInt();
|
|
655
755
|
const groupId = reader.readVarInt();
|
|
656
756
|
const publisherPriority = reader.readUint8();
|
|
657
|
-
return { type:
|
|
757
|
+
return { type: "stream_header_group", trackAlias, groupId, publisherPriority };
|
|
658
758
|
}
|
|
659
759
|
|
|
660
760
|
function decodeStreamHeaderSubgroup(reader: BufferReader): StreamHeaderSubgroup {
|
|
661
|
-
const subscribeId = reader.readVarInt();
|
|
662
761
|
const trackAlias = reader.readVarInt();
|
|
663
762
|
const groupId = reader.readVarInt();
|
|
664
763
|
const subgroupId = reader.readVarInt();
|
|
665
764
|
const publisherPriority = reader.readUint8();
|
|
666
|
-
return {
|
|
765
|
+
return {
|
|
766
|
+
type: "stream_header_subgroup",
|
|
767
|
+
trackAlias,
|
|
768
|
+
groupId,
|
|
769
|
+
subgroupId,
|
|
770
|
+
publisherPriority,
|
|
771
|
+
};
|
|
667
772
|
}
|
|
668
773
|
|
|
669
774
|
// --- Decode dispatch by wire type ID (control messages only) ---
|
|
@@ -777,7 +882,11 @@ function decodeMessageImpl(bytes: Uint8Array): DecodeResult<MoqtMessage> {
|
|
|
777
882
|
if (!decoder) {
|
|
778
883
|
return {
|
|
779
884
|
ok: false,
|
|
780
|
-
error: new DecodeError(
|
|
885
|
+
error: new DecodeError(
|
|
886
|
+
"UNKNOWN_MESSAGE_TYPE",
|
|
887
|
+
`Unknown data stream type ID: 0x${typeId.toString(16)}`,
|
|
888
|
+
0,
|
|
889
|
+
),
|
|
781
890
|
};
|
|
782
891
|
}
|
|
783
892
|
const message = decoder(reader);
|
|
@@ -786,12 +895,16 @@ function decodeMessageImpl(bytes: Uint8Array): DecodeResult<MoqtMessage> {
|
|
|
786
895
|
|
|
787
896
|
// Control message: read length, then decode payload from bounded sub-reader
|
|
788
897
|
const payloadLength = Number(reader.readVarInt());
|
|
789
|
-
const
|
|
898
|
+
const _headerBytes = reader.offset; // bytes consumed by type + length
|
|
790
899
|
|
|
791
900
|
if (reader.remaining < payloadLength) {
|
|
792
901
|
return {
|
|
793
902
|
ok: false,
|
|
794
|
-
error: new DecodeError(
|
|
903
|
+
error: new DecodeError(
|
|
904
|
+
"UNEXPECTED_END",
|
|
905
|
+
`Not enough bytes for payload: need ${payloadLength}, have ${reader.remaining}`,
|
|
906
|
+
reader.offset,
|
|
907
|
+
),
|
|
795
908
|
};
|
|
796
909
|
}
|
|
797
910
|
|
|
@@ -802,7 +915,11 @@ function decodeMessageImpl(bytes: Uint8Array): DecodeResult<MoqtMessage> {
|
|
|
802
915
|
if (!decoder) {
|
|
803
916
|
return {
|
|
804
917
|
ok: false,
|
|
805
|
-
error: new DecodeError(
|
|
918
|
+
error: new DecodeError(
|
|
919
|
+
"UNKNOWN_MESSAGE_TYPE",
|
|
920
|
+
`Unknown message type ID: 0x${typeId.toString(16)}`,
|
|
921
|
+
0,
|
|
922
|
+
),
|
|
806
923
|
};
|
|
807
924
|
}
|
|
808
925
|
|
|
@@ -832,7 +949,7 @@ function createStreamDecoderImpl(): TransformStream<Uint8Array, MoqtMessage> {
|
|
|
832
949
|
while (buffer.length > 0) {
|
|
833
950
|
const result = decodeMessageImpl(buffer);
|
|
834
951
|
if (!result.ok) {
|
|
835
|
-
if (result.error.code ===
|
|
952
|
+
if (result.error.code === "UNEXPECTED_END") {
|
|
836
953
|
// Need more data -- wait for next chunk
|
|
837
954
|
break;
|
|
838
955
|
}
|
|
@@ -850,7 +967,7 @@ function createStreamDecoderImpl(): TransformStream<Uint8Array, MoqtMessage> {
|
|
|
850
967
|
// If there is remaining data in the buffer, it is a truncated message
|
|
851
968
|
if (buffer.length > 0) {
|
|
852
969
|
controller.error(
|
|
853
|
-
new DecodeError(
|
|
970
|
+
new DecodeError("UNEXPECTED_END", "Stream ended with incomplete message data", 0),
|
|
854
971
|
);
|
|
855
972
|
}
|
|
856
973
|
},
|
|
@@ -861,7 +978,7 @@ function createStreamDecoderImpl(): TransformStream<Uint8Array, MoqtMessage> {
|
|
|
861
978
|
|
|
862
979
|
export function createDraft07Codec(): Codec {
|
|
863
980
|
return {
|
|
864
|
-
draft:
|
|
981
|
+
draft: "draft-ietf-moq-transport-07",
|
|
865
982
|
encodeMessage: encodeMessageImpl,
|
|
866
983
|
decodeMessage: decodeMessageImpl,
|
|
867
984
|
encodeVarInt,
|