@moqtap/codec 0.1.0 → 0.1.1

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.
Files changed (67) hide show
  1. package/dist/{chunk-YBSEOSSP.js → chunk-A27S7HW7.js} +5 -1
  2. package/dist/{chunk-5WFXFLL4.cjs → chunk-FUFTMAQD.cjs} +96 -63
  3. package/dist/{chunk-2NARXGVA.cjs → chunk-FWISIR26.cjs} +5 -1
  4. package/dist/{chunk-23YG7F46.js → chunk-IXHOBNXA.js} +117 -17
  5. package/dist/{chunk-3BSZ55L3.cjs → chunk-NLYTRGXA.cjs} +153 -19
  6. package/dist/{chunk-GDRGWFEK.cjs → chunk-NPWHHWXT.cjs} +249 -37
  7. package/dist/{chunk-IQPDRQVC.js → chunk-U2B3B42P.js} +62 -29
  8. package/dist/{chunk-WNTXF3DE.cjs → chunk-YBZD3DU5.cjs} +127 -27
  9. package/dist/{chunk-DC4L6ZIT.js → chunk-YTXLWKOR.js} +153 -19
  10. package/dist/{chunk-YPXLV5YK.js → chunk-Z66WDWHI.js} +249 -37
  11. package/dist/{codec-qPzfmLNu.d.ts → codec-B2mc2g3i.d.ts} +5 -5
  12. package/dist/{codec-CTvFtQQI.d.cts → codec-Bvr7rFtj.d.cts} +5 -5
  13. package/dist/draft14-session.cjs +2 -2
  14. package/dist/draft14-session.d.cts +4 -4
  15. package/dist/draft14-session.d.ts +4 -4
  16. package/dist/draft14-session.js +1 -1
  17. package/dist/draft14.cjs +4 -4
  18. package/dist/draft14.d.cts +15 -15
  19. package/dist/draft14.d.ts +15 -15
  20. package/dist/draft14.js +3 -3
  21. package/dist/draft7-session.cjs +2 -2
  22. package/dist/draft7-session.d.cts +3 -3
  23. package/dist/draft7-session.d.ts +3 -3
  24. package/dist/draft7-session.js +1 -1
  25. package/dist/draft7.cjs +5 -5
  26. package/dist/draft7.d.cts +10 -10
  27. package/dist/draft7.d.ts +10 -10
  28. package/dist/draft7.js +2 -2
  29. package/dist/index.cjs +6 -6
  30. package/dist/index.d.cts +6 -6
  31. package/dist/index.d.ts +6 -6
  32. package/dist/index.js +3 -3
  33. package/dist/{session-types-B9NIf7_F.d.ts → session-types-DFjMk4HH.d.ts} +20 -20
  34. package/dist/{session-types-CCo-oA-d.d.cts → session-types-DW1RSZX_.d.cts} +20 -20
  35. package/dist/session.cjs +4 -4
  36. package/dist/session.d.cts +3 -3
  37. package/dist/session.d.ts +3 -3
  38. package/dist/session.js +2 -2
  39. package/dist/{types-CIk5W10V.d.ts → types-BTFeKYCb.d.cts} +37 -37
  40. package/dist/{types-CIk5W10V.d.cts → types-BTFeKYCb.d.ts} +37 -37
  41. package/dist/{types-ClXELFGN.d.cts → types-DPYE49t0.d.cts} +36 -36
  42. package/dist/{types-ClXELFGN.d.ts → types-DPYE49t0.d.ts} +36 -36
  43. package/package.json +7 -7
  44. package/src/core/buffer-reader.ts +16 -9
  45. package/src/core/buffer-writer.ts +2 -2
  46. package/src/core/errors.ts +1 -1
  47. package/src/core/session-types.ts +28 -41
  48. package/src/core/types.ts +70 -70
  49. package/src/drafts/draft07/announce-fsm.ts +1 -1
  50. package/src/drafts/draft07/codec.ts +195 -86
  51. package/src/drafts/draft07/index.ts +43 -44
  52. package/src/drafts/draft07/messages.ts +1 -1
  53. package/src/drafts/draft07/parameters.ts +2 -2
  54. package/src/drafts/draft07/rules.ts +68 -37
  55. package/src/drafts/draft07/session-fsm.ts +330 -117
  56. package/src/drafts/draft07/session.ts +10 -10
  57. package/src/drafts/draft07/subscription-fsm.ts +1 -1
  58. package/src/drafts/draft07/varint.ts +4 -4
  59. package/src/drafts/draft14/codec.ts +339 -189
  60. package/src/drafts/draft14/index.ts +103 -108
  61. package/src/drafts/draft14/messages.ts +61 -61
  62. package/src/drafts/draft14/rules.ts +77 -34
  63. package/src/drafts/draft14/session-fsm.ts +458 -146
  64. package/src/drafts/draft14/session.ts +13 -13
  65. package/src/drafts/draft14/types.ts +68 -68
  66. package/src/index.ts +66 -31
  67. package/src/session.ts +20 -20
@@ -1,21 +1,21 @@
1
- type Draft = 'draft-ietf-moq-transport-07' | 'draft-ietf-moq-transport-14';
2
- type DraftShorthand = '07' | '14';
3
- type MoqtMessageType = 'client_setup' | 'server_setup' | 'subscribe' | 'subscribe_ok' | 'subscribe_error' | 'subscribe_done' | 'subscribe_update' | 'unsubscribe' | 'announce' | 'announce_ok' | 'announce_error' | 'announce_cancel' | 'unannounce' | 'track_status_request' | 'track_status' | 'object_stream' | 'object_datagram' | 'stream_header_track' | 'stream_header_group' | 'stream_header_subgroup' | 'goaway' | 'subscribe_announces' | 'subscribe_announces_ok' | 'subscribe_announces_error' | 'unsubscribe_announces' | 'max_subscribe_id' | 'fetch' | 'fetch_ok' | 'fetch_error' | 'fetch_cancel';
1
+ type Draft = "draft-ietf-moq-transport-07" | "draft-ietf-moq-transport-14";
2
+ type DraftShorthand = "07" | "14";
3
+ type MoqtMessageType = "client_setup" | "server_setup" | "subscribe" | "subscribe_ok" | "subscribe_error" | "subscribe_done" | "subscribe_update" | "unsubscribe" | "announce" | "announce_ok" | "announce_error" | "announce_cancel" | "unannounce" | "track_status_request" | "track_status" | "object_stream" | "object_datagram" | "stream_header_track" | "stream_header_group" | "stream_header_subgroup" | "goaway" | "subscribe_announces" | "subscribe_announces_ok" | "subscribe_announces_error" | "unsubscribe_announces" | "max_subscribe_id" | "fetch" | "fetch_ok" | "fetch_error" | "fetch_cancel";
4
4
  interface BaseMessage {
5
5
  readonly type: MoqtMessageType;
6
6
  }
7
7
  interface ClientSetup extends BaseMessage {
8
- readonly type: 'client_setup';
8
+ readonly type: "client_setup";
9
9
  readonly supportedVersions: bigint[];
10
10
  readonly parameters: Map<bigint, Uint8Array>;
11
11
  }
12
12
  interface ServerSetup extends BaseMessage {
13
- readonly type: 'server_setup';
13
+ readonly type: "server_setup";
14
14
  readonly selectedVersion: bigint;
15
15
  readonly parameters: Map<bigint, Uint8Array>;
16
16
  }
17
17
  interface Subscribe extends BaseMessage {
18
- readonly type: 'subscribe';
18
+ readonly type: "subscribe";
19
19
  readonly subscribeId: bigint;
20
20
  readonly trackAlias: bigint;
21
21
  readonly trackNamespace: string[];
@@ -29,9 +29,9 @@ interface Subscribe extends BaseMessage {
29
29
  readonly endObject?: bigint;
30
30
  readonly parameters: Map<bigint, Uint8Array>;
31
31
  }
32
- type FilterType = 'latest_group' | 'latest_object' | 'absolute_start' | 'absolute_range';
32
+ type FilterType = "latest_group" | "latest_object" | "absolute_start" | "absolute_range";
33
33
  interface SubscribeOk extends BaseMessage {
34
- readonly type: 'subscribe_ok';
34
+ readonly type: "subscribe_ok";
35
35
  readonly subscribeId: bigint;
36
36
  readonly expires: bigint;
37
37
  readonly groupOrder: GroupOrderValue;
@@ -40,16 +40,16 @@ interface SubscribeOk extends BaseMessage {
40
40
  readonly largestObjectId?: bigint;
41
41
  readonly parameters: Map<bigint, Uint8Array>;
42
42
  }
43
- type GroupOrderValue = 'ascending' | 'descending' | 'original';
43
+ type GroupOrderValue = "ascending" | "descending" | "original";
44
44
  interface SubscribeError extends BaseMessage {
45
- readonly type: 'subscribe_error';
45
+ readonly type: "subscribe_error";
46
46
  readonly subscribeId: bigint;
47
47
  readonly errorCode: bigint;
48
48
  readonly reasonPhrase: string;
49
49
  readonly trackAlias: bigint;
50
50
  }
51
51
  interface SubscribeDone extends BaseMessage {
52
- readonly type: 'subscribe_done';
52
+ readonly type: "subscribe_done";
53
53
  readonly subscribeId: bigint;
54
54
  readonly statusCode: bigint;
55
55
  readonly reasonPhrase: string;
@@ -58,7 +58,7 @@ interface SubscribeDone extends BaseMessage {
58
58
  readonly finalObjectId?: bigint;
59
59
  }
60
60
  interface SubscribeUpdate extends BaseMessage {
61
- readonly type: 'subscribe_update';
61
+ readonly type: "subscribe_update";
62
62
  readonly subscribeId: bigint;
63
63
  readonly startGroup: bigint;
64
64
  readonly startObject: bigint;
@@ -68,41 +68,41 @@ interface SubscribeUpdate extends BaseMessage {
68
68
  readonly parameters: Map<bigint, Uint8Array>;
69
69
  }
70
70
  interface Unsubscribe extends BaseMessage {
71
- readonly type: 'unsubscribe';
71
+ readonly type: "unsubscribe";
72
72
  readonly subscribeId: bigint;
73
73
  }
74
74
  interface Announce extends BaseMessage {
75
- readonly type: 'announce';
75
+ readonly type: "announce";
76
76
  readonly trackNamespace: string[];
77
77
  readonly parameters: Map<bigint, Uint8Array>;
78
78
  }
79
79
  interface AnnounceOk extends BaseMessage {
80
- readonly type: 'announce_ok';
80
+ readonly type: "announce_ok";
81
81
  readonly trackNamespace: string[];
82
82
  }
83
83
  interface AnnounceError extends BaseMessage {
84
- readonly type: 'announce_error';
84
+ readonly type: "announce_error";
85
85
  readonly trackNamespace: string[];
86
86
  readonly errorCode: bigint;
87
87
  readonly reasonPhrase: string;
88
88
  }
89
89
  interface AnnounceCancel extends BaseMessage {
90
- readonly type: 'announce_cancel';
90
+ readonly type: "announce_cancel";
91
91
  readonly trackNamespace: string[];
92
92
  readonly errorCode: bigint;
93
93
  readonly reasonPhrase: string;
94
94
  }
95
95
  interface Unannounce extends BaseMessage {
96
- readonly type: 'unannounce';
96
+ readonly type: "unannounce";
97
97
  readonly trackNamespace: string[];
98
98
  }
99
99
  interface TrackStatusRequest extends BaseMessage {
100
- readonly type: 'track_status_request';
100
+ readonly type: "track_status_request";
101
101
  readonly trackNamespace: string[];
102
102
  readonly trackName: string;
103
103
  }
104
104
  interface TrackStatus extends BaseMessage {
105
- readonly type: 'track_status';
105
+ readonly type: "track_status";
106
106
  readonly trackNamespace: string[];
107
107
  readonly trackName: string;
108
108
  readonly statusCode: bigint;
@@ -110,7 +110,7 @@ interface TrackStatus extends BaseMessage {
110
110
  readonly lastObjectId: bigint;
111
111
  }
112
112
  interface ObjectStream extends BaseMessage {
113
- readonly type: 'object_stream';
113
+ readonly type: "object_stream";
114
114
  readonly subscribeId: bigint;
115
115
  readonly trackAlias: bigint;
116
116
  readonly groupId: bigint;
@@ -120,7 +120,7 @@ interface ObjectStream extends BaseMessage {
120
120
  readonly payload: Uint8Array;
121
121
  }
122
122
  interface ObjectDatagram extends BaseMessage {
123
- readonly type: 'object_datagram';
123
+ readonly type: "object_datagram";
124
124
  readonly subscribeId: bigint;
125
125
  readonly trackAlias: bigint;
126
126
  readonly groupId: bigint;
@@ -130,20 +130,20 @@ interface ObjectDatagram extends BaseMessage {
130
130
  readonly payload: Uint8Array;
131
131
  }
132
132
  interface StreamHeaderTrack extends BaseMessage {
133
- readonly type: 'stream_header_track';
133
+ readonly type: "stream_header_track";
134
134
  readonly subscribeId: bigint;
135
135
  readonly trackAlias: bigint;
136
136
  readonly publisherPriority: number;
137
137
  }
138
138
  interface StreamHeaderGroup extends BaseMessage {
139
- readonly type: 'stream_header_group';
139
+ readonly type: "stream_header_group";
140
140
  readonly subscribeId: bigint;
141
141
  readonly trackAlias: bigint;
142
142
  readonly groupId: bigint;
143
143
  readonly publisherPriority: number;
144
144
  }
145
145
  interface StreamHeaderSubgroup extends BaseMessage {
146
- readonly type: 'stream_header_subgroup';
146
+ readonly type: "stream_header_subgroup";
147
147
  readonly subscribeId: bigint;
148
148
  readonly trackAlias: bigint;
149
149
  readonly groupId: bigint;
@@ -151,34 +151,34 @@ interface StreamHeaderSubgroup extends BaseMessage {
151
151
  readonly publisherPriority: number;
152
152
  }
153
153
  interface GoAway extends BaseMessage {
154
- readonly type: 'goaway';
154
+ readonly type: "goaway";
155
155
  readonly newSessionUri: string;
156
156
  }
157
157
  interface SubscribeAnnounces extends BaseMessage {
158
- readonly type: 'subscribe_announces';
158
+ readonly type: "subscribe_announces";
159
159
  readonly trackNamespace: string[];
160
160
  readonly parameters: Map<bigint, Uint8Array>;
161
161
  }
162
162
  interface SubscribeAnnouncesOk extends BaseMessage {
163
- readonly type: 'subscribe_announces_ok';
163
+ readonly type: "subscribe_announces_ok";
164
164
  readonly trackNamespace: string[];
165
165
  }
166
166
  interface SubscribeAnnouncesError extends BaseMessage {
167
- readonly type: 'subscribe_announces_error';
167
+ readonly type: "subscribe_announces_error";
168
168
  readonly trackNamespace: string[];
169
169
  readonly errorCode: bigint;
170
170
  readonly reasonPhrase: string;
171
171
  }
172
172
  interface UnsubscribeAnnounces extends BaseMessage {
173
- readonly type: 'unsubscribe_announces';
173
+ readonly type: "unsubscribe_announces";
174
174
  readonly trackNamespace: string[];
175
175
  }
176
176
  interface MaxSubscribeId extends BaseMessage {
177
- readonly type: 'max_subscribe_id';
177
+ readonly type: "max_subscribe_id";
178
178
  readonly subscribeId: bigint;
179
179
  }
180
180
  interface Fetch extends BaseMessage {
181
- readonly type: 'fetch';
181
+ readonly type: "fetch";
182
182
  readonly subscribeId: bigint;
183
183
  readonly trackNamespace: string[];
184
184
  readonly trackName: string;
@@ -191,7 +191,7 @@ interface Fetch extends BaseMessage {
191
191
  readonly parameters: Map<bigint, Uint8Array>;
192
192
  }
193
193
  interface FetchOk extends BaseMessage {
194
- readonly type: 'fetch_ok';
194
+ readonly type: "fetch_ok";
195
195
  readonly subscribeId: bigint;
196
196
  readonly groupOrder: GroupOrderValue;
197
197
  readonly endOfTrack: boolean;
@@ -200,13 +200,13 @@ interface FetchOk extends BaseMessage {
200
200
  readonly parameters: Map<bigint, Uint8Array>;
201
201
  }
202
202
  interface FetchError extends BaseMessage {
203
- readonly type: 'fetch_error';
203
+ readonly type: "fetch_error";
204
204
  readonly subscribeId: bigint;
205
205
  readonly errorCode: bigint;
206
206
  readonly reasonPhrase: string;
207
207
  }
208
208
  interface FetchCancel extends BaseMessage {
209
- readonly type: 'fetch_cancel';
209
+ readonly type: "fetch_cancel";
210
210
  readonly subscribeId: bigint;
211
211
  }
212
212
  type MoqtMessage = ClientSetup | ServerSetup | Subscribe | SubscribeOk | SubscribeError | SubscribeDone | SubscribeUpdate | Unsubscribe | Announce | AnnounceOk | AnnounceError | AnnounceCancel | Unannounce | TrackStatusRequest | TrackStatus | ObjectStream | ObjectDatagram | StreamHeaderTrack | StreamHeaderGroup | StreamHeaderSubgroup | GoAway | SubscribeAnnounces | SubscribeAnnouncesOk | SubscribeAnnouncesError | UnsubscribeAnnounces | MaxSubscribeId | Fetch | FetchOk | FetchError | FetchCancel;
@@ -231,7 +231,7 @@ type DecodeResult<T> = {
231
231
  ok: false;
232
232
  error: DecodeError;
233
233
  };
234
- type DecodeErrorCode = 'UNEXPECTED_END' | 'INVALID_VARINT' | 'UNKNOWN_MESSAGE_TYPE' | 'INVALID_PARAMETER' | 'CONSTRAINT_VIOLATION';
234
+ type DecodeErrorCode = "UNEXPECTED_END" | "INVALID_VARINT" | "UNKNOWN_MESSAGE_TYPE" | "INVALID_PARAMETER" | "CONSTRAINT_VIOLATION";
235
235
  declare class DecodeError extends Error {
236
236
  readonly code: DecodeErrorCode;
237
237
  readonly offset: number;
@@ -1,21 +1,21 @@
1
- type Draft = 'draft-ietf-moq-transport-07' | 'draft-ietf-moq-transport-14';
2
- type DraftShorthand = '07' | '14';
3
- type MoqtMessageType = 'client_setup' | 'server_setup' | 'subscribe' | 'subscribe_ok' | 'subscribe_error' | 'subscribe_done' | 'subscribe_update' | 'unsubscribe' | 'announce' | 'announce_ok' | 'announce_error' | 'announce_cancel' | 'unannounce' | 'track_status_request' | 'track_status' | 'object_stream' | 'object_datagram' | 'stream_header_track' | 'stream_header_group' | 'stream_header_subgroup' | 'goaway' | 'subscribe_announces' | 'subscribe_announces_ok' | 'subscribe_announces_error' | 'unsubscribe_announces' | 'max_subscribe_id' | 'fetch' | 'fetch_ok' | 'fetch_error' | 'fetch_cancel';
1
+ type Draft = "draft-ietf-moq-transport-07" | "draft-ietf-moq-transport-14";
2
+ type DraftShorthand = "07" | "14";
3
+ type MoqtMessageType = "client_setup" | "server_setup" | "subscribe" | "subscribe_ok" | "subscribe_error" | "subscribe_done" | "subscribe_update" | "unsubscribe" | "announce" | "announce_ok" | "announce_error" | "announce_cancel" | "unannounce" | "track_status_request" | "track_status" | "object_stream" | "object_datagram" | "stream_header_track" | "stream_header_group" | "stream_header_subgroup" | "goaway" | "subscribe_announces" | "subscribe_announces_ok" | "subscribe_announces_error" | "unsubscribe_announces" | "max_subscribe_id" | "fetch" | "fetch_ok" | "fetch_error" | "fetch_cancel";
4
4
  interface BaseMessage {
5
5
  readonly type: MoqtMessageType;
6
6
  }
7
7
  interface ClientSetup extends BaseMessage {
8
- readonly type: 'client_setup';
8
+ readonly type: "client_setup";
9
9
  readonly supportedVersions: bigint[];
10
10
  readonly parameters: Map<bigint, Uint8Array>;
11
11
  }
12
12
  interface ServerSetup extends BaseMessage {
13
- readonly type: 'server_setup';
13
+ readonly type: "server_setup";
14
14
  readonly selectedVersion: bigint;
15
15
  readonly parameters: Map<bigint, Uint8Array>;
16
16
  }
17
17
  interface Subscribe extends BaseMessage {
18
- readonly type: 'subscribe';
18
+ readonly type: "subscribe";
19
19
  readonly subscribeId: bigint;
20
20
  readonly trackAlias: bigint;
21
21
  readonly trackNamespace: string[];
@@ -29,9 +29,9 @@ interface Subscribe extends BaseMessage {
29
29
  readonly endObject?: bigint;
30
30
  readonly parameters: Map<bigint, Uint8Array>;
31
31
  }
32
- type FilterType = 'latest_group' | 'latest_object' | 'absolute_start' | 'absolute_range';
32
+ type FilterType = "latest_group" | "latest_object" | "absolute_start" | "absolute_range";
33
33
  interface SubscribeOk extends BaseMessage {
34
- readonly type: 'subscribe_ok';
34
+ readonly type: "subscribe_ok";
35
35
  readonly subscribeId: bigint;
36
36
  readonly expires: bigint;
37
37
  readonly groupOrder: GroupOrderValue;
@@ -40,16 +40,16 @@ interface SubscribeOk extends BaseMessage {
40
40
  readonly largestObjectId?: bigint;
41
41
  readonly parameters: Map<bigint, Uint8Array>;
42
42
  }
43
- type GroupOrderValue = 'ascending' | 'descending' | 'original';
43
+ type GroupOrderValue = "ascending" | "descending" | "original";
44
44
  interface SubscribeError extends BaseMessage {
45
- readonly type: 'subscribe_error';
45
+ readonly type: "subscribe_error";
46
46
  readonly subscribeId: bigint;
47
47
  readonly errorCode: bigint;
48
48
  readonly reasonPhrase: string;
49
49
  readonly trackAlias: bigint;
50
50
  }
51
51
  interface SubscribeDone extends BaseMessage {
52
- readonly type: 'subscribe_done';
52
+ readonly type: "subscribe_done";
53
53
  readonly subscribeId: bigint;
54
54
  readonly statusCode: bigint;
55
55
  readonly reasonPhrase: string;
@@ -58,7 +58,7 @@ interface SubscribeDone extends BaseMessage {
58
58
  readonly finalObjectId?: bigint;
59
59
  }
60
60
  interface SubscribeUpdate extends BaseMessage {
61
- readonly type: 'subscribe_update';
61
+ readonly type: "subscribe_update";
62
62
  readonly subscribeId: bigint;
63
63
  readonly startGroup: bigint;
64
64
  readonly startObject: bigint;
@@ -68,41 +68,41 @@ interface SubscribeUpdate extends BaseMessage {
68
68
  readonly parameters: Map<bigint, Uint8Array>;
69
69
  }
70
70
  interface Unsubscribe extends BaseMessage {
71
- readonly type: 'unsubscribe';
71
+ readonly type: "unsubscribe";
72
72
  readonly subscribeId: bigint;
73
73
  }
74
74
  interface Announce extends BaseMessage {
75
- readonly type: 'announce';
75
+ readonly type: "announce";
76
76
  readonly trackNamespace: string[];
77
77
  readonly parameters: Map<bigint, Uint8Array>;
78
78
  }
79
79
  interface AnnounceOk extends BaseMessage {
80
- readonly type: 'announce_ok';
80
+ readonly type: "announce_ok";
81
81
  readonly trackNamespace: string[];
82
82
  }
83
83
  interface AnnounceError extends BaseMessage {
84
- readonly type: 'announce_error';
84
+ readonly type: "announce_error";
85
85
  readonly trackNamespace: string[];
86
86
  readonly errorCode: bigint;
87
87
  readonly reasonPhrase: string;
88
88
  }
89
89
  interface AnnounceCancel extends BaseMessage {
90
- readonly type: 'announce_cancel';
90
+ readonly type: "announce_cancel";
91
91
  readonly trackNamespace: string[];
92
92
  readonly errorCode: bigint;
93
93
  readonly reasonPhrase: string;
94
94
  }
95
95
  interface Unannounce extends BaseMessage {
96
- readonly type: 'unannounce';
96
+ readonly type: "unannounce";
97
97
  readonly trackNamespace: string[];
98
98
  }
99
99
  interface TrackStatusRequest extends BaseMessage {
100
- readonly type: 'track_status_request';
100
+ readonly type: "track_status_request";
101
101
  readonly trackNamespace: string[];
102
102
  readonly trackName: string;
103
103
  }
104
104
  interface TrackStatus extends BaseMessage {
105
- readonly type: 'track_status';
105
+ readonly type: "track_status";
106
106
  readonly trackNamespace: string[];
107
107
  readonly trackName: string;
108
108
  readonly statusCode: bigint;
@@ -110,7 +110,7 @@ interface TrackStatus extends BaseMessage {
110
110
  readonly lastObjectId: bigint;
111
111
  }
112
112
  interface ObjectStream extends BaseMessage {
113
- readonly type: 'object_stream';
113
+ readonly type: "object_stream";
114
114
  readonly subscribeId: bigint;
115
115
  readonly trackAlias: bigint;
116
116
  readonly groupId: bigint;
@@ -120,7 +120,7 @@ interface ObjectStream extends BaseMessage {
120
120
  readonly payload: Uint8Array;
121
121
  }
122
122
  interface ObjectDatagram extends BaseMessage {
123
- readonly type: 'object_datagram';
123
+ readonly type: "object_datagram";
124
124
  readonly subscribeId: bigint;
125
125
  readonly trackAlias: bigint;
126
126
  readonly groupId: bigint;
@@ -130,20 +130,20 @@ interface ObjectDatagram extends BaseMessage {
130
130
  readonly payload: Uint8Array;
131
131
  }
132
132
  interface StreamHeaderTrack extends BaseMessage {
133
- readonly type: 'stream_header_track';
133
+ readonly type: "stream_header_track";
134
134
  readonly subscribeId: bigint;
135
135
  readonly trackAlias: bigint;
136
136
  readonly publisherPriority: number;
137
137
  }
138
138
  interface StreamHeaderGroup extends BaseMessage {
139
- readonly type: 'stream_header_group';
139
+ readonly type: "stream_header_group";
140
140
  readonly subscribeId: bigint;
141
141
  readonly trackAlias: bigint;
142
142
  readonly groupId: bigint;
143
143
  readonly publisherPriority: number;
144
144
  }
145
145
  interface StreamHeaderSubgroup extends BaseMessage {
146
- readonly type: 'stream_header_subgroup';
146
+ readonly type: "stream_header_subgroup";
147
147
  readonly subscribeId: bigint;
148
148
  readonly trackAlias: bigint;
149
149
  readonly groupId: bigint;
@@ -151,34 +151,34 @@ interface StreamHeaderSubgroup extends BaseMessage {
151
151
  readonly publisherPriority: number;
152
152
  }
153
153
  interface GoAway extends BaseMessage {
154
- readonly type: 'goaway';
154
+ readonly type: "goaway";
155
155
  readonly newSessionUri: string;
156
156
  }
157
157
  interface SubscribeAnnounces extends BaseMessage {
158
- readonly type: 'subscribe_announces';
158
+ readonly type: "subscribe_announces";
159
159
  readonly trackNamespace: string[];
160
160
  readonly parameters: Map<bigint, Uint8Array>;
161
161
  }
162
162
  interface SubscribeAnnouncesOk extends BaseMessage {
163
- readonly type: 'subscribe_announces_ok';
163
+ readonly type: "subscribe_announces_ok";
164
164
  readonly trackNamespace: string[];
165
165
  }
166
166
  interface SubscribeAnnouncesError extends BaseMessage {
167
- readonly type: 'subscribe_announces_error';
167
+ readonly type: "subscribe_announces_error";
168
168
  readonly trackNamespace: string[];
169
169
  readonly errorCode: bigint;
170
170
  readonly reasonPhrase: string;
171
171
  }
172
172
  interface UnsubscribeAnnounces extends BaseMessage {
173
- readonly type: 'unsubscribe_announces';
173
+ readonly type: "unsubscribe_announces";
174
174
  readonly trackNamespace: string[];
175
175
  }
176
176
  interface MaxSubscribeId extends BaseMessage {
177
- readonly type: 'max_subscribe_id';
177
+ readonly type: "max_subscribe_id";
178
178
  readonly subscribeId: bigint;
179
179
  }
180
180
  interface Fetch extends BaseMessage {
181
- readonly type: 'fetch';
181
+ readonly type: "fetch";
182
182
  readonly subscribeId: bigint;
183
183
  readonly trackNamespace: string[];
184
184
  readonly trackName: string;
@@ -191,7 +191,7 @@ interface Fetch extends BaseMessage {
191
191
  readonly parameters: Map<bigint, Uint8Array>;
192
192
  }
193
193
  interface FetchOk extends BaseMessage {
194
- readonly type: 'fetch_ok';
194
+ readonly type: "fetch_ok";
195
195
  readonly subscribeId: bigint;
196
196
  readonly groupOrder: GroupOrderValue;
197
197
  readonly endOfTrack: boolean;
@@ -200,13 +200,13 @@ interface FetchOk extends BaseMessage {
200
200
  readonly parameters: Map<bigint, Uint8Array>;
201
201
  }
202
202
  interface FetchError extends BaseMessage {
203
- readonly type: 'fetch_error';
203
+ readonly type: "fetch_error";
204
204
  readonly subscribeId: bigint;
205
205
  readonly errorCode: bigint;
206
206
  readonly reasonPhrase: string;
207
207
  }
208
208
  interface FetchCancel extends BaseMessage {
209
- readonly type: 'fetch_cancel';
209
+ readonly type: "fetch_cancel";
210
210
  readonly subscribeId: bigint;
211
211
  }
212
212
  type MoqtMessage = ClientSetup | ServerSetup | Subscribe | SubscribeOk | SubscribeError | SubscribeDone | SubscribeUpdate | Unsubscribe | Announce | AnnounceOk | AnnounceError | AnnounceCancel | Unannounce | TrackStatusRequest | TrackStatus | ObjectStream | ObjectDatagram | StreamHeaderTrack | StreamHeaderGroup | StreamHeaderSubgroup | GoAway | SubscribeAnnounces | SubscribeAnnouncesOk | SubscribeAnnouncesError | UnsubscribeAnnounces | MaxSubscribeId | Fetch | FetchOk | FetchError | FetchCancel;
@@ -231,7 +231,7 @@ type DecodeResult<T> = {
231
231
  ok: false;
232
232
  error: DecodeError;
233
233
  };
234
- type DecodeErrorCode = 'UNEXPECTED_END' | 'INVALID_VARINT' | 'UNKNOWN_MESSAGE_TYPE' | 'INVALID_PARAMETER' | 'CONSTRAINT_VIOLATION';
234
+ type DecodeErrorCode = "UNEXPECTED_END" | "INVALID_VARINT" | "UNKNOWN_MESSAGE_TYPE" | "INVALID_PARAMETER" | "CONSTRAINT_VIOLATION";
235
235
  declare class DecodeError extends Error {
236
236
  readonly code: DecodeErrorCode;
237
237
  readonly offset: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moqtap/codec",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "MoQT wire-format codec and session state machine — multi-draft, zero dependencies",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,37 +32,37 @@
32
32
  ".": {
33
33
  "bun": "./src/index.ts",
34
34
  "types": "./dist/index.d.ts",
35
- "import": "./dist/index.mjs",
35
+ "import": "./dist/index.js",
36
36
  "require": "./dist/index.cjs"
37
37
  },
38
38
  "./draft7": {
39
39
  "bun": "./src/drafts/draft07/index.ts",
40
40
  "types": "./dist/draft7.d.ts",
41
- "import": "./dist/draft7.mjs",
41
+ "import": "./dist/draft7.js",
42
42
  "require": "./dist/draft7.cjs"
43
43
  },
44
44
  "./draft14": {
45
45
  "bun": "./src/drafts/draft14/index.ts",
46
46
  "types": "./dist/draft14.d.ts",
47
- "import": "./dist/draft14.mjs",
47
+ "import": "./dist/draft14.js",
48
48
  "require": "./dist/draft14.cjs"
49
49
  },
50
50
  "./session": {
51
51
  "bun": "./src/session.ts",
52
52
  "types": "./dist/session.d.ts",
53
- "import": "./dist/session.mjs",
53
+ "import": "./dist/session.js",
54
54
  "require": "./dist/session.cjs"
55
55
  },
56
56
  "./draft7/session": {
57
57
  "bun": "./src/drafts/draft07/session.ts",
58
58
  "types": "./dist/draft7-session.d.ts",
59
- "import": "./dist/draft7-session.mjs",
59
+ "import": "./dist/draft7-session.js",
60
60
  "require": "./dist/draft7-session.cjs"
61
61
  },
62
62
  "./draft14/session": {
63
63
  "bun": "./src/drafts/draft14/session.ts",
64
64
  "types": "./dist/draft14-session.d.ts",
65
- "import": "./dist/draft14-session.mjs",
65
+ "import": "./dist/draft14-session.js",
66
66
  "require": "./dist/draft14-session.cjs"
67
67
  }
68
68
  },
@@ -1,10 +1,13 @@
1
- import { DecodeError } from './types.js';
1
+ import { DecodeError } from "./types.js";
2
2
 
3
3
  export class BufferReader {
4
4
  private readonly view: DataView;
5
5
  private pos: number;
6
6
 
7
- constructor(readonly buffer: Uint8Array, offset = 0) {
7
+ constructor(
8
+ readonly buffer: Uint8Array,
9
+ offset = 0,
10
+ ) {
8
11
  this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
9
12
  this.pos = offset;
10
13
  }
@@ -19,7 +22,7 @@ export class BufferReader {
19
22
 
20
23
  readUint8(): number {
21
24
  if (this.remaining < 1) {
22
- throw new DecodeError('UNEXPECTED_END', 'Not enough bytes to read uint8', this.pos);
25
+ throw new DecodeError("UNEXPECTED_END", "Not enough bytes to read uint8", this.pos);
23
26
  }
24
27
  const value = this.view.getUint8(this.pos);
25
28
  this.pos += 1;
@@ -28,7 +31,11 @@ export class BufferReader {
28
31
 
29
32
  readBytes(length: number): Uint8Array {
30
33
  if (this.remaining < length) {
31
- throw new DecodeError('UNEXPECTED_END', `Not enough bytes: need ${length}, have ${this.remaining}`, this.pos);
34
+ throw new DecodeError(
35
+ "UNEXPECTED_END",
36
+ `Not enough bytes: need ${length}, have ${this.remaining}`,
37
+ this.pos,
38
+ );
32
39
  }
33
40
  const slice = this.buffer.slice(this.pos, this.pos + length);
34
41
  this.pos += length;
@@ -37,7 +44,7 @@ export class BufferReader {
37
44
 
38
45
  readVarInt(): bigint {
39
46
  if (this.remaining < 1) {
40
- throw new DecodeError('UNEXPECTED_END', 'Not enough bytes for varint', this.pos);
47
+ throw new DecodeError("UNEXPECTED_END", "Not enough bytes for varint", this.pos);
41
48
  }
42
49
  const first = this.view.getUint8(this.pos);
43
50
  const prefix = first >> 6;
@@ -52,26 +59,26 @@ export class BufferReader {
52
59
  case 1:
53
60
  length = 2;
54
61
  if (this.remaining < 2) {
55
- throw new DecodeError('UNEXPECTED_END', 'Not enough bytes for 2-byte varint', this.pos);
62
+ throw new DecodeError("UNEXPECTED_END", "Not enough bytes for 2-byte varint", this.pos);
56
63
  }
57
64
  value = BigInt(this.view.getUint16(this.pos) & 0x3fff);
58
65
  break;
59
66
  case 2:
60
67
  length = 4;
61
68
  if (this.remaining < 4) {
62
- throw new DecodeError('UNEXPECTED_END', 'Not enough bytes for 4-byte varint', this.pos);
69
+ throw new DecodeError("UNEXPECTED_END", "Not enough bytes for 4-byte varint", this.pos);
63
70
  }
64
71
  value = BigInt(this.view.getUint32(this.pos)) & 0x3fffffffn;
65
72
  break;
66
73
  case 3:
67
74
  length = 8;
68
75
  if (this.remaining < 8) {
69
- throw new DecodeError('UNEXPECTED_END', 'Not enough bytes for 8-byte varint', this.pos);
76
+ throw new DecodeError("UNEXPECTED_END", "Not enough bytes for 8-byte varint", this.pos);
70
77
  }
71
78
  value = this.view.getBigUint64(this.pos) & 0x3fffffffffffffffn;
72
79
  break;
73
80
  default:
74
- throw new DecodeError('INVALID_VARINT', 'Invalid varint prefix', this.pos);
81
+ throw new DecodeError("INVALID_VARINT", "Invalid varint prefix", this.pos);
75
82
  }
76
83
 
77
84
  this.pos += length;
@@ -40,7 +40,7 @@ export class BufferWriter {
40
40
 
41
41
  writeVarInt(value: number | bigint): void {
42
42
  const v = BigInt(value);
43
- if (v < 0n) throw new Error('VarInt value must be non-negative');
43
+ if (v < 0n) throw new Error("VarInt value must be non-negative");
44
44
 
45
45
  if (v < 0x40n) {
46
46
  this.ensureCapacity(1);
@@ -59,7 +59,7 @@ export class BufferWriter {
59
59
  this.view.setBigUint64(this.pos, v | 0xc000000000000000n);
60
60
  this.pos += 8;
61
61
  } else {
62
- throw new Error('VarInt value exceeds 62-bit range');
62
+ throw new Error("VarInt value exceeds 62-bit range");
63
63
  }
64
64
  }
65
65
 
@@ -1 +1 @@
1
- export { DecodeError, type DecodeErrorCode } from './types.js';
1
+ export { DecodeError, type DecodeErrorCode } from "./types.js";