@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
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { Signal } from "@moq/signals";
|
|
2
|
+
import * as Path from "../path.js";
|
|
3
|
+
import { Writer } from "../stream.js";
|
|
4
|
+
import { error } from "../util/error.js";
|
|
5
|
+
import { Announce, AnnounceInit } from "./announce.js";
|
|
6
|
+
import { Group as GroupMessage } from "./group.js";
|
|
7
|
+
import { Probe } from "./probe.js";
|
|
8
|
+
import { encodeSubscribeResponse, SubscribeOk, SubscribeUpdate } from "./subscribe.js";
|
|
9
|
+
import { Version } from "./version.js";
|
|
10
|
+
const PROBE_INTERVAL = 100; // ms
|
|
11
|
+
const PROBE_MAX_AGE = 10_000; // ms
|
|
12
|
+
const PROBE_MAX_DELTA = 0.25;
|
|
13
|
+
/**
|
|
14
|
+
* Handles publishing broadcasts and managing their lifecycle.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export class Publisher {
|
|
19
|
+
// The version of the connection.
|
|
20
|
+
version;
|
|
21
|
+
// Per-connection origin appended to outbound Announce hops, so the peer
|
|
22
|
+
// can detect loops and prefer shorter paths. Created by Connection and
|
|
23
|
+
// shared with Subscriber, which can optionally use it to filter out its
|
|
24
|
+
// own announcements.
|
|
25
|
+
origin;
|
|
26
|
+
#quic;
|
|
27
|
+
// Our published broadcasts.
|
|
28
|
+
// It's a signal so we can live update any announce streams.
|
|
29
|
+
#broadcasts = new Signal(new Map());
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new Publisher instance.
|
|
32
|
+
* @param quic - The WebTransport session to use
|
|
33
|
+
* @param version - Negotiated protocol version
|
|
34
|
+
* @param origin - Origin id shared with the Subscriber
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
constructor(quic, version, origin) {
|
|
39
|
+
this.#quic = quic;
|
|
40
|
+
this.version = version;
|
|
41
|
+
this.origin = origin;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Publishes a broadcast with any associated tracks.
|
|
45
|
+
* @param name - The broadcast to publish
|
|
46
|
+
*/
|
|
47
|
+
publish(path, broadcast) {
|
|
48
|
+
this.#broadcasts.mutate((broadcasts) => {
|
|
49
|
+
if (!broadcasts)
|
|
50
|
+
throw new Error("closed");
|
|
51
|
+
broadcasts.set(path, broadcast);
|
|
52
|
+
});
|
|
53
|
+
// Remove the broadcast from the lookup when it's closed.
|
|
54
|
+
void broadcast.closed.finally(() => {
|
|
55
|
+
this.#broadcasts.mutate((broadcasts) => {
|
|
56
|
+
broadcasts?.delete(path);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Handles an announce interest message.
|
|
62
|
+
* @param msg - The announce interest message
|
|
63
|
+
* @param stream - The stream to write announcements to
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
async runAnnounce(msg, stream) {
|
|
68
|
+
console.debug(`announce: prefix=${msg.prefix}`);
|
|
69
|
+
// Send initial announcements
|
|
70
|
+
let active = new Set();
|
|
71
|
+
const broadcasts = this.#broadcasts.peek();
|
|
72
|
+
if (!broadcasts)
|
|
73
|
+
return; // closed
|
|
74
|
+
for (const name of broadcasts.keys()) {
|
|
75
|
+
const suffix = Path.stripPrefix(msg.prefix, name);
|
|
76
|
+
if (suffix === null)
|
|
77
|
+
continue;
|
|
78
|
+
console.debug(`announce: broadcast=${name} active=true`);
|
|
79
|
+
active.add(suffix);
|
|
80
|
+
}
|
|
81
|
+
switch (this.version) {
|
|
82
|
+
case Version.DRAFT_01:
|
|
83
|
+
case Version.DRAFT_02: {
|
|
84
|
+
const init = new AnnounceInit([...active]);
|
|
85
|
+
await init.encode(stream.writer, this.version);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
// Draft03+: send individual Announce messages for initial state.
|
|
90
|
+
for (const suffix of active) {
|
|
91
|
+
const wire = new Announce({ suffix, active: true, hops: [this.origin] });
|
|
92
|
+
await wire.encode(stream.writer, this.version);
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
// Wait for updates to the broadcasts.
|
|
97
|
+
for (;;) {
|
|
98
|
+
// TODO Make a better helper within Signals.
|
|
99
|
+
let dispose;
|
|
100
|
+
const changed = new Promise((resolve) => {
|
|
101
|
+
dispose = this.#broadcasts.changed(resolve);
|
|
102
|
+
});
|
|
103
|
+
// Wait until the map of broadcasts changes.
|
|
104
|
+
const broadcasts = await Promise.race([changed, stream.reader.closed]);
|
|
105
|
+
dispose();
|
|
106
|
+
if (!broadcasts)
|
|
107
|
+
break;
|
|
108
|
+
// Create a new set of active broadcasts.
|
|
109
|
+
// This is SLOW, but it's not worth optimizing because we often have just 1 broadcast anyway.
|
|
110
|
+
const newActive = new Set();
|
|
111
|
+
for (const name of broadcasts.keys()) {
|
|
112
|
+
const suffix = Path.stripPrefix(msg.prefix, name);
|
|
113
|
+
if (suffix === null)
|
|
114
|
+
continue; // Not our prefix.
|
|
115
|
+
newActive.add(suffix);
|
|
116
|
+
}
|
|
117
|
+
// Announce any new broadcasts.
|
|
118
|
+
for (const added of newActive.difference(active)) {
|
|
119
|
+
console.debug(`announce: broadcast=${added} active=true`);
|
|
120
|
+
const wire = new Announce({ suffix: added, active: true, hops: [this.origin] });
|
|
121
|
+
await wire.encode(stream.writer, this.version);
|
|
122
|
+
}
|
|
123
|
+
// Announce any removed broadcasts.
|
|
124
|
+
// Ended announces don't need hops — the peer matches on path only.
|
|
125
|
+
for (const removed of active.difference(newActive)) {
|
|
126
|
+
console.debug(`announce: broadcast=${removed} active=false`);
|
|
127
|
+
const wire = new Announce({ suffix: removed, active: false });
|
|
128
|
+
await wire.encode(stream.writer, this.version);
|
|
129
|
+
}
|
|
130
|
+
// NOTE: This is kind of a hack that won't work with a rapid UNANNOUNCE/ANNOUNCE cycle.
|
|
131
|
+
// However, our client doesn't do that anyway.
|
|
132
|
+
active = newActive;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Handles a subscribe message.
|
|
137
|
+
* @param msg - The subscribe message
|
|
138
|
+
* @param stream - The stream to write track data to
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
async runSubscribe(msg, stream) {
|
|
143
|
+
const broadcast = this.#broadcasts.peek()?.get(msg.broadcast);
|
|
144
|
+
if (!broadcast) {
|
|
145
|
+
console.debug(`publish unknown: broadcast=${msg.broadcast}`);
|
|
146
|
+
stream.writer.reset(new Error("not found"));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const track = broadcast.subscribe(msg.track, msg.priority);
|
|
150
|
+
try {
|
|
151
|
+
const info = new SubscribeOk({ priority: msg.priority });
|
|
152
|
+
await encodeSubscribeResponse(stream.writer, { ok: info }, this.version);
|
|
153
|
+
console.debug(`publish ok: broadcast=${msg.broadcast} track=${track.name}`);
|
|
154
|
+
const serving = this.#runTrack(msg.id, msg.broadcast, track, stream.writer);
|
|
155
|
+
for (;;) {
|
|
156
|
+
const decode = SubscribeUpdate.decodeMaybe(stream.reader, this.version);
|
|
157
|
+
const result = await Promise.any([serving, decode]);
|
|
158
|
+
if (!result)
|
|
159
|
+
break;
|
|
160
|
+
if (result instanceof SubscribeUpdate) {
|
|
161
|
+
// TODO use the update
|
|
162
|
+
console.warn("subscribe update not supported", result);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
console.debug(`publish done: broadcast=${msg.broadcast} track=${track.name}`);
|
|
166
|
+
stream.close();
|
|
167
|
+
track.close();
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
const e = error(err);
|
|
171
|
+
console.warn(`publish error: broadcast=${msg.broadcast} track=${track.name} error=${e.message}`);
|
|
172
|
+
track.close(e);
|
|
173
|
+
stream.abort(e);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Runs a track and sends its data to the stream.
|
|
178
|
+
* @param sub - The subscription ID
|
|
179
|
+
* @param broadcast - The broadcast name
|
|
180
|
+
* @param track - The track to run
|
|
181
|
+
* @param stream - The stream to write to
|
|
182
|
+
*
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
185
|
+
async #runTrack(sub, broadcast, track, stream) {
|
|
186
|
+
try {
|
|
187
|
+
for (;;) {
|
|
188
|
+
const next = track.recvGroup();
|
|
189
|
+
const group = await Promise.race([next, stream.closed]);
|
|
190
|
+
if (!group) {
|
|
191
|
+
next.then((group) => group?.close()).catch(() => { });
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
void this.#runGroup(sub, group);
|
|
195
|
+
}
|
|
196
|
+
console.debug(`publish close: broadcast=${broadcast} track=${track.name}`);
|
|
197
|
+
track.close();
|
|
198
|
+
stream.close();
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
const e = error(err);
|
|
202
|
+
console.warn(`publish error: broadcast=${broadcast} track=${track.name} error=${e.message}`);
|
|
203
|
+
track.close(e);
|
|
204
|
+
stream.reset(e);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Runs a group and sends its frames to the stream.
|
|
209
|
+
* @param sub - The subscription ID
|
|
210
|
+
* @param group - The group to run
|
|
211
|
+
*
|
|
212
|
+
* @internal
|
|
213
|
+
*/
|
|
214
|
+
async #runGroup(sub, group) {
|
|
215
|
+
const msg = new GroupMessage(sub, group.sequence);
|
|
216
|
+
try {
|
|
217
|
+
const stream = await Writer.open(this.#quic);
|
|
218
|
+
await stream.u8(0); // stream type
|
|
219
|
+
await msg.encode(stream);
|
|
220
|
+
try {
|
|
221
|
+
for (;;) {
|
|
222
|
+
const frame = await Promise.race([group.readFrame(), stream.closed]);
|
|
223
|
+
if (!frame)
|
|
224
|
+
break;
|
|
225
|
+
await stream.u53(frame.byteLength);
|
|
226
|
+
await stream.write(frame);
|
|
227
|
+
}
|
|
228
|
+
stream.close();
|
|
229
|
+
group.close();
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
const e = error(err);
|
|
233
|
+
stream.reset(e);
|
|
234
|
+
group.close(e);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
const e = error(err);
|
|
239
|
+
group.close(e);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Handles a probe stream by periodically reporting estimated bitrate.
|
|
244
|
+
* @param stream - The probe bidi stream
|
|
245
|
+
*
|
|
246
|
+
* @internal
|
|
247
|
+
*/
|
|
248
|
+
async runProbe(stream) {
|
|
249
|
+
// getStats is not yet in the TypeScript WebTransport type definitions.
|
|
250
|
+
const quic = this.#quic;
|
|
251
|
+
if (!quic.getStats) {
|
|
252
|
+
// Best-effort: we can't supply bandwidth estimates, so close the
|
|
253
|
+
// whole bidi (FIN + STOP_SENDING) to let the peer release its end.
|
|
254
|
+
stream.close();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
let lastSentBitrate;
|
|
258
|
+
let lastSentTime;
|
|
259
|
+
try {
|
|
260
|
+
for (;;) {
|
|
261
|
+
const timeout = new Promise((resolve) => setTimeout(() => resolve("timeout"), PROBE_INTERVAL));
|
|
262
|
+
const result = await Promise.race([timeout, stream.reader.closed]);
|
|
263
|
+
if (result !== "timeout")
|
|
264
|
+
break;
|
|
265
|
+
const stats = await quic.getStats();
|
|
266
|
+
const bitrate = stats.estimatedSendRate;
|
|
267
|
+
if (bitrate == null)
|
|
268
|
+
continue;
|
|
269
|
+
let shouldSend;
|
|
270
|
+
if (lastSentBitrate === undefined || lastSentTime === undefined) {
|
|
271
|
+
shouldSend = true;
|
|
272
|
+
}
|
|
273
|
+
else if (lastSentBitrate === 0) {
|
|
274
|
+
shouldSend = bitrate > 0;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
const elapsed = performance.now() - lastSentTime;
|
|
278
|
+
const t = Math.max(PROBE_INTERVAL, Math.min(PROBE_MAX_AGE, elapsed));
|
|
279
|
+
const range = PROBE_MAX_AGE - PROBE_INTERVAL;
|
|
280
|
+
const threshold = (PROBE_MAX_DELTA * (PROBE_MAX_AGE - t)) / range;
|
|
281
|
+
const change = Math.abs(bitrate - lastSentBitrate) / lastSentBitrate;
|
|
282
|
+
shouldSend = change >= threshold;
|
|
283
|
+
}
|
|
284
|
+
if (shouldSend) {
|
|
285
|
+
await new Probe(bitrate).encode(stream.writer, this.version);
|
|
286
|
+
lastSentBitrate = bitrate;
|
|
287
|
+
lastSentTime = performance.now();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
console.warn("probe stream error", err);
|
|
293
|
+
stream.close();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
close() {
|
|
297
|
+
this.#broadcasts.update((broadcasts) => {
|
|
298
|
+
for (const broadcast of broadcasts?.values() ?? []) {
|
|
299
|
+
broadcast.close();
|
|
300
|
+
}
|
|
301
|
+
return undefined;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=publisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/lite/publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAyB,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,uBAAuB,EAAkB,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvG,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,cAAc,GAAG,GAAG,CAAC,CAAC,KAAK;AACjC,MAAM,aAAa,GAAG,MAAM,CAAC,CAAC,KAAK;AACnC,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B;;;;GAIG;AACH,MAAM,OAAO,SAAS;IACrB,iCAAiC;IACxB,OAAO,CAAU;IAE1B,wEAAwE;IACxE,uEAAuE;IACvE,wEAAwE;IACxE,qBAAqB;IACZ,MAAM,CAAS;IAExB,KAAK,CAAe;IAEpB,4BAA4B;IAC5B,4DAA4D;IAC5D,WAAW,GAAG,IAAI,MAAM,CAAyC,IAAI,GAAG,EAAE,CAAC,CAAC;I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C,UAAU,EAAE,EAAE;YACtC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;gBACpD,SAAS,CAAC,KAAK,EAAE,CAAC;YACnB,CAAC;YACD,OAAO,SAAS,CAAC;QAClB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import { type Dispose, Signal } from \"@moq/signals\";\nimport type { Broadcast } from \"../broadcast.ts\";\nimport type { Group } from \"../group.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Stream, Writer } from \"../stream.ts\";\nimport type { Track } from \"../track.ts\";\nimport { error } from \"../util/error.ts\";\nimport { Announce, AnnounceInit, type AnnounceInterest } from \"./announce.ts\";\nimport { Group as GroupMessage } from \"./group.ts\";\nimport type { Origin } from \"./origin.ts\";\nimport { Probe } from \"./probe.ts\";\nimport { encodeSubscribeResponse, type Subscribe, SubscribeOk, SubscribeUpdate } from \"./subscribe.ts\";\nimport { Version } from \"./version.ts\";\n\nconst PROBE_INTERVAL = 100; // ms\nconst PROBE_MAX_AGE = 10_000; // ms\nconst PROBE_MAX_DELTA = 0.25;\n\n/**\n * Handles publishing broadcasts and managing their lifecycle.\n *\n * @internal\n */\nexport class Publisher {\n\t// The version of the connection.\n\treadonly version: Version;\n\n\t// Per-connection origin appended to outbound Announce hops, so the peer\n\t// can detect loops and prefer shorter paths. Created by Connection and\n\t// shared with Subscriber, which can optionally use it to filter out its\n\t// own announcements.\n\treadonly origin: Origin;\n\n\t#quic: WebTransport;\n\n\t// Our published broadcasts.\n\t// It's a signal so we can live update any announce streams.\n\t#broadcasts = new Signal<Map<Path.Valid, Broadcast> | undefined>(new Map());\n\n\t/**\n\t * Creates a new Publisher instance.\n\t * @param quic - The WebTransport session to use\n\t * @param version - Negotiated protocol version\n\t * @param origin - Origin id shared with the Subscriber\n\t *\n\t * @internal\n\t */\n\tconstructor(quic: WebTransport, version: Version, origin: Origin) {\n\t\tthis.#quic = quic;\n\t\tthis.version = version;\n\t\tthis.origin = origin;\n\t}\n\n\t/**\n\t * Publishes a broadcast with any associated tracks.\n\t * @param name - The broadcast to publish\n\t */\n\tpublish(path: Path.Valid, broadcast: Broadcast) {\n\t\tthis.#broadcasts.mutate((broadcasts) => {\n\t\t\tif (!broadcasts) throw new Error(\"closed\");\n\t\t\tbroadcasts.set(path, broadcast);\n\t\t});\n\n\t\t// Remove the broadcast from the lookup when it's closed.\n\t\tvoid broadcast.closed.finally(() => {\n\t\t\tthis.#broadcasts.mutate((broadcasts) => {\n\t\t\t\tbroadcasts?.delete(path);\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Handles an announce interest message.\n\t * @param msg - The announce interest message\n\t * @param stream - The stream to write announcements to\n\t *\n\t * @internal\n\t */\n\tasync runAnnounce(msg: AnnounceInterest, stream: Stream) {\n\t\tconsole.debug(`announce: prefix=${msg.prefix}`);\n\n\t\t// Send initial announcements\n\t\tlet active = new Set<Path.Valid>();\n\n\t\tconst broadcasts = this.#broadcasts.peek();\n\t\tif (!broadcasts) return; // closed\n\n\t\tfor (const name of broadcasts.keys()) {\n\t\t\tconst suffix = Path.stripPrefix(msg.prefix, name);\n\t\t\tif (suffix === null) continue;\n\t\t\tconsole.debug(`announce: broadcast=${name} active=true`);\n\t\t\tactive.add(suffix);\n\t\t}\n\n\t\tswitch (this.version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02: {\n\t\t\t\tconst init = new AnnounceInit([...active]);\n\t\t\t\tawait init.encode(stream.writer, this.version);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\t// Draft03+: send individual Announce messages for initial state.\n\t\t\t\tfor (const suffix of active) {\n\t\t\t\t\tconst wire = new Announce({ suffix, active: true, hops: [this.origin] });\n\t\t\t\t\tawait wire.encode(stream.writer, this.version);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\n\t\t// Wait for updates to the broadcasts.\n\t\tfor (;;) {\n\t\t\t// TODO Make a better helper within Signals.\n\t\t\tlet dispose!: Dispose;\n\t\t\tconst changed = new Promise<Map<Path.Valid, Broadcast> | undefined>((resolve) => {\n\t\t\t\tdispose = this.#broadcasts.changed(resolve);\n\t\t\t});\n\n\t\t\t// Wait until the map of broadcasts changes.\n\t\t\tconst broadcasts = await Promise.race([changed, stream.reader.closed]);\n\t\t\tdispose();\n\t\t\tif (!broadcasts) break;\n\n\t\t\t// Create a new set of active broadcasts.\n\t\t\t// This is SLOW, but it's not worth optimizing because we often have just 1 broadcast anyway.\n\t\t\tconst newActive = new Set<Path.Valid>();\n\t\t\tfor (const name of broadcasts.keys()) {\n\t\t\t\tconst suffix = Path.stripPrefix(msg.prefix, name);\n\t\t\t\tif (suffix === null) continue; // Not our prefix.\n\t\t\t\tnewActive.add(suffix);\n\t\t\t}\n\n\t\t\t// Announce any new broadcasts.\n\t\t\tfor (const added of newActive.difference(active)) {\n\t\t\t\tconsole.debug(`announce: broadcast=${added} active=true`);\n\t\t\t\tconst wire = new Announce({ suffix: added, active: true, hops: [this.origin] });\n\t\t\t\tawait wire.encode(stream.writer, this.version);\n\t\t\t}\n\n\t\t\t// Announce any removed broadcasts.\n\t\t\t// Ended announces don't need hops — the peer matches on path only.\n\t\t\tfor (const removed of active.difference(newActive)) {\n\t\t\t\tconsole.debug(`announce: broadcast=${removed} active=false`);\n\t\t\t\tconst wire = new Announce({ suffix: removed, active: false });\n\t\t\t\tawait wire.encode(stream.writer, this.version);\n\t\t\t}\n\n\t\t\t// NOTE: This is kind of a hack that won't work with a rapid UNANNOUNCE/ANNOUNCE cycle.\n\t\t\t// However, our client doesn't do that anyway.\n\n\t\t\tactive = newActive;\n\t\t}\n\t}\n\n\t/**\n\t * Handles a subscribe message.\n\t * @param msg - The subscribe message\n\t * @param stream - The stream to write track data to\n\t *\n\t * @internal\n\t */\n\tasync runSubscribe(msg: Subscribe, stream: Stream) {\n\t\tconst broadcast = this.#broadcasts.peek()?.get(msg.broadcast);\n\t\tif (!broadcast) {\n\t\t\tconsole.debug(`publish unknown: broadcast=${msg.broadcast}`);\n\t\t\tstream.writer.reset(new Error(\"not found\"));\n\t\t\treturn;\n\t\t}\n\n\t\tconst track = broadcast.subscribe(msg.track, msg.priority);\n\n\t\ttry {\n\t\t\tconst info = new SubscribeOk({ priority: msg.priority });\n\t\t\tawait encodeSubscribeResponse(stream.writer, { ok: info }, this.version);\n\n\t\t\tconsole.debug(`publish ok: broadcast=${msg.broadcast} track=${track.name}`);\n\n\t\t\tconst serving = this.#runTrack(msg.id, msg.broadcast, track, stream.writer);\n\n\t\t\tfor (;;) {\n\t\t\t\tconst decode = SubscribeUpdate.decodeMaybe(stream.reader, this.version);\n\n\t\t\t\tconst result = await Promise.any([serving, decode]);\n\t\t\t\tif (!result) break;\n\n\t\t\t\tif (result instanceof SubscribeUpdate) {\n\t\t\t\t\t// TODO use the update\n\t\t\t\t\tconsole.warn(\"subscribe update not supported\", result);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconsole.debug(`publish done: broadcast=${msg.broadcast} track=${track.name}`);\n\t\t\tstream.close();\n\t\t\ttrack.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`publish error: broadcast=${msg.broadcast} track=${track.name} error=${e.message}`);\n\t\t\ttrack.close(e);\n\t\t\tstream.abort(e);\n\t\t}\n\t}\n\n\t/**\n\t * Runs a track and sends its data to the stream.\n\t * @param sub - The subscription ID\n\t * @param broadcast - The broadcast name\n\t * @param track - The track to run\n\t * @param stream - The stream to write to\n\t *\n\t * @internal\n\t */\n\tasync #runTrack(sub: bigint, broadcast: Path.Valid, track: Track, stream: Writer) {\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst next = track.recvGroup();\n\t\t\t\tconst group = await Promise.race([next, stream.closed]);\n\t\t\t\tif (!group) {\n\t\t\t\t\tnext.then((group) => group?.close()).catch(() => {});\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tvoid this.#runGroup(sub, group);\n\t\t\t}\n\n\t\t\tconsole.debug(`publish close: broadcast=${broadcast} track=${track.name}`);\n\t\t\ttrack.close();\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`publish error: broadcast=${broadcast} track=${track.name} error=${e.message}`);\n\t\t\ttrack.close(e);\n\t\t\tstream.reset(e);\n\t\t}\n\t}\n\n\t/**\n\t * Runs a group and sends its frames to the stream.\n\t * @param sub - The subscription ID\n\t * @param group - The group to run\n\t *\n\t * @internal\n\t */\n\tasync #runGroup(sub: bigint, group: Group) {\n\t\tconst msg = new GroupMessage(sub, group.sequence);\n\t\ttry {\n\t\t\tconst stream = await Writer.open(this.#quic);\n\t\t\tawait stream.u8(0); // stream type\n\t\t\tawait msg.encode(stream);\n\n\t\t\ttry {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst frame = await Promise.race([group.readFrame(), stream.closed]);\n\t\t\t\t\tif (!frame) break;\n\n\t\t\t\t\tawait stream.u53(frame.byteLength);\n\t\t\t\t\tawait stream.write(frame);\n\t\t\t\t}\n\n\t\t\t\tstream.close();\n\t\t\t\tgroup.close();\n\t\t\t} catch (err: unknown) {\n\t\t\t\tconst e = error(err);\n\t\t\t\tstream.reset(e);\n\t\t\t\tgroup.close(e);\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tgroup.close(e);\n\t\t}\n\t}\n\n\t/**\n\t * Handles a probe stream by periodically reporting estimated bitrate.\n\t * @param stream - The probe bidi stream\n\t *\n\t * @internal\n\t */\n\tasync runProbe(stream: Stream) {\n\t\t// getStats is not yet in the TypeScript WebTransport type definitions.\n\t\tconst quic = this.#quic as unknown as {\n\t\t\tgetStats?: () => Promise<{ estimatedSendRate: number | null }>;\n\t\t};\n\t\tif (!quic.getStats) {\n\t\t\t// Best-effort: we can't supply bandwidth estimates, so close the\n\t\t\t// whole bidi (FIN + STOP_SENDING) to let the peer release its end.\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\n\t\tlet lastSentBitrate: number | undefined;\n\t\tlet lastSentTime: number | undefined;\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst timeout = new Promise<\"timeout\">((resolve) =>\n\t\t\t\t\tsetTimeout(() => resolve(\"timeout\"), PROBE_INTERVAL),\n\t\t\t\t);\n\t\t\t\tconst result = await Promise.race([timeout, stream.reader.closed]);\n\t\t\t\tif (result !== \"timeout\") break;\n\n\t\t\t\tconst stats = await quic.getStats();\n\t\t\t\tconst bitrate = stats.estimatedSendRate;\n\t\t\t\tif (bitrate == null) continue;\n\n\t\t\t\tlet shouldSend: boolean;\n\t\t\t\tif (lastSentBitrate === undefined || lastSentTime === undefined) {\n\t\t\t\t\tshouldSend = true;\n\t\t\t\t} else if (lastSentBitrate === 0) {\n\t\t\t\t\tshouldSend = bitrate > 0;\n\t\t\t\t} else {\n\t\t\t\t\tconst elapsed = performance.now() - lastSentTime;\n\t\t\t\t\tconst t = Math.max(PROBE_INTERVAL, Math.min(PROBE_MAX_AGE, elapsed));\n\t\t\t\t\tconst range = PROBE_MAX_AGE - PROBE_INTERVAL;\n\t\t\t\t\tconst threshold = (PROBE_MAX_DELTA * (PROBE_MAX_AGE - t)) / range;\n\t\t\t\t\tconst change = Math.abs(bitrate - lastSentBitrate) / lastSentBitrate;\n\t\t\t\t\tshouldSend = change >= threshold;\n\t\t\t\t}\n\n\t\t\t\tif (shouldSend) {\n\t\t\t\t\tawait new Probe(bitrate).encode(stream.writer, this.version);\n\t\t\t\t\tlastSentBitrate = bitrate;\n\t\t\t\t\tlastSentTime = performance.now();\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconsole.warn(\"probe stream error\", err);\n\t\t\tstream.close();\n\t\t}\n\t}\n\n\tclose() {\n\t\tthis.#broadcasts.update((broadcasts) => {\n\t\t\tfor (const broadcast of broadcasts?.values() ?? []) {\n\t\t\t\tbroadcast.close();\n\t\t\t}\n\t\t\treturn undefined;\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Reader, Writer } from "../stream.ts";
|
|
2
|
+
import { Version } from "./version.ts";
|
|
3
|
+
export declare class Extensions {
|
|
4
|
+
entries: Map<bigint, Uint8Array>;
|
|
5
|
+
constructor();
|
|
6
|
+
set(id: bigint, value: Uint8Array): void;
|
|
7
|
+
get(id: bigint): Uint8Array | undefined;
|
|
8
|
+
remove(id: bigint): Uint8Array | undefined;
|
|
9
|
+
encode(w: Writer): Promise<void>;
|
|
10
|
+
static decode(r: Reader): Promise<Extensions>;
|
|
11
|
+
}
|
|
12
|
+
export declare class SessionClient {
|
|
13
|
+
#private;
|
|
14
|
+
versions: number[];
|
|
15
|
+
extensions: Extensions;
|
|
16
|
+
constructor(versions: number[], extensions?: Extensions);
|
|
17
|
+
encode(w: Writer): Promise<void>;
|
|
18
|
+
static decode(r: Reader): Promise<SessionClient>;
|
|
19
|
+
}
|
|
20
|
+
export declare class SessionServer {
|
|
21
|
+
#private;
|
|
22
|
+
version: number;
|
|
23
|
+
extensions: Extensions;
|
|
24
|
+
constructor(version: number, extensions?: Extensions);
|
|
25
|
+
encode(w: Writer): Promise<void>;
|
|
26
|
+
static decode(r: Reader): Promise<SessionServer>;
|
|
27
|
+
}
|
|
28
|
+
export declare class SessionInfo {
|
|
29
|
+
#private;
|
|
30
|
+
bitrate: number;
|
|
31
|
+
constructor(bitrate: number);
|
|
32
|
+
encode(w: Writer, version: Version): Promise<void>;
|
|
33
|
+
static decode(r: Reader, version: Version): Promise<SessionInfo>;
|
|
34
|
+
static decodeMaybe(r: Reader, version: Version): Promise<SessionInfo | undefined>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/lite/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA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AAO,GAAG,OAAO,CAAC,WAAW,CAAC;WAKzD,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;CAIvF"}
|
package/lite/session.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import * as Message from "./message.js";
|
|
2
|
+
import { Version } from "./version.js";
|
|
3
|
+
export class Extensions {
|
|
4
|
+
entries;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.entries = new Map();
|
|
7
|
+
}
|
|
8
|
+
set(id, value) {
|
|
9
|
+
this.entries.set(id, value);
|
|
10
|
+
}
|
|
11
|
+
get(id) {
|
|
12
|
+
return this.entries.get(id);
|
|
13
|
+
}
|
|
14
|
+
remove(id) {
|
|
15
|
+
const value = this.entries.get(id);
|
|
16
|
+
this.entries.delete(id);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
async encode(w) {
|
|
20
|
+
await w.u53(this.entries.size);
|
|
21
|
+
for (const [id, value] of this.entries) {
|
|
22
|
+
await w.u62(id);
|
|
23
|
+
await w.u53(value.length);
|
|
24
|
+
await w.write(value);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
static async decode(r) {
|
|
28
|
+
const count = await r.u53();
|
|
29
|
+
const params = new Extensions();
|
|
30
|
+
for (let i = 0; i < count; i++) {
|
|
31
|
+
const id = await r.u62();
|
|
32
|
+
const size = await r.u53();
|
|
33
|
+
const value = await r.read(size);
|
|
34
|
+
if (params.entries.has(id)) {
|
|
35
|
+
throw new Error(`duplicate parameter id: ${id.toString()}`);
|
|
36
|
+
}
|
|
37
|
+
params.entries.set(id, value);
|
|
38
|
+
}
|
|
39
|
+
return params;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class SessionClient {
|
|
43
|
+
versions;
|
|
44
|
+
extensions;
|
|
45
|
+
constructor(versions, extensions = new Extensions()) {
|
|
46
|
+
this.versions = versions;
|
|
47
|
+
this.extensions = extensions;
|
|
48
|
+
}
|
|
49
|
+
async #encode(w) {
|
|
50
|
+
await w.u53(this.versions.length);
|
|
51
|
+
for (const v of this.versions) {
|
|
52
|
+
await w.u53(v);
|
|
53
|
+
}
|
|
54
|
+
await this.extensions.encode(w);
|
|
55
|
+
}
|
|
56
|
+
static async #decode(r) {
|
|
57
|
+
const versions = [];
|
|
58
|
+
const count = await r.u53();
|
|
59
|
+
for (let i = 0; i < count; i++) {
|
|
60
|
+
versions.push(await r.u53());
|
|
61
|
+
}
|
|
62
|
+
const extensions = await Extensions.decode(r);
|
|
63
|
+
return new SessionClient(versions, extensions);
|
|
64
|
+
}
|
|
65
|
+
async encode(w) {
|
|
66
|
+
return Message.encode(w, this.#encode.bind(this));
|
|
67
|
+
}
|
|
68
|
+
static async decode(r) {
|
|
69
|
+
return Message.decode(r, SessionClient.#decode);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export class SessionServer {
|
|
73
|
+
version;
|
|
74
|
+
extensions;
|
|
75
|
+
constructor(version, extensions = new Extensions()) {
|
|
76
|
+
this.version = version;
|
|
77
|
+
this.extensions = extensions;
|
|
78
|
+
}
|
|
79
|
+
async #encode(w) {
|
|
80
|
+
await w.u53(this.version);
|
|
81
|
+
await this.extensions.encode(w);
|
|
82
|
+
}
|
|
83
|
+
static async #decode(r) {
|
|
84
|
+
const version = await r.u53();
|
|
85
|
+
const extensions = await Extensions.decode(r);
|
|
86
|
+
return new SessionServer(version, extensions);
|
|
87
|
+
}
|
|
88
|
+
async encode(w) {
|
|
89
|
+
return Message.encode(w, this.#encode.bind(this));
|
|
90
|
+
}
|
|
91
|
+
static async decode(r) {
|
|
92
|
+
return Message.decode(r, SessionServer.#decode);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export class SessionInfo {
|
|
96
|
+
bitrate;
|
|
97
|
+
constructor(bitrate) {
|
|
98
|
+
this.bitrate = bitrate;
|
|
99
|
+
}
|
|
100
|
+
static #guard(version) {
|
|
101
|
+
switch (version) {
|
|
102
|
+
case Version.DRAFT_01:
|
|
103
|
+
case Version.DRAFT_02:
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
throw new Error("session info not supported for this version");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async #encode(w) {
|
|
110
|
+
await w.u53(this.bitrate);
|
|
111
|
+
}
|
|
112
|
+
static async #decode(r) {
|
|
113
|
+
const bitrate = await r.u53();
|
|
114
|
+
return new SessionInfo(bitrate);
|
|
115
|
+
}
|
|
116
|
+
async encode(w, version) {
|
|
117
|
+
SessionInfo.#guard(version);
|
|
118
|
+
return Message.encode(w, this.#encode.bind(this));
|
|
119
|
+
}
|
|
120
|
+
static async decode(r, version) {
|
|
121
|
+
SessionInfo.#guard(version);
|
|
122
|
+
return Message.decode(r, SessionInfo.#decode);
|
|
123
|
+
}
|
|
124
|
+
static async decodeMaybe(r, version) {
|
|
125
|
+
SessionInfo.#guard(version);
|
|
126
|
+
return Message.decodeMaybe(r, SessionInfo.#decode);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/lite/session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,OAAO,UAAU;IACtB,OAAO,CAA0B;IAEjC;QACC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED,GAAG,CAAC,EAAU,EAAE,KAAiB;QAChC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,GAAG,CAAC,EAAU;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,M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,MAAM,CAAC,MAAM,CAAC,OAAgB;QAC7B,QAAQ,OAAO,EAAE,CAAC;YACjB,KAAK,OAAO,CAAC,QAAQ,CAAC;YACtB,KAAK,OAAO,CAAC,QAAQ;gBACpB,MAAM;YACP;gBACC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;IACF,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACtB,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAS;QAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;QAC9B,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC5B,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,MAAM,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAS,EAAE,OAAgB;QACnD,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;CACD","sourcesContent":["import type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { Version } from \"./version.ts\";\n\nexport class Extensions {\n\tentries: Map<bigint, Uint8Array>;\n\n\tconstructor() {\n\t\tthis.entries = new Map();\n\t}\n\n\tset(id: bigint, value: Uint8Array) {\n\t\tthis.entries.set(id, value);\n\t}\n\n\tget(id: bigint): Uint8Array | undefined {\n\t\treturn this.entries.get(id);\n\t}\n\n\tremove(id: bigint): Uint8Array | undefined {\n\t\tconst value = this.entries.get(id);\n\t\tthis.entries.delete(id);\n\t\treturn value;\n\t}\n\n\tasync encode(w: Writer) {\n\t\tawait w.u53(this.entries.size);\n\t\tfor (const [id, value] of this.entries) {\n\t\t\tawait w.u62(id);\n\t\t\tawait w.u53(value.length);\n\t\t\tawait w.write(value);\n\t\t}\n\t}\n\n\tstatic async decode(r: Reader): Promise<Extensions> {\n\t\tconst count = await r.u53();\n\t\tconst params = new Extensions();\n\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tconst id = await r.u62();\n\t\t\tconst size = await r.u53();\n\t\t\tconst value = await r.read(size);\n\n\t\t\tif (params.entries.has(id)) {\n\t\t\t\tthrow new Error(`duplicate parameter id: ${id.toString()}`);\n\t\t\t}\n\n\t\t\tparams.entries.set(id, value);\n\t\t}\n\n\t\treturn params;\n\t}\n}\n\nexport class SessionClient {\n\tversions: number[];\n\textensions: Extensions;\n\n\tconstructor(versions: number[], extensions = new Extensions()) {\n\t\tthis.versions = versions;\n\t\tthis.extensions = extensions;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u53(this.versions.length);\n\t\tfor (const v of this.versions) {\n\t\t\tawait w.u53(v);\n\t\t}\n\n\t\tawait this.extensions.encode(w);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<SessionClient> {\n\t\tconst versions: number[] = [];\n\t\tconst count = await r.u53();\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tversions.push(await r.u53());\n\t\t}\n\n\t\tconst extensions = await Extensions.decode(r);\n\t\treturn new SessionClient(versions, extensions);\n\t}\n\n\tasync encode(w: Writer): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader): Promise<SessionClient> {\n\t\treturn Message.decode(r, SessionClient.#decode);\n\t}\n}\n\nexport class SessionServer {\n\tversion: number;\n\textensions: Extensions;\n\n\tconstructor(version: number, extensions = new Extensions()) {\n\t\tthis.version = version;\n\t\tthis.extensions = extensions;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u53(this.version);\n\t\tawait this.extensions.encode(w);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<SessionServer> {\n\t\tconst version = await r.u53();\n\t\tconst extensions = await Extensions.decode(r);\n\t\treturn new SessionServer(version, extensions);\n\t}\n\n\tasync encode(w: Writer): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader): Promise<SessionServer> {\n\t\treturn Message.decode(r, SessionServer.#decode);\n\t}\n}\n\nexport class SessionInfo {\n\tbitrate: number;\n\n\tconstructor(bitrate: number) {\n\t\tthis.bitrate = bitrate;\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(\"session info not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u53(this.bitrate);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<SessionInfo> {\n\t\tconst bitrate = await r.u53();\n\t\treturn new SessionInfo(bitrate);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tSessionInfo.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<SessionInfo> {\n\t\tSessionInfo.#guard(version);\n\t\treturn Message.decode(r, SessionInfo.#decode);\n\t}\n\n\tstatic async decodeMaybe(r: Reader, version: Version): Promise<SessionInfo | undefined> {\n\t\tSessionInfo.#guard(version);\n\t\treturn Message.decodeMaybe(r, SessionInfo.#decode);\n\t}\n}\n"]}
|
package/lite/stream.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AnnounceInterest } from "./announce.ts";
|
|
2
|
+
import type { Goaway } from "./goaway.ts";
|
|
3
|
+
import type { Group } from "./group.ts";
|
|
4
|
+
import type { SessionClient } from "./session.ts";
|
|
5
|
+
import type { Subscribe } from "./subscribe.ts";
|
|
6
|
+
export type StreamBi = SessionClient | AnnounceInterest | Subscribe | Goaway;
|
|
7
|
+
export type StreamUni = Group;
|
|
8
|
+
export declare const StreamId: {
|
|
9
|
+
readonly Session: 0;
|
|
10
|
+
readonly Announce: 1;
|
|
11
|
+
readonly Subscribe: 2;
|
|
12
|
+
readonly Fetch: 3;
|
|
13
|
+
readonly Probe: 4;
|
|
14
|
+
readonly Goaway: 5;
|
|
15
|
+
readonly ClientCompat: 32;
|
|
16
|
+
readonly ServerCompat: 33;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/lite/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,MAAM,QAAQ,GAAG,aAAa,GAAG,gBAAgB,GAAG,SAAS,GAAG,MAAM,CAAC;AAC7E,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC;AAE9B,eAAO,MAAM,QAAQ;;;;;;;;;CASX,CAAC"}
|
package/lite/stream.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/lite/stream.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,SAAS,EAAE,CAAC;IACZ,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,IAAI;CACT,CAAC","sourcesContent":["import type { AnnounceInterest } from \"./announce.ts\";\nimport type { Goaway } from \"./goaway.ts\";\nimport type { Group } from \"./group.ts\";\nimport type { SessionClient } from \"./session.ts\";\nimport type { Subscribe } from \"./subscribe.ts\";\n\nexport type StreamBi = SessionClient | AnnounceInterest | Subscribe | Goaway;\nexport type StreamUni = Group;\n\nexport const StreamId = {\n\tSession: 0,\n\tAnnounce: 1,\n\tSubscribe: 2,\n\tFetch: 3,\n\tProbe: 4,\n\tGoaway: 5,\n\tClientCompat: 0x20,\n\tServerCompat: 0x21,\n} as const;\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 SubscribeUpdate {
|
|
5
|
+
#private;
|
|
6
|
+
priority: number;
|
|
7
|
+
ordered: boolean;
|
|
8
|
+
maxLatency: number;
|
|
9
|
+
startGroup?: number;
|
|
10
|
+
endGroup?: number;
|
|
11
|
+
constructor(props: {
|
|
12
|
+
priority: number;
|
|
13
|
+
ordered?: boolean;
|
|
14
|
+
maxLatency?: number;
|
|
15
|
+
startGroup?: number;
|
|
16
|
+
endGroup?: number;
|
|
17
|
+
});
|
|
18
|
+
encode(w: Writer, version: Version): Promise<void>;
|
|
19
|
+
static decode(r: Reader, version: Version): Promise<SubscribeUpdate>;
|
|
20
|
+
static decodeMaybe(r: Reader, version: Version): Promise<SubscribeUpdate | undefined>;
|
|
21
|
+
}
|
|
22
|
+
export declare class Subscribe {
|
|
23
|
+
#private;
|
|
24
|
+
id: bigint;
|
|
25
|
+
broadcast: Path.Valid;
|
|
26
|
+
track: string;
|
|
27
|
+
priority: number;
|
|
28
|
+
ordered: boolean;
|
|
29
|
+
maxLatency: number;
|
|
30
|
+
startGroup?: number;
|
|
31
|
+
endGroup?: number;
|
|
32
|
+
constructor(props: {
|
|
33
|
+
id: bigint;
|
|
34
|
+
broadcast: Path.Valid;
|
|
35
|
+
track: string;
|
|
36
|
+
priority: number;
|
|
37
|
+
ordered?: boolean;
|
|
38
|
+
maxLatency?: number;
|
|
39
|
+
startGroup?: number;
|
|
40
|
+
endGroup?: number;
|
|
41
|
+
});
|
|
42
|
+
encode(w: Writer, version: Version): Promise<void>;
|
|
43
|
+
static decode(r: Reader, version: Version): Promise<Subscribe>;
|
|
44
|
+
}
|
|
45
|
+
export declare class SubscribeOk {
|
|
46
|
+
#private;
|
|
47
|
+
priority: number;
|
|
48
|
+
ordered: boolean;
|
|
49
|
+
maxLatency: number;
|
|
50
|
+
startGroup?: number;
|
|
51
|
+
endGroup?: number;
|
|
52
|
+
constructor({ priority, ordered, maxLatency, startGroup, endGroup, }: {
|
|
53
|
+
priority?: number;
|
|
54
|
+
ordered?: boolean;
|
|
55
|
+
maxLatency?: number;
|
|
56
|
+
startGroup?: number;
|
|
57
|
+
endGroup?: number;
|
|
58
|
+
});
|
|
59
|
+
encode(w: Writer, version: Version): Promise<void>;
|
|
60
|
+
static decode(r: Reader, version: Version): Promise<SubscribeOk>;
|
|
61
|
+
}
|
|
62
|
+
export declare class SubscribeDrop {
|
|
63
|
+
#private;
|
|
64
|
+
start: number;
|
|
65
|
+
end: number;
|
|
66
|
+
error: number;
|
|
67
|
+
constructor(props: {
|
|
68
|
+
start: number;
|
|
69
|
+
end: number;
|
|
70
|
+
error: number;
|
|
71
|
+
});
|
|
72
|
+
encode(w: Writer): Promise<void>;
|
|
73
|
+
static decode(r: Reader): Promise<SubscribeDrop>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A response message on the subscribe stream.
|
|
77
|
+
*
|
|
78
|
+
* In Draft03+, each response is prefixed with a type discriminator:
|
|
79
|
+
* - 0x0 for SUBSCRIBE_OK
|
|
80
|
+
* - 0x1 for SUBSCRIBE_DROP
|
|
81
|
+
*
|
|
82
|
+
* SUBSCRIBE_OK must be the first message on the response stream.
|
|
83
|
+
*/
|
|
84
|
+
export type SubscribeResponse = {
|
|
85
|
+
ok: SubscribeOk;
|
|
86
|
+
} | {
|
|
87
|
+
drop: SubscribeDrop;
|
|
88
|
+
};
|
|
89
|
+
export declare function encodeSubscribeResponse(w: Writer, resp: SubscribeResponse, version: Version): Promise<void>;
|
|
90
|
+
export declare function decodeSubscribeResponse(r: Reader, version: Version): Promise<SubscribeResponse>;
|
|
91
|
+
//# sourceMappingURL=subscribe.d.ts.map
|