@moq/net 0.1.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 +70 -0
- package/announced.d.ts +41 -0
- package/announced.d.ts.map +1 -0
- package/announced.js +65 -0
- package/announced.js.map +1 -0
- package/bandwidth.d.ts +11 -0
- package/bandwidth.d.ts.map +1 -0
- package/bandwidth.js +6 -0
- package/bandwidth.js.map +1 -0
- package/broadcast.d.ts +35 -0
- package/broadcast.d.ts.map +1 -0
- package/broadcast.js +72 -0
- package/broadcast.js.map +1 -0
- package/connection/accept.d.ts +14 -0
- package/connection/accept.d.ts.map +1 -0
- package/connection/accept.js +133 -0
- package/connection/accept.js.map +1 -0
- package/connection/connect.d.ts +19 -0
- package/connection/connect.d.ts.map +1 -0
- package/connection/connect.js +284 -0
- package/connection/connect.js.map +1 -0
- package/connection/established.d.ts +22 -0
- package/connection/established.d.ts.map +1 -0
- package/connection/established.js +2 -0
- package/connection/established.js.map +1 -0
- package/connection/handshake.d.ts +10 -0
- package/connection/handshake.d.ts.map +1 -0
- package/connection/handshake.js +47 -0
- package/connection/handshake.js.map +1 -0
- package/connection/index.d.ts +5 -0
- package/connection/index.d.ts.map +1 -0
- package/connection/index.js +5 -0
- package/connection/index.js.map +1 -0
- package/connection/reload.d.ts +32 -0
- package/connection/reload.d.ts.map +1 -0
- package/connection/reload.js +127 -0
- package/connection/reload.js.map +1 -0
- package/group.d.ts +34 -0
- package/group.d.ts.map +1 -0
- package/group.js +92 -0
- package/group.js.map +1 -0
- package/ietf/adapter.d.ts +65 -0
- package/ietf/adapter.d.ts.map +1 -0
- package/ietf/adapter.js +625 -0
- package/ietf/adapter.js.map +1 -0
- package/ietf/connection.d.ts +65 -0
- package/ietf/connection.d.ts.map +1 -0
- package/ietf/connection.js +239 -0
- package/ietf/connection.js.map +1 -0
- package/ietf/control.d.ts +135 -0
- package/ietf/control.d.ts.map +1 -0
- package/ietf/control.js +237 -0
- package/ietf/control.js.map +1 -0
- package/ietf/fetch.d.ts +64 -0
- package/ietf/fetch.d.ts.map +1 -0
- package/ietf/fetch.js +99 -0
- package/ietf/fetch.js.map +1 -0
- package/ietf/goaway.d.ts +15 -0
- package/ietf/goaway.d.ts.map +1 -0
- package/ietf/goaway.js +33 -0
- package/ietf/goaway.js.map +1 -0
- package/ietf/ietf.test.d.ts +2 -0
- package/ietf/ietf.test.d.ts.map +1 -0
- package/ietf/ietf.test.js +800 -0
- package/ietf/ietf.test.js.map +1 -0
- package/ietf/index.d.ts +18 -0
- package/ietf/index.d.ts.map +1 -0
- package/ietf/index.js +18 -0
- package/ietf/index.js.map +1 -0
- package/ietf/message.d.ts +4 -0
- package/ietf/message.d.ts.map +1 -0
- package/ietf/message.js +53 -0
- package/ietf/message.js.map +1 -0
- package/ietf/namespace.d.ts +5 -0
- package/ietf/namespace.d.ts.map +1 -0
- package/ietf/namespace.js +21 -0
- package/ietf/namespace.js.map +1 -0
- package/ietf/object.d.ts +37 -0
- package/ietf/object.d.ts.map +1 -0
- package/ietf/object.js +129 -0
- package/ietf/object.js.map +1 -0
- package/ietf/parameters.d.ts +56 -0
- package/ietf/parameters.d.ts.map +1 -0
- package/ietf/parameters.js +336 -0
- package/ietf/parameters.js.map +1 -0
- package/ietf/properties.d.ts +4 -0
- package/ietf/properties.d.ts.map +1 -0
- package/ietf/properties.js +32 -0
- package/ietf/properties.js.map +1 -0
- package/ietf/publish.d.ts +68 -0
- package/ietf/publish.d.ts.map +1 -0
- package/ietf/publish.js +191 -0
- package/ietf/publish.js.map +1 -0
- package/ietf/publish_namespace.d.ts +68 -0
- package/ietf/publish_namespace.d.ts.map +1 -0
- package/ietf/publish_namespace.js +175 -0
- package/ietf/publish_namespace.js.map +1 -0
- package/ietf/publisher.d.ts +50 -0
- package/ietf/publisher.d.ts.map +1 -0
- package/ietf/publisher.js +329 -0
- package/ietf/publisher.js.map +1 -0
- package/ietf/request.d.ts +52 -0
- package/ietf/request.d.ts.map +1 -0
- package/ietf/request.js +118 -0
- package/ietf/request.js.map +1 -0
- package/ietf/setup.d.ts +38 -0
- package/ietf/setup.d.ts.map +1 -0
- package/ietf/setup.js +128 -0
- package/ietf/setup.js.map +1 -0
- package/ietf/subscribe.d.ts +66 -0
- package/ietf/subscribe.d.ts.map +1 -0
- package/ietf/subscribe.js +275 -0
- package/ietf/subscribe.js.map +1 -0
- package/ietf/subscribe_namespace.d.ts +89 -0
- package/ietf/subscribe_namespace.d.ts.map +1 -0
- package/ietf/subscribe_namespace.js +195 -0
- package/ietf/subscribe_namespace.js.map +1 -0
- package/ietf/subscriber.d.ts +53 -0
- package/ietf/subscriber.d.ts.map +1 -0
- package/ietf/subscriber.js +395 -0
- package/ietf/subscriber.js.map +1 -0
- package/ietf/track.d.ts +40 -0
- package/ietf/track.d.ts.map +1 -0
- package/ietf/track.js +107 -0
- package/ietf/track.js.map +1 -0
- package/ietf/version.d.ts +50 -0
- package/ietf/version.d.ts.map +1 -0
- package/ietf/version.js +55 -0
- package/ietf/version.js.map +1 -0
- package/index.d.ts +11 -0
- package/index.d.ts.map +1 -0
- package/index.js +16 -0
- package/index.js.map +1 -0
- package/integration.test.d.ts +2 -0
- package/integration.test.d.ts.map +1 -0
- package/integration.test.js +83 -0
- package/integration.test.js.map +1 -0
- package/lite/announce.d.ts +35 -0
- package/lite/announce.d.ts.map +1 -0
- package/lite/announce.js +165 -0
- package/lite/announce.js.map +1 -0
- package/lite/connection.d.ts +47 -0
- package/lite/connection.d.ts.map +1 -0
- package/lite/connection.js +218 -0
- package/lite/connection.js.map +1 -0
- package/lite/fetch.d.ts +14 -0
- package/lite/fetch.d.ts.map +1 -0
- package/lite/fetch.js +46 -0
- package/lite/fetch.js.map +1 -0
- package/lite/goaway.d.ts +10 -0
- package/lite/goaway.d.ts.map +1 -0
- package/lite/goaway.js +36 -0
- package/lite/goaway.js.map +1 -0
- package/lite/group.d.ts +18 -0
- package/lite/group.d.ts.map +1 -0
- package/lite/group.js +45 -0
- package/lite/group.js.map +1 -0
- package/lite/index.d.ts +11 -0
- package/lite/index.d.ts.map +1 -0
- package/lite/index.js +11 -0
- package/lite/index.js.map +1 -0
- package/lite/message.d.ts +5 -0
- package/lite/message.d.ts.map +1 -0
- package/lite/message.js +50 -0
- package/lite/message.js.map +1 -0
- package/lite/origin.d.ts +19 -0
- package/lite/origin.d.ts.map +1 -0
- package/lite/origin.js +28 -0
- package/lite/origin.js.map +1 -0
- package/lite/probe.d.ts +12 -0
- package/lite/probe.d.ts.map +1 -0
- package/lite/probe.js +59 -0
- package/lite/probe.js.map +1 -0
- package/lite/publisher.d.ts +56 -0
- package/lite/publisher.d.ts.map +1 -0
- package/lite/publisher.js +305 -0
- package/lite/publisher.js.map +1 -0
- package/lite/session.d.ts +36 -0
- package/lite/session.d.ts.map +1 -0
- package/lite/session.js +129 -0
- package/lite/session.js.map +1 -0
- package/lite/stream.d.ts +18 -0
- package/lite/stream.d.ts.map +1 -0
- package/lite/stream.js +11 -0
- package/lite/stream.js.map +1 -0
- package/lite/subscribe.d.ts +91 -0
- package/lite/subscribe.d.ts.map +1 -0
- package/lite/subscribe.js +267 -0
- package/lite/subscribe.js.map +1 -0
- package/lite/subscriber.d.ts +80 -0
- package/lite/subscriber.d.ts.map +1 -0
- package/lite/subscriber.js +245 -0
- package/lite/subscriber.js.map +1 -0
- package/lite/version.d.ts +12 -0
- package/lite/version.d.ts.map +1 -0
- package/lite/version.js +23 -0
- package/lite/version.js.map +1 -0
- package/mock.d.ts +16 -0
- package/mock.d.ts.map +1 -0
- package/mock.js +153 -0
- package/mock.js.map +1 -0
- package/package.json +27 -0
- package/path.d.ts +87 -0
- package/path.d.ts.map +1 -0
- package/path.js +98 -0
- package/path.js.map +1 -0
- package/path.test.d.ts +2 -0
- package/path.test.d.ts.map +1 -0
- package/path.test.js +153 -0
- package/path.test.js.map +1 -0
- package/stream.d.ts +57 -0
- package/stream.d.ts.map +1 -0
- package/stream.js +325 -0
- package/stream.js.map +1 -0
- package/stream.test.d.ts +2 -0
- package/stream.test.d.ts.map +1 -0
- package/stream.test.js +209 -0
- package/stream.test.js.map +1 -0
- package/time.d.ts +77 -0
- package/time.d.ts.map +1 -0
- package/time.js +65 -0
- package/time.js.map +1 -0
- package/track.d.ts +66 -0
- package/track.d.ts.map +1 -0
- package/track.js +203 -0
- package/track.js.map +1 -0
- package/track.test.d.ts +2 -0
- package/track.test.d.ts.map +1 -0
- package/track.test.js +39 -0
- package/track.test.js.map +1 -0
- package/util/error.d.ts +3 -0
- package/util/error.d.ts.map +1 -0
- package/util/error.js +8 -0
- package/util/error.js.map +1 -0
- package/util/hex.d.ts +2 -0
- package/util/hex.d.ts.map +1 -0
- package/util/hex.js +12 -0
- package/util/hex.js.map +1 -0
- package/util/index.d.ts +2 -0
- package/util/index.d.ts.map +1 -0
- package/util/index.js +2 -0
- package/util/index.js.map +1 -0
- package/varint.d.ts +28 -0
- package/varint.d.ts.map +1 -0
- package/varint.js +279 -0
- package/varint.js.map +1 -0
- package/varint.test.d.ts +2 -0
- package/varint.test.d.ts.map +1 -0
- package/varint.test.js +105 -0
- package/varint.test.js.map +1 -0
- package/zod.d.ts +6 -0
- package/zod.d.ts.map +1 -0
- package/zod.js +12 -0
- package/zod.js.map +1 -0
package/lite/announce.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import * as Path from "../path.js";
|
|
2
|
+
import * as Message from "./message.js";
|
|
3
|
+
import { OriginSchema } from "./origin.js";
|
|
4
|
+
import { Version } from "./version.js";
|
|
5
|
+
// Must match the MAX_HOPS in Rust's model/origin.rs. Broadcasts with longer
|
|
6
|
+
// hop chains are rejected; this keeps loop-detection bounded and rejects
|
|
7
|
+
// pathological announcements across clusters with unbounded forwarding.
|
|
8
|
+
export const MAX_HOPS = 32;
|
|
9
|
+
export class Announce {
|
|
10
|
+
suffix;
|
|
11
|
+
active;
|
|
12
|
+
hops;
|
|
13
|
+
constructor(props) {
|
|
14
|
+
this.suffix = props.suffix;
|
|
15
|
+
this.active = props.active;
|
|
16
|
+
this.hops = props.hops ?? [];
|
|
17
|
+
if (this.hops.length > MAX_HOPS) {
|
|
18
|
+
throw new Error(`hop count ${this.hops.length} exceeds maximum ${MAX_HOPS}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async #encode(w, version) {
|
|
22
|
+
await w.bool(this.active);
|
|
23
|
+
await w.string(this.suffix);
|
|
24
|
+
switch (version) {
|
|
25
|
+
case Version.DRAFT_01:
|
|
26
|
+
case Version.DRAFT_02:
|
|
27
|
+
break;
|
|
28
|
+
case Version.DRAFT_03:
|
|
29
|
+
await w.u53(this.hops.length);
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
// Lite04+: hop count + individual Origin varints.
|
|
33
|
+
await w.u53(this.hops.length);
|
|
34
|
+
for (const origin of this.hops) {
|
|
35
|
+
await w.u62(origin);
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
static async #decode(r, version) {
|
|
41
|
+
const active = await r.bool();
|
|
42
|
+
const suffix = Path.from(await r.string());
|
|
43
|
+
let hops = [];
|
|
44
|
+
switch (version) {
|
|
45
|
+
case Version.DRAFT_01:
|
|
46
|
+
case Version.DRAFT_02:
|
|
47
|
+
break;
|
|
48
|
+
case Version.DRAFT_03: {
|
|
49
|
+
const count = await r.u53();
|
|
50
|
+
if (count > MAX_HOPS)
|
|
51
|
+
throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);
|
|
52
|
+
// Lite03 carries only a hop count, not individual ids. Fill with
|
|
53
|
+
// the zero placeholder (OriginSchema accepts 0 as valid on-wire).
|
|
54
|
+
const placeholder = OriginSchema.parse(0n);
|
|
55
|
+
hops = new Array(count).fill(placeholder);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
default: {
|
|
59
|
+
// Lite04+: hop count + individual Origin varints.
|
|
60
|
+
const count = await r.u53();
|
|
61
|
+
if (count > MAX_HOPS)
|
|
62
|
+
throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);
|
|
63
|
+
hops = [];
|
|
64
|
+
for (let i = 0; i < count; i++) {
|
|
65
|
+
hops.push(OriginSchema.parse(await r.u62()));
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return new Announce({ suffix, active, hops });
|
|
71
|
+
}
|
|
72
|
+
async encode(w, version) {
|
|
73
|
+
return Message.encode(w, (w) => this.#encode(w, version));
|
|
74
|
+
}
|
|
75
|
+
static async decode(r, version) {
|
|
76
|
+
return Message.decode(r, (r) => Announce.#decode(r, version));
|
|
77
|
+
}
|
|
78
|
+
static async decodeMaybe(r, version) {
|
|
79
|
+
return Message.decodeMaybe(r, (r) => Announce.#decode(r, version));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export class AnnounceInterest {
|
|
83
|
+
prefix;
|
|
84
|
+
// 62-bit Origin id of the peer asking for announces. Zero means "no exclusion".
|
|
85
|
+
// Must be a bigint: peer origins are up to 62 bits and overflow u53.
|
|
86
|
+
excludeHop;
|
|
87
|
+
constructor(prefix, excludeHop = 0n) {
|
|
88
|
+
this.prefix = prefix;
|
|
89
|
+
this.excludeHop = excludeHop;
|
|
90
|
+
}
|
|
91
|
+
async #encode(w, version) {
|
|
92
|
+
await w.string(this.prefix);
|
|
93
|
+
switch (version) {
|
|
94
|
+
case Version.DRAFT_01:
|
|
95
|
+
case Version.DRAFT_02:
|
|
96
|
+
case Version.DRAFT_03:
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
// Lite04+: exclude_hop field (u62 varint).
|
|
100
|
+
await w.u62(this.excludeHop);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
static async #decode(r, version) {
|
|
105
|
+
const prefix = Path.from(await r.string());
|
|
106
|
+
let excludeHop = 0n;
|
|
107
|
+
switch (version) {
|
|
108
|
+
case Version.DRAFT_01:
|
|
109
|
+
case Version.DRAFT_02:
|
|
110
|
+
case Version.DRAFT_03:
|
|
111
|
+
break;
|
|
112
|
+
default:
|
|
113
|
+
excludeHop = await r.u62();
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
return new AnnounceInterest(prefix, excludeHop);
|
|
117
|
+
}
|
|
118
|
+
async encode(w, version) {
|
|
119
|
+
return Message.encode(w, (w) => this.#encode(w, version));
|
|
120
|
+
}
|
|
121
|
+
static async decode(r, version) {
|
|
122
|
+
return Message.decode(r, (r) => AnnounceInterest.#decode(r, version));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/// Sent after setup to communicate the initially announced paths.
|
|
126
|
+
///
|
|
127
|
+
/// Used by Draft01/Draft02 only. Draft03+ uses individual Announce messages instead.
|
|
128
|
+
export class AnnounceInit {
|
|
129
|
+
suffixes;
|
|
130
|
+
constructor(paths) {
|
|
131
|
+
this.suffixes = paths;
|
|
132
|
+
}
|
|
133
|
+
static #guard(version) {
|
|
134
|
+
switch (version) {
|
|
135
|
+
case Version.DRAFT_01:
|
|
136
|
+
case Version.DRAFT_02:
|
|
137
|
+
break;
|
|
138
|
+
default:
|
|
139
|
+
throw new Error("announce init not supported for this version");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async #encode(w) {
|
|
143
|
+
await w.u53(this.suffixes.length);
|
|
144
|
+
for (const path of this.suffixes) {
|
|
145
|
+
await w.string(path);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
static async #decode(r) {
|
|
149
|
+
const count = await r.u53();
|
|
150
|
+
const suffixes = [];
|
|
151
|
+
for (let i = 0; i < count; i++) {
|
|
152
|
+
suffixes.push(Path.from(await r.string()));
|
|
153
|
+
}
|
|
154
|
+
return new AnnounceInit(suffixes);
|
|
155
|
+
}
|
|
156
|
+
async encode(w, version) {
|
|
157
|
+
AnnounceInit.#guard(version);
|
|
158
|
+
return Message.encode(w, this.#encode.bind(this));
|
|
159
|
+
}
|
|
160
|
+
static async decode(r, version) {
|
|
161
|
+
AnnounceInit.#guard(version);
|
|
162
|
+
return Message.decode(r, AnnounceInit.#decode);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=announce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"announce.js","sourceRoot":"","sources":["../../src/lite/announce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,4EAA4E;AAC5E,yEAAyE;AACzE,wEAAwE;AACxE,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAC;AAE3B,MAAM,OAAO,QAAQ;IACpB,MAAM,CAAa;IACnB,MAAM,CAAU;IAChB,IAAI,CAAW;IAEf,YAAY,KAA+D;QAC1E,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,QAAQ,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,MAAM,oBAAoB,QAAQ,EAAE,CAAC,CAAC;QAC9E,CAAC;IACF,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS,EAAE,OAAgB;QACxC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE5B,QAAQ,OAAO,EAAE,CAAC;YACjB,KAAK,OAAO,CAAC,QAAQ,CAAC;YACtB,KAAK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CAAC,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;CACD","sourcesContent":["import * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { type Origin, OriginSchema } from \"./origin.ts\";\nimport { Version } from \"./version.ts\";\n\n// Must match the MAX_HOPS in Rust's model/origin.rs. Broadcasts with longer\n// hop chains are rejected; this keeps loop-detection bounded and rejects\n// pathological announcements across clusters with unbounded forwarding.\nexport const MAX_HOPS = 32;\n\nexport class Announce {\n\tsuffix: Path.Valid;\n\tactive: boolean;\n\thops: Origin[];\n\n\tconstructor(props: { suffix: Path.Valid; active: boolean; hops?: Origin[] }) {\n\t\tthis.suffix = props.suffix;\n\t\tthis.active = props.active;\n\t\tthis.hops = props.hops ?? [];\n\t\tif (this.hops.length > MAX_HOPS) {\n\t\t\tthrow new Error(`hop count ${this.hops.length} exceeds maximum ${MAX_HOPS}`);\n\t\t}\n\t}\n\n\tasync #encode(w: Writer, version: Version) {\n\t\tawait w.bool(this.active);\n\t\tawait w.string(this.suffix);\n\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\t\tbreak;\n\t\t\tcase Version.DRAFT_03:\n\t\t\t\tawait w.u53(this.hops.length);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t// Lite04+: hop count + individual Origin varints.\n\t\t\t\tawait w.u53(this.hops.length);\n\t\t\t\tfor (const origin of this.hops) {\n\t\t\t\t\tawait w.u62(origin);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader, version: Version): Promise<Announce> {\n\t\tconst active = await r.bool();\n\t\tconst suffix = Path.from(await r.string());\n\n\t\tlet hops: Origin[] = [];\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\t\tbreak;\n\t\t\tcase Version.DRAFT_03: {\n\t\t\t\tconst count = await r.u53();\n\t\t\t\tif (count > MAX_HOPS) throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);\n\t\t\t\t// Lite03 carries only a hop count, not individual ids. Fill with\n\t\t\t\t// the zero placeholder (OriginSchema accepts 0 as valid on-wire).\n\t\t\t\tconst placeholder = OriginSchema.parse(0n);\n\t\t\t\thops = new Array<Origin>(count).fill(placeholder);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\t// Lite04+: hop count + individual Origin varints.\n\t\t\t\tconst count = await r.u53();\n\t\t\t\tif (count > MAX_HOPS) throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);\n\t\t\t\thops = [];\n\t\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\t\thops.push(OriginSchema.parse(await r.u62()));\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn new Announce({ suffix, active, hops });\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\treturn Message.encode(w, (w) => this.#encode(w, version));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Announce> {\n\t\treturn Message.decode(r, (r) => Announce.#decode(r, version));\n\t}\n\n\tstatic async decodeMaybe(r: Reader, version: Version): Promise<Announce | undefined> {\n\t\treturn Message.decodeMaybe(r, (r) => Announce.#decode(r, version));\n\t}\n}\n\nexport class AnnounceInterest {\n\tprefix: Path.Valid;\n\t// 62-bit Origin id of the peer asking for announces. Zero means \"no exclusion\".\n\t// Must be a bigint: peer origins are up to 62 bits and overflow u53.\n\texcludeHop: bigint;\n\n\tconstructor(prefix: Path.Valid, excludeHop: bigint = 0n) {\n\t\tthis.prefix = prefix;\n\t\tthis.excludeHop = excludeHop;\n\t}\n\n\tasync #encode(w: Writer, version: Version) {\n\t\tawait w.string(this.prefix);\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\tcase Version.DRAFT_03:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t// Lite04+: exclude_hop field (u62 varint).\n\t\t\t\tawait w.u62(this.excludeHop);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader, version: Version): Promise<AnnounceInterest> {\n\t\tconst prefix = Path.from(await r.string());\n\t\tlet excludeHop = 0n;\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\tcase Version.DRAFT_03:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\texcludeHop = await r.u62();\n\t\t\t\tbreak;\n\t\t}\n\t\treturn new AnnounceInterest(prefix, excludeHop);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\treturn Message.encode(w, (w) => this.#encode(w, version));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceInterest> {\n\t\treturn Message.decode(r, (r) => AnnounceInterest.#decode(r, version));\n\t}\n}\n\n/// Sent after setup to communicate the initially announced paths.\n///\n/// Used by Draft01/Draft02 only. Draft03+ uses individual Announce messages instead.\nexport class AnnounceInit {\n\tsuffixes: Path.Valid[];\n\n\tconstructor(paths: Path.Valid[]) {\n\t\tthis.suffixes = paths;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"announce init not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u53(this.suffixes.length);\n\t\tfor (const path of this.suffixes) {\n\t\t\tawait w.string(path);\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceInit> {\n\t\tconst count = await r.u53();\n\t\tconst suffixes: Path.Valid[] = [];\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tsuffixes.push(Path.from(await r.string()));\n\t\t}\n\t\treturn new AnnounceInit(suffixes);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tAnnounceInit.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceInit> {\n\t\tAnnounceInit.#guard(version);\n\t\treturn Message.decode(r, AnnounceInit.#decode);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Signal } from "@moq/signals";
|
|
2
|
+
import type { Announced } from "../announced.ts";
|
|
3
|
+
import { type Bandwidth } from "../bandwidth.ts";
|
|
4
|
+
import type { Broadcast } from "../broadcast.ts";
|
|
5
|
+
import type { Established } from "../connection/established.ts";
|
|
6
|
+
import * as Path from "../path.ts";
|
|
7
|
+
import { Stream } from "../stream.ts";
|
|
8
|
+
import type * as Time from "../time.ts";
|
|
9
|
+
import { type Origin } from "./origin.ts";
|
|
10
|
+
import { Version } from "./version.ts";
|
|
11
|
+
/**
|
|
12
|
+
* Represents a connection to a MoQ server.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare class Connection implements Established {
|
|
17
|
+
#private;
|
|
18
|
+
readonly url: URL;
|
|
19
|
+
readonly version: string;
|
|
20
|
+
/** Estimated send bitrate from the congestion controller. */
|
|
21
|
+
readonly sendBandwidth?: Bandwidth;
|
|
22
|
+
/** Estimated receive bitrate from PROBE (moq-lite-03+ only). */
|
|
23
|
+
readonly recvBandwidth?: Bandwidth;
|
|
24
|
+
/** RTT in milliseconds from PROBE (moq-lite-04+ only). */
|
|
25
|
+
readonly rtt?: Signal<Time.Milli | undefined>;
|
|
26
|
+
/** Random per-connection origin id. Shared by Publisher (for outbound hop
|
|
27
|
+
* chains) and Subscriber (available for optional self-filtering on announces). */
|
|
28
|
+
readonly origin: Origin;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new Connection instance.
|
|
31
|
+
* @param url - The URL of the connection
|
|
32
|
+
* @param quic - The WebTransport session
|
|
33
|
+
* @param session - The session stream
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
constructor(url: URL, quic: WebTransport, version: Version, session?: Stream);
|
|
38
|
+
/**
|
|
39
|
+
* Closes the connection.
|
|
40
|
+
*/
|
|
41
|
+
close(): void;
|
|
42
|
+
publish(path: Path.Valid, broadcast: Broadcast): void;
|
|
43
|
+
announced(prefix?: Path.Valid): Announced;
|
|
44
|
+
consume(broadcast: Path.Valid): Broadcast;
|
|
45
|
+
get closed(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAwB,MAAM,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAC;AAIxC,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,aAAa,CAAC;AAMxD,OAAO,EAAE,OAAO,EAAe,MAAM,cAAc,CAAC;AAIpD;;;;GAIG;AACH,qBAAa,UAAW,YAAW,WAAW;;IAE7C,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAGlB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAiBzB,6DAA6D;IAC7D,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC;IAEnC,gEAAgE;IAChE,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC;IAEnC,0DAA0D;IAC1D,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IAE9C;sFACkF;IAClF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;;;;;OAOG;gBACS,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM;IA6B5E;;OAEG;IACH,KAAK;IAgCL,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS;IAI9C,SAAS,CAAC,MAAM,aAAe,GAAG,SAAS;IAI3C,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,GAAG,SAAS;IAyGzC,IAAI,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1B;CACD"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Signal } from "@moq/signals";
|
|
2
|
+
import { createBandwidth } from "../bandwidth.js";
|
|
3
|
+
import * as Path from "../path.js";
|
|
4
|
+
import { Readers, Stream } from "../stream.js";
|
|
5
|
+
import { AnnounceInterest } from "./announce.js";
|
|
6
|
+
import { Goaway } from "./goaway.js";
|
|
7
|
+
import { Group } from "./group.js";
|
|
8
|
+
import { randomOrigin } from "./origin.js";
|
|
9
|
+
import { Publisher } from "./publisher.js";
|
|
10
|
+
import { SessionInfo } from "./session.js";
|
|
11
|
+
import { StreamId } from "./stream.js";
|
|
12
|
+
import { Subscribe } from "./subscribe.js";
|
|
13
|
+
import { Subscriber } from "./subscriber.js";
|
|
14
|
+
import { Version, versionName } from "./version.js";
|
|
15
|
+
const SEND_BW_POLL_INTERVAL = 100; // ms
|
|
16
|
+
/**
|
|
17
|
+
* Represents a connection to a MoQ server.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export class Connection {
|
|
22
|
+
// The URL of the connection.
|
|
23
|
+
url;
|
|
24
|
+
// The version of the connection as a human-readable string.
|
|
25
|
+
version;
|
|
26
|
+
// The version used for encoding/decoding.
|
|
27
|
+
#version;
|
|
28
|
+
// The established WebTransport session.
|
|
29
|
+
#quic;
|
|
30
|
+
// Use to receive/send session messages.
|
|
31
|
+
#session;
|
|
32
|
+
// Module for contributing tracks.
|
|
33
|
+
#publisher;
|
|
34
|
+
// Module for distributing tracks.
|
|
35
|
+
#subscriber;
|
|
36
|
+
/** Estimated send bitrate from the congestion controller. */
|
|
37
|
+
sendBandwidth;
|
|
38
|
+
/** Estimated receive bitrate from PROBE (moq-lite-03+ only). */
|
|
39
|
+
recvBandwidth;
|
|
40
|
+
/** RTT in milliseconds from PROBE (moq-lite-04+ only). */
|
|
41
|
+
rtt;
|
|
42
|
+
/** Random per-connection origin id. Shared by Publisher (for outbound hop
|
|
43
|
+
* chains) and Subscriber (available for optional self-filtering on announces). */
|
|
44
|
+
origin;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new Connection instance.
|
|
47
|
+
* @param url - The URL of the connection
|
|
48
|
+
* @param quic - The WebTransport session
|
|
49
|
+
* @param session - The session stream
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
constructor(url, quic, version, session) {
|
|
54
|
+
this.url = url;
|
|
55
|
+
this.#quic = quic;
|
|
56
|
+
this.#session = session;
|
|
57
|
+
this.version = versionName(version);
|
|
58
|
+
this.#version = version;
|
|
59
|
+
// Send bandwidth is version-agnostic: depends on browser/QUIC support.
|
|
60
|
+
const hasGetStats = typeof quic.getStats === "function";
|
|
61
|
+
if (hasGetStats) {
|
|
62
|
+
this.sendBandwidth = createBandwidth();
|
|
63
|
+
}
|
|
64
|
+
// Recv bandwidth requires PROBE support (Lite03+).
|
|
65
|
+
if (version !== Version.DRAFT_01 && version !== Version.DRAFT_02) {
|
|
66
|
+
this.recvBandwidth = createBandwidth();
|
|
67
|
+
}
|
|
68
|
+
// RTT can be populated by PROBE (Lite04+) or getStats() (when supported).
|
|
69
|
+
// TODO prefer getStats() when both are available.
|
|
70
|
+
this.rtt = new Signal(undefined);
|
|
71
|
+
this.origin = randomOrigin();
|
|
72
|
+
this.#publisher = new Publisher(this.#quic, this.#version, this.origin);
|
|
73
|
+
this.#subscriber = new Subscriber(this.#quic, this.#version, this.origin, this.recvBandwidth, this.rtt);
|
|
74
|
+
this.#run();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Closes the connection.
|
|
78
|
+
*/
|
|
79
|
+
close() {
|
|
80
|
+
this.#publisher.close();
|
|
81
|
+
this.#subscriber.close();
|
|
82
|
+
try {
|
|
83
|
+
// TODO: For whatever reason, this try/catch doesn't seem to work..?
|
|
84
|
+
this.#quic.close();
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// ignore
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async #run() {
|
|
91
|
+
const tasks = [this.#runSession(), this.#runBidis(), this.#runUnis()];
|
|
92
|
+
if (this.sendBandwidth) {
|
|
93
|
+
tasks.push(this.#runSendBandwidth(this.sendBandwidth));
|
|
94
|
+
}
|
|
95
|
+
if (this.recvBandwidth) {
|
|
96
|
+
tasks.push(this.#subscriber.runProbe());
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
await Promise.all(tasks);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
console.error("fatal error running connection", err);
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
this.close();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
publish(path, broadcast) {
|
|
109
|
+
this.#publisher.publish(path, broadcast);
|
|
110
|
+
}
|
|
111
|
+
announced(prefix = Path.empty()) {
|
|
112
|
+
return this.#subscriber.announced(prefix);
|
|
113
|
+
}
|
|
114
|
+
consume(broadcast) {
|
|
115
|
+
return this.#subscriber.consume(broadcast);
|
|
116
|
+
}
|
|
117
|
+
async #runSession() {
|
|
118
|
+
if (!this.#session) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
for (;;) {
|
|
123
|
+
const msg = await SessionInfo.decodeMaybe(this.#session.reader, this.#version);
|
|
124
|
+
if (!msg)
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
console.debug("session stream closed");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async #runBidis() {
|
|
133
|
+
for (;;) {
|
|
134
|
+
const stream = await Stream.accept(this.#quic);
|
|
135
|
+
if (!stream)
|
|
136
|
+
break;
|
|
137
|
+
this.#runBidi(stream)
|
|
138
|
+
.catch((err) => {
|
|
139
|
+
stream.writer.reset(err);
|
|
140
|
+
})
|
|
141
|
+
.finally(() => {
|
|
142
|
+
stream.writer.close();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async #runBidi(stream) {
|
|
147
|
+
const typ = await stream.reader.u53();
|
|
148
|
+
if (typ === StreamId.Session) {
|
|
149
|
+
throw new Error("duplicate session stream");
|
|
150
|
+
}
|
|
151
|
+
else if (typ === StreamId.Announce) {
|
|
152
|
+
const msg = await AnnounceInterest.decode(stream.reader, this.#version);
|
|
153
|
+
await this.#publisher.runAnnounce(msg, stream);
|
|
154
|
+
}
|
|
155
|
+
else if (typ === StreamId.Subscribe) {
|
|
156
|
+
const msg = await Subscribe.decode(stream.reader, this.#version);
|
|
157
|
+
await this.#publisher.runSubscribe(msg, stream);
|
|
158
|
+
}
|
|
159
|
+
else if (typ === StreamId.Probe) {
|
|
160
|
+
await this.#publisher.runProbe(stream);
|
|
161
|
+
}
|
|
162
|
+
else if (typ === StreamId.Goaway) {
|
|
163
|
+
const msg = await Goaway.decode(stream.reader, this.#version);
|
|
164
|
+
console.info("received goaway:", msg.uri);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
throw new Error(`unknown stream type: ${typ.toString()}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async #runUnis() {
|
|
171
|
+
const readers = new Readers(this.#quic);
|
|
172
|
+
for (;;) {
|
|
173
|
+
const stream = await readers.next();
|
|
174
|
+
if (!stream)
|
|
175
|
+
break;
|
|
176
|
+
this.#runUni(stream)
|
|
177
|
+
.then(() => {
|
|
178
|
+
stream.stop(new Error("cancel"));
|
|
179
|
+
})
|
|
180
|
+
.catch((err) => {
|
|
181
|
+
stream.stop(err);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async #runUni(stream) {
|
|
186
|
+
const typ = await stream.u8();
|
|
187
|
+
if (typ === 0) {
|
|
188
|
+
const msg = await Group.decode(stream);
|
|
189
|
+
await this.#subscriber.runGroup(msg, stream);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
throw new Error(`unknown stream type: ${typ.toString()}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async #runSendBandwidth(bandwidth) {
|
|
196
|
+
const quic = this.#quic;
|
|
197
|
+
return new Promise((resolve) => {
|
|
198
|
+
const id = setInterval(async () => {
|
|
199
|
+
try {
|
|
200
|
+
const stats = await quic.getStats();
|
|
201
|
+
bandwidth.set(stats.estimatedSendRate ?? undefined);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
clearInterval(id);
|
|
205
|
+
resolve();
|
|
206
|
+
}
|
|
207
|
+
}, SEND_BW_POLL_INTERVAL);
|
|
208
|
+
void this.closed.then(() => {
|
|
209
|
+
clearInterval(id);
|
|
210
|
+
resolve();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
get closed() {
|
|
215
|
+
return this.#quic.closed.then(() => undefined);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAkB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlE,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEp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,CAAC;oBACJ,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACpC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,IAAI,SAAS,CAAC,CAAC;gBACrD,CAAC;gBAAC,MAAM,CAAC;oBACR,aAAa,CAAC,EAAE,CAAC,CAAC;oBAClB,OAAO,EAAE,CAAC;gBACX,CAAC;YACF,CAAC,EAAE,qBAAqB,CAAC,CAAC;YAE1B,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;gBAC1B,aAAa,CAAC,EAAE,CAAC,CAAC;gBAClB,OAAO,EAAE,CAAC;YACX,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;CACD","sourcesContent":["import { Signal } from \"@moq/signals\";\nimport type { Announced } from \"../announced.ts\";\nimport { type Bandwidth, createBandwidth } from \"../bandwidth.ts\";\nimport type { Broadcast } from \"../broadcast.ts\";\nimport type { Established } from \"../connection/established.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Readers, Stream } from \"../stream.ts\";\nimport type * as Time from \"../time.ts\";\nimport { AnnounceInterest } from \"./announce.ts\";\nimport { Goaway } from \"./goaway.ts\";\nimport { Group } from \"./group.ts\";\nimport { type Origin, randomOrigin } from \"./origin.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { SessionInfo } from \"./session.ts\";\nimport { StreamId } from \"./stream.ts\";\nimport { Subscribe } from \"./subscribe.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Version, versionName } from \"./version.ts\";\n\nconst SEND_BW_POLL_INTERVAL = 100; // ms\n\n/**\n * Represents a connection to a MoQ server.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The version of the connection as a human-readable string.\n\treadonly version: string;\n\n\t// The version used for encoding/decoding.\n\t#version: Version;\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Use to receive/send session messages.\n\t#session?: Stream;\n\n\t// Module for contributing tracks.\n\t#publisher: Publisher;\n\n\t// Module for distributing tracks.\n\t#subscriber: Subscriber;\n\n\t/** Estimated send bitrate from the congestion controller. */\n\treadonly sendBandwidth?: Bandwidth;\n\n\t/** Estimated receive bitrate from PROBE (moq-lite-03+ only). */\n\treadonly recvBandwidth?: Bandwidth;\n\n\t/** RTT in milliseconds from PROBE (moq-lite-04+ only). */\n\treadonly rtt?: Signal<Time.Milli | undefined>;\n\n\t/** Random per-connection origin id. Shared by Publisher (for outbound hop\n\t * chains) and Subscriber (available for optional self-filtering on announces). */\n\treadonly origin: Origin;\n\n\t/**\n\t * Creates a new Connection instance.\n\t * @param url - The URL of the connection\n\t * @param quic - The WebTransport session\n\t * @param session - The session stream\n\t *\n\t * @internal\n\t */\n\tconstructor(url: URL, quic: WebTransport, version: Version, session?: Stream) {\n\t\tthis.url = url;\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\tthis.version = versionName(version);\n\t\tthis.#version = version;\n\n\t\t// Send bandwidth is version-agnostic: depends on browser/QUIC support.\n\t\tconst hasGetStats = typeof (quic as unknown as { getStats?: unknown }).getStats === \"function\";\n\t\tif (hasGetStats) {\n\t\t\tthis.sendBandwidth = createBandwidth();\n\t\t}\n\n\t\t// Recv bandwidth requires PROBE support (Lite03+).\n\t\tif (version !== Version.DRAFT_01 && version !== Version.DRAFT_02) {\n\t\t\tthis.recvBandwidth = createBandwidth();\n\t\t}\n\n\t\t// RTT can be populated by PROBE (Lite04+) or getStats() (when supported).\n\t\t// TODO prefer getStats() when both are available.\n\t\tthis.rtt = new Signal<Time.Milli | undefined>(undefined);\n\n\t\tthis.origin = randomOrigin();\n\t\tthis.#publisher = new Publisher(this.#quic, this.#version, this.origin);\n\t\tthis.#subscriber = new Subscriber(this.#quic, this.#version, this.origin, this.recvBandwidth, this.rtt);\n\n\t\tthis.#run();\n\t}\n\n\t/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tthis.#publisher.close();\n\t\tthis.#subscriber.close();\n\n\t\ttry {\n\t\t\t// TODO: For whatever reason, this try/catch doesn't seem to work..?\n\t\t\tthis.#quic.close();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tasync #run(): Promise<void> {\n\t\tconst tasks: Promise<void>[] = [this.#runSession(), this.#runBidis(), this.#runUnis()];\n\n\t\tif (this.sendBandwidth) {\n\t\t\ttasks.push(this.#runSendBandwidth(this.sendBandwidth));\n\t\t}\n\n\t\tif (this.recvBandwidth) {\n\t\t\ttasks.push(this.#subscriber.runProbe());\n\t\t}\n\n\t\ttry {\n\t\t\tawait Promise.all(tasks);\n\t\t} catch (err) {\n\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tpublish(path: Path.Valid, broadcast: Broadcast) {\n\t\tthis.#publisher.publish(path, broadcast);\n\t}\n\n\tannounced(prefix = Path.empty()): Announced {\n\t\treturn this.#subscriber.announced(prefix);\n\t}\n\n\tconsume(broadcast: Path.Valid): Broadcast {\n\t\treturn this.#subscriber.consume(broadcast);\n\t}\n\n\tasync #runSession() {\n\t\tif (!this.#session) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst msg = await SessionInfo.decodeMaybe(this.#session.reader, this.#version);\n\t\t\t\tif (!msg) break;\n\t\t\t}\n\t\t} finally {\n\t\t\tconsole.debug(\"session stream closed\");\n\t\t}\n\t}\n\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await Stream.accept(this.#quic);\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runBidi(stream)\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.writer.reset(err);\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tstream.writer.close();\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runBidi(stream: Stream) {\n\t\tconst typ = await stream.reader.u53();\n\n\t\tif (typ === StreamId.Session) {\n\t\t\tthrow new Error(\"duplicate session stream\");\n\t\t} else if (typ === StreamId.Announce) {\n\t\t\tconst msg = await AnnounceInterest.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runAnnounce(msg, stream);\n\t\t} else if (typ === StreamId.Subscribe) {\n\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t} else if (typ === StreamId.Probe) {\n\t\t\tawait this.#publisher.runProbe(stream);\n\t\t} else if (typ === StreamId.Goaway) {\n\t\t\tconst msg = await Goaway.decode(stream.reader, this.#version);\n\t\t\tconsole.info(\"received goaway:\", msg.uri);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\tasync #runUnis() {\n\t\tconst readers = new Readers(this.#quic);\n\n\t\tfor (;;) {\n\t\t\tconst stream = await readers.next();\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runUni(stream)\n\t\t\t\t.then(() => {\n\t\t\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t\t\t})\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.stop(err);\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runUni(stream: Reader) {\n\t\tconst typ = await stream.u8();\n\t\tif (typ === 0) {\n\t\t\tconst msg = await Group.decode(stream);\n\t\t\tawait this.#subscriber.runGroup(msg, stream);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\tasync #runSendBandwidth(bandwidth: Bandwidth): Promise<void> {\n\t\tconst quic = this.#quic as unknown as {\n\t\t\tgetStats: () => Promise<{ estimatedSendRate: number | null }>;\n\t\t};\n\n\t\treturn new Promise<void>((resolve) => {\n\t\t\tconst id = setInterval(async () => {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = await quic.getStats();\n\t\t\t\t\tbandwidth.set(stats.estimatedSendRate ?? undefined);\n\t\t\t\t} catch {\n\t\t\t\t\tclearInterval(id);\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t}, SEND_BW_POLL_INTERVAL);\n\n\t\t\tvoid this.closed.then(() => {\n\t\t\t\tclearInterval(id);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\t}\n\n\tget closed(): Promise<void> {\n\t\treturn this.#quic.closed.then(() => undefined);\n\t}\n}\n"]}
|
package/lite/fetch.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as Path from "../path.ts";
|
|
2
|
+
import type { Reader, Writer } from "../stream.ts";
|
|
3
|
+
import { Version } from "./version.ts";
|
|
4
|
+
export declare class Fetch {
|
|
5
|
+
#private;
|
|
6
|
+
broadcast: Path.Valid;
|
|
7
|
+
track: string;
|
|
8
|
+
priority: number;
|
|
9
|
+
group: number;
|
|
10
|
+
constructor(broadcast: Path.Valid, track: string, priority: number, group: number);
|
|
11
|
+
encode(w: Writer, version: Version): Promise<void>;
|
|
12
|
+
static decode(r: Reader, version: Version): Promise<Fetch>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/lite/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAYvC,qBAAa,KAAK;;IACjB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;gBAEF,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAsB3E,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;WAK3C,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;CAIhE"}
|
package/lite/fetch.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as Path from "../path.js";
|
|
2
|
+
import * as Message from "./message.js";
|
|
3
|
+
import { Version } from "./version.js";
|
|
4
|
+
function guardFetch(version) {
|
|
5
|
+
switch (version) {
|
|
6
|
+
case Version.DRAFT_01:
|
|
7
|
+
case Version.DRAFT_02:
|
|
8
|
+
throw new Error("fetch not supported for this version");
|
|
9
|
+
default:
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class Fetch {
|
|
14
|
+
broadcast;
|
|
15
|
+
track;
|
|
16
|
+
priority;
|
|
17
|
+
group;
|
|
18
|
+
constructor(broadcast, track, priority, group) {
|
|
19
|
+
this.broadcast = broadcast;
|
|
20
|
+
this.track = track;
|
|
21
|
+
this.priority = priority;
|
|
22
|
+
this.group = group;
|
|
23
|
+
}
|
|
24
|
+
async #encode(w) {
|
|
25
|
+
await w.string(this.broadcast);
|
|
26
|
+
await w.string(this.track);
|
|
27
|
+
await w.u8(this.priority);
|
|
28
|
+
await w.u53(this.group);
|
|
29
|
+
}
|
|
30
|
+
static async #decode(r) {
|
|
31
|
+
const broadcast = Path.from(await r.string());
|
|
32
|
+
const track = await r.string();
|
|
33
|
+
const priority = await r.u8();
|
|
34
|
+
const group = await r.u53();
|
|
35
|
+
return new Fetch(broadcast, track, priority, group);
|
|
36
|
+
}
|
|
37
|
+
async encode(w, version) {
|
|
38
|
+
guardFetch(version);
|
|
39
|
+
return Message.encode(w, this.#encode.bind(this));
|
|
40
|
+
}
|
|
41
|
+
static async decode(r, version) {
|
|
42
|
+
guardFetch(version);
|
|
43
|
+
return Message.decode(r, Fetch.#decode);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/lite/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,SAAS,UAAU,CAAC,OAAgB;IACnC,QAAQ,OAAO,EAAE,CAAC;QACjB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ;YACpB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QACzD;YACC,MAAM;IACR,CAAC;AACF,CAAC;AAED,MAAM,OAAO,KAAK;IACjB,SAAS,CAAa;IACtB,KAAK,CAAS;IACd,QAAQ,CAAS;IACjB,KAAK,CAAS;IAEd,YAAY,SAAqB,EAAE,KAAa,EAAE,QAAgB,EAAE,KAAa;QAChF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACtB,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/B,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3B,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1B,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAS;QAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;QAC5B,OAAO,IAAI,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,UAAU,CAAC,OAAO,CAAC,CAAC;QACpB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,UAAU,CAAC,OAAO,CAAC,CAAC;QACpB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACD","sourcesContent":["import * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction guardFetch(version: Version) {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\tthrow new Error(\"fetch not supported for this version\");\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\nexport class Fetch {\n\tbroadcast: Path.Valid;\n\ttrack: string;\n\tpriority: number;\n\tgroup: number;\n\n\tconstructor(broadcast: Path.Valid, track: string, priority: number, group: number) {\n\t\tthis.broadcast = broadcast;\n\t\tthis.track = track;\n\t\tthis.priority = priority;\n\t\tthis.group = group;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.string(this.broadcast);\n\t\tawait w.string(this.track);\n\t\tawait w.u8(this.priority);\n\t\tawait w.u53(this.group);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Fetch> {\n\t\tconst broadcast = Path.from(await r.string());\n\t\tconst track = await r.string();\n\t\tconst priority = await r.u8();\n\t\tconst group = await r.u53();\n\t\treturn new Fetch(broadcast, track, priority, group);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardFetch(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Fetch> {\n\t\tguardFetch(version);\n\t\treturn Message.decode(r, Fetch.#decode);\n\t}\n}\n"]}
|
package/lite/goaway.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Reader, Writer } from "../stream.ts";
|
|
2
|
+
import { Version } from "./version.ts";
|
|
3
|
+
export declare class Goaway {
|
|
4
|
+
#private;
|
|
5
|
+
uri: string;
|
|
6
|
+
constructor(uri: string);
|
|
7
|
+
encode(w: Writer, version: Version): Promise<void>;
|
|
8
|
+
static decode(r: Reader, version: Version): Promise<Goaway>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=goaway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goaway.d.ts","sourceRoot":"","sources":["../../src/lite/goaway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAgBvC,qBAAa,MAAM;;IAClB,GAAG,EAAE,MAAM,CAAC;gBAEA,GAAG,EAAE,MAAM;IAYjB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;WAK3C,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;CAIjE"}
|
package/lite/goaway.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as Message from "./message.js";
|
|
2
|
+
import { Version } from "./version.js";
|
|
3
|
+
function guardGoaway(version) {
|
|
4
|
+
switch (version) {
|
|
5
|
+
case Version.DRAFT_01:
|
|
6
|
+
case Version.DRAFT_02:
|
|
7
|
+
case Version.DRAFT_03:
|
|
8
|
+
throw new Error("goaway not supported for this version");
|
|
9
|
+
default:
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/// Sent to gracefully shut down a session and optionally redirect to a new URI.
|
|
14
|
+
///
|
|
15
|
+
/// Lite04+ only.
|
|
16
|
+
export class Goaway {
|
|
17
|
+
uri;
|
|
18
|
+
constructor(uri) {
|
|
19
|
+
this.uri = uri;
|
|
20
|
+
}
|
|
21
|
+
async #encode(w) {
|
|
22
|
+
await w.string(this.uri);
|
|
23
|
+
}
|
|
24
|
+
static async #decode(r) {
|
|
25
|
+
return new Goaway(await r.string());
|
|
26
|
+
}
|
|
27
|
+
async encode(w, version) {
|
|
28
|
+
guardGoaway(version);
|
|
29
|
+
return Message.encode(w, this.#encode.bind(this));
|
|
30
|
+
}
|
|
31
|
+
static async decode(r, version) {
|
|
32
|
+
guardGoaway(version);
|
|
33
|
+
return Message.decode(r, Goaway.#decode);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=goaway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goaway.js","sourceRoot":"","sources":["../../src/lite/goaway.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,SAAS,WAAW,CAAC,OAAgB;IACpC,QAAQ,OAAO,EAAE,CAAC;QACjB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ;YACpB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC1D;YACC,MAAM;IACR,CAAC;AACF,CAAC;AAED,gFAAgF;AAChF,GAAG;AACH,iBAAiB;AACjB,MAAM,OAAO,MAAM;IAClB,GAAG,CAAS;IAEZ,YAAY,GAAW;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACtB,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAS;QAC7B,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,WAAW,CAAC,OAAO,CAAC,CAAC;QACrB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,WAAW,CAAC,OAAO,CAAC,CAAC;QACrB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;CACD","sourcesContent":["import type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction guardGoaway(version: Version) {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\t\tthrow new Error(\"goaway not supported for this version\");\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\n/// Sent to gracefully shut down a session and optionally redirect to a new URI.\n///\n/// Lite04+ only.\nexport class Goaway {\n\turi: string;\n\n\tconstructor(uri: string) {\n\t\tthis.uri = uri;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.string(this.uri);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Goaway> {\n\t\treturn new Goaway(await r.string());\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardGoaway(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Goaway> {\n\t\tguardGoaway(version);\n\t\treturn Message.decode(r, Goaway.#decode);\n\t}\n}\n"]}
|
package/lite/group.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Reader, Writer } from "../stream.ts";
|
|
2
|
+
export declare class Group {
|
|
3
|
+
#private;
|
|
4
|
+
subscribe: bigint;
|
|
5
|
+
sequence: number;
|
|
6
|
+
constructor(subscribe: bigint, sequence: number);
|
|
7
|
+
encode(w: Writer): Promise<void>;
|
|
8
|
+
static decode(r: Reader): Promise<Group>;
|
|
9
|
+
static decodeMaybe(r: Reader): Promise<Group | undefined>;
|
|
10
|
+
}
|
|
11
|
+
export declare class Frame {
|
|
12
|
+
#private;
|
|
13
|
+
payload: Uint8Array;
|
|
14
|
+
constructor(payload: Uint8Array);
|
|
15
|
+
encode(w: Writer): Promise<void>;
|
|
16
|
+
static decode(r: Reader): Promise<Frame>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/lite/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,qBAAa,KAAK;;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;gBAEL,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAczC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAIzB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;WAIjC,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;CAG/D;AAED,qBAAa,KAAK;;IACjB,OAAO,EAAE,UAAU,CAAC;gBAER,OAAO,EAAE,UAAU;IAazB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAIzB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;CAG9C"}
|