rwebtransport 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/crates/echo-server/src/bin/gen-test-cert.rs +82 -0
- package/crates/echo-server/src/main.rs +7 -7
- package/crates/native/src/config.rs +1 -1
- package/crates/native/src/driver.rs +91 -13
- package/crates/native/src/lib.rs +196 -4
- package/crates/native/src/server.rs +111 -10
- package/crates/native/src/session.rs +585 -56
- package/crates/native/src/tls.rs +68 -5
- package/crates/wtcore/src/h3.rs +303 -1
- package/crates/wtcore/src/lib.rs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +299 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +298 -11
- package/dist/index.mjs.map +1 -1
- package/dist/native.d.ts +63 -4
- package/dist/server.d.ts +6 -0
- package/dist/streams.d.ts +11 -2
- package/dist/types.d.ts +21 -1
- package/dist/webtransport.d.ts +12 -4
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-x64/rwebtransport.node +0 -0
- package/prebuilds/win32-x64/rwebtransport.node +0 -0
- package/vendor/quiche/src/lib.rs +11 -0
- package/vendor/quiche/src/tls/mod.rs +38 -0
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
WebTransportDatagramDuplexStream: () => WebTransportDatagramDuplexStream,
|
|
26
26
|
WebTransportError: () => WebTransportError,
|
|
27
27
|
WebTransportReceiveStream: () => WebTransportReceiveStream,
|
|
28
|
+
WebTransportSendGroup: () => WebTransportSendGroup,
|
|
28
29
|
WebTransportSendStream: () => WebTransportSendStream,
|
|
29
30
|
WebTransportServer: () => WebTransportServer,
|
|
30
31
|
WebTransportServerSession: () => WebTransportServerSession,
|
|
@@ -141,6 +142,10 @@ var SessionCore = class {
|
|
|
141
142
|
writes = /* @__PURE__ */ new Map();
|
|
142
143
|
/** Pending {@link SessionCore.sendDatagram} requests, keyed by request id. */
|
|
143
144
|
datagramAcks = /* @__PURE__ */ new Map();
|
|
145
|
+
/** Pending getStats() requests, keyed by request id. */
|
|
146
|
+
statsRequests = /* @__PURE__ */ new Map();
|
|
147
|
+
/** Pending exportKeyingMaterial() requests, keyed by request id. */
|
|
148
|
+
keyingMaterialRequests = /* @__PURE__ */ new Map();
|
|
144
149
|
/** Active receive sinks, keyed by stream id. */
|
|
145
150
|
receives = /* @__PURE__ */ new Map();
|
|
146
151
|
/** Active send sinks, keyed by stream id. */
|
|
@@ -149,10 +154,20 @@ var SessionCore = class {
|
|
|
149
154
|
incoming;
|
|
150
155
|
/** Sink for inbound datagrams, if one has been set. */
|
|
151
156
|
datagramSink;
|
|
157
|
+
/** Count of inbound datagrams dropped because the readable queue was full. */
|
|
158
|
+
droppedIncomingDatagrams = 0;
|
|
152
159
|
/** True once the session has reached its terminal (closed) state. */
|
|
153
160
|
closedState = false;
|
|
154
161
|
/** True once the session has been established (`ready`/`serverReady`). */
|
|
155
162
|
readyState = false;
|
|
163
|
+
/** True when the session reached its terminal state through an error. */
|
|
164
|
+
failedState = false;
|
|
165
|
+
/** The most recent stats reported by the native layer, cached for {@link SessionCore.getStats}. */
|
|
166
|
+
lastStats;
|
|
167
|
+
/** The negotiated subprotocol, cached from the ready event (`''` if none). */
|
|
168
|
+
cachedProtocol = "";
|
|
169
|
+
/** The CONNECT response headers, cached from the client ready event. */
|
|
170
|
+
cachedResponseHeaders = [];
|
|
156
171
|
/**
|
|
157
172
|
* Resolves when the session is established, rejects if it fails before then.
|
|
158
173
|
* Backs the public `WebTransport.ready` promise.
|
|
@@ -163,6 +178,12 @@ var SessionCore = class {
|
|
|
163
178
|
* close that happens before the session is ready. Backs `WebTransport.closed`.
|
|
164
179
|
*/
|
|
165
180
|
closed = deferred();
|
|
181
|
+
/**
|
|
182
|
+
* Resolves when the peer sends a DRAIN_WEBTRANSPORT_SESSION capsule (it
|
|
183
|
+
* intends to close soon but the session stays usable). Backs
|
|
184
|
+
* `WebTransport.draining`. Never rejects.
|
|
185
|
+
*/
|
|
186
|
+
draining = deferred();
|
|
166
187
|
/**
|
|
167
188
|
* Attach no-op catch handlers to {@link SessionCore.ready} and
|
|
168
189
|
* {@link SessionCore.closed} so that a session whose promises the user never
|
|
@@ -302,6 +323,42 @@ var SessionCore = class {
|
|
|
302
323
|
if (this.closedState || !this.transport) return;
|
|
303
324
|
this.transport.closeSession(code >>> 0, new TextEncoder().encode(reason));
|
|
304
325
|
}
|
|
326
|
+
/** Tell the peer this session is draining (send a DRAIN capsule). */
|
|
327
|
+
drain() {
|
|
328
|
+
this.transport?.drain();
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Snapshot the connection's stats. Resolves with a
|
|
332
|
+
* {@link WebTransportConnectionStats} once the driver reports back. After a
|
|
333
|
+
* clean close it resolves with the last stats seen while live; it rejects
|
|
334
|
+
* only when the session was never attached or terminated through an error.
|
|
335
|
+
*/
|
|
336
|
+
getStats() {
|
|
337
|
+
if (!this.usable()) {
|
|
338
|
+
if (!this.failedState && this.lastStats !== void 0) {
|
|
339
|
+
return Promise.resolve(this.lastStats);
|
|
340
|
+
}
|
|
341
|
+
return Promise.reject(this.deadError());
|
|
342
|
+
}
|
|
343
|
+
const requestId = this.nextId();
|
|
344
|
+
const d = deferred();
|
|
345
|
+
this.statsRequests.set(requestId, d);
|
|
346
|
+
this.transport.getStats(requestId);
|
|
347
|
+
return d.promise;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Export TLS keying material (RFC 5705). Resolves with `length` bytes derived
|
|
351
|
+
* from `label` and `context` once the driver reports back; rejects if the
|
|
352
|
+
* session is not usable or the TLS export fails.
|
|
353
|
+
*/
|
|
354
|
+
exportKeyingMaterial(label, context, length) {
|
|
355
|
+
if (!this.usable()) return Promise.reject(this.deadError());
|
|
356
|
+
const requestId = this.nextId();
|
|
357
|
+
const d = deferred();
|
|
358
|
+
this.keyingMaterialRequests.set(requestId, d);
|
|
359
|
+
this.transport.exportKeyingMaterial(requestId, label, context, length);
|
|
360
|
+
return d.promise;
|
|
361
|
+
}
|
|
305
362
|
/** Tear down the native resources for this session. No-op if not attached. */
|
|
306
363
|
shutdown() {
|
|
307
364
|
this.transport?.shutdown();
|
|
@@ -370,6 +427,13 @@ var SessionCore = class {
|
|
|
370
427
|
setDatagramSink(sink) {
|
|
371
428
|
this.datagramSink = sink;
|
|
372
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* Record that one inbound datagram was dropped because the readable queue
|
|
432
|
+
* was full. Surfaced through getStats() as `datagrams.droppedIncoming`.
|
|
433
|
+
*/
|
|
434
|
+
recordDroppedIncomingDatagram() {
|
|
435
|
+
this.droppedIncomingDatagrams++;
|
|
436
|
+
}
|
|
373
437
|
/**
|
|
374
438
|
* Route one native event to the appropriate promise, sink, or handler.
|
|
375
439
|
*
|
|
@@ -384,12 +448,23 @@ var SessionCore = class {
|
|
|
384
448
|
*/
|
|
385
449
|
dispatch(ev) {
|
|
386
450
|
switch (ev.type) {
|
|
387
|
-
case "ready" /* Ready */:
|
|
451
|
+
case "ready" /* Ready */: {
|
|
452
|
+
this.readyState = true;
|
|
453
|
+
this.cachedProtocol = ev.protocol ?? "";
|
|
454
|
+
this.cachedResponseHeaders = ev.responseHeaders;
|
|
455
|
+
this.ready.resolve();
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
388
458
|
case "serverReady" /* ServerReady */: {
|
|
389
459
|
this.readyState = true;
|
|
460
|
+
this.cachedProtocol = ev.protocol ?? "";
|
|
390
461
|
this.ready.resolve();
|
|
391
462
|
break;
|
|
392
463
|
}
|
|
464
|
+
case "draining" /* Draining */: {
|
|
465
|
+
this.draining.resolve();
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
393
468
|
case "closed" /* Closed */: {
|
|
394
469
|
const reason = new TextDecoder().decode(ev.reason);
|
|
395
470
|
this.finish({ closeCode: ev.code, reason }, void 0);
|
|
@@ -440,6 +515,44 @@ var SessionCore = class {
|
|
|
440
515
|
this.datagramAcks.delete(ev.requestId);
|
|
441
516
|
break;
|
|
442
517
|
}
|
|
518
|
+
case "stats" /* Stats */: {
|
|
519
|
+
const stats = {
|
|
520
|
+
bytesSent: ev.bytesSent,
|
|
521
|
+
bytesReceived: ev.bytesReceived,
|
|
522
|
+
packetsSent: ev.packetsSent,
|
|
523
|
+
packetsReceived: ev.packetsReceived,
|
|
524
|
+
packetsLost: ev.packetsLost,
|
|
525
|
+
smoothedRtt: ev.smoothedRtt,
|
|
526
|
+
rttVariation: ev.rttVariation,
|
|
527
|
+
minRtt: ev.minRtt,
|
|
528
|
+
datagrams: {
|
|
529
|
+
expiredOutgoing: 0,
|
|
530
|
+
droppedIncoming: this.droppedIncomingDatagrams,
|
|
531
|
+
lostOutgoing: 0,
|
|
532
|
+
expiredIncoming: 0
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
this.lastStats = stats;
|
|
536
|
+
this.statsRequests.get(ev.requestId)?.resolve(stats);
|
|
537
|
+
this.statsRequests.delete(ev.requestId);
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
540
|
+
case "keyingMaterial" /* KeyingMaterial */: {
|
|
541
|
+
const d = this.keyingMaterialRequests.get(ev.requestId);
|
|
542
|
+
if (d) {
|
|
543
|
+
if (ev.ok && ev.data) {
|
|
544
|
+
d.resolve(ev.data);
|
|
545
|
+
} else {
|
|
546
|
+
d.reject(
|
|
547
|
+
new WebTransportError("keying material export failed", {
|
|
548
|
+
source: "session"
|
|
549
|
+
})
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
this.keyingMaterialRequests.delete(ev.requestId);
|
|
553
|
+
}
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
443
556
|
}
|
|
444
557
|
}
|
|
445
558
|
/**
|
|
@@ -461,6 +574,8 @@ var SessionCore = class {
|
|
|
461
574
|
finish(info, error) {
|
|
462
575
|
if (this.closedState) return;
|
|
463
576
|
this.closedState = true;
|
|
577
|
+
if (error) this.failedState = true;
|
|
578
|
+
this.draining.resolve();
|
|
464
579
|
if (!this.readyState) {
|
|
465
580
|
const err2 = error ?? new WebTransportError("session closed before it was established", {
|
|
466
581
|
source: "session"
|
|
@@ -476,11 +591,15 @@ var SessionCore = class {
|
|
|
476
591
|
for (const d of this.opens.values()) d.reject(err);
|
|
477
592
|
for (const d of this.writes.values()) d.reject(err);
|
|
478
593
|
for (const d of this.datagramAcks.values()) d.resolve(false);
|
|
479
|
-
for (const
|
|
480
|
-
for (const
|
|
594
|
+
for (const d of this.statsRequests.values()) d.reject(err);
|
|
595
|
+
for (const d of this.keyingMaterialRequests.values()) d.reject(err);
|
|
596
|
+
for (const sink of this.receives.values()) sink.onSessionClose(err);
|
|
597
|
+
for (const sink of this.sends.values()) sink.onSessionClose(err);
|
|
481
598
|
this.opens.clear();
|
|
482
599
|
this.writes.clear();
|
|
483
600
|
this.datagramAcks.clear();
|
|
601
|
+
this.statsRequests.clear();
|
|
602
|
+
this.keyingMaterialRequests.clear();
|
|
484
603
|
this.receives.clear();
|
|
485
604
|
this.sends.clear();
|
|
486
605
|
this.transport?.shutdown();
|
|
@@ -489,6 +608,18 @@ var SessionCore = class {
|
|
|
489
608
|
get isClosed() {
|
|
490
609
|
return this.closedState;
|
|
491
610
|
}
|
|
611
|
+
/** @returns Whether the session has been established (ready). */
|
|
612
|
+
get isReady() {
|
|
613
|
+
return this.readyState;
|
|
614
|
+
}
|
|
615
|
+
/** @returns The negotiated subprotocol, or `''` if none was negotiated. */
|
|
616
|
+
get protocol() {
|
|
617
|
+
return this.cachedProtocol;
|
|
618
|
+
}
|
|
619
|
+
/** @returns The CONNECT response headers as ordered `[name, value]` pairs. */
|
|
620
|
+
get responseHeaders() {
|
|
621
|
+
return this.cachedResponseHeaders;
|
|
622
|
+
}
|
|
492
623
|
};
|
|
493
624
|
var ClientTransport = class {
|
|
494
625
|
/**
|
|
@@ -559,6 +690,18 @@ var ClientTransport = class {
|
|
|
559
690
|
closeSession(code, reason) {
|
|
560
691
|
this.native.closeSession(this.handle, code, reason);
|
|
561
692
|
}
|
|
693
|
+
/** Send a DRAIN_WEBTRANSPORT_SESSION capsule to the peer. */
|
|
694
|
+
drain() {
|
|
695
|
+
this.native.drain(this.handle);
|
|
696
|
+
}
|
|
697
|
+
/** Request connection stats; the result arrives as a `stats` event. */
|
|
698
|
+
getStats(requestId) {
|
|
699
|
+
this.native.getStats(this.handle, requestId);
|
|
700
|
+
}
|
|
701
|
+
/** Export TLS keying material; the result arrives as a `keyingMaterial` event. */
|
|
702
|
+
exportKeyingMaterial(requestId, label, context, length) {
|
|
703
|
+
this.native.exportKeyingMaterial(this.handle, requestId, label, context, length);
|
|
704
|
+
}
|
|
562
705
|
/** Tear down the session's native driver thread. */
|
|
563
706
|
shutdown() {
|
|
564
707
|
this.native.shutdown(this.handle);
|
|
@@ -575,6 +718,7 @@ function createClientSession(config) {
|
|
|
575
718
|
config.origin,
|
|
576
719
|
config.headerNames,
|
|
577
720
|
config.headerValues,
|
|
721
|
+
config.protocols,
|
|
578
722
|
(ev) => core.dispatch(ev)
|
|
579
723
|
);
|
|
580
724
|
core.attach(new ClientTransport(native, handle));
|
|
@@ -655,6 +799,25 @@ var ServerTransport = class {
|
|
|
655
799
|
closeSession(code, reason) {
|
|
656
800
|
this.native.serverCloseSession(this.handle, this.session, code, reason);
|
|
657
801
|
}
|
|
802
|
+
/** Send a DRAIN_WEBTRANSPORT_SESSION capsule to this session's peer. */
|
|
803
|
+
drain() {
|
|
804
|
+
this.native.serverDrain(this.handle, this.session);
|
|
805
|
+
}
|
|
806
|
+
/** Request this session's connection stats; the result arrives as a `stats` event. */
|
|
807
|
+
getStats(requestId) {
|
|
808
|
+
this.native.serverGetStats(this.handle, this.session, requestId);
|
|
809
|
+
}
|
|
810
|
+
/** Export TLS keying material; the result arrives as a `keyingMaterial` event. */
|
|
811
|
+
exportKeyingMaterial(requestId, label, context, length) {
|
|
812
|
+
this.native.serverExportKeyingMaterial(
|
|
813
|
+
this.handle,
|
|
814
|
+
this.session,
|
|
815
|
+
requestId,
|
|
816
|
+
label,
|
|
817
|
+
context,
|
|
818
|
+
length
|
|
819
|
+
);
|
|
820
|
+
}
|
|
658
821
|
/**
|
|
659
822
|
* No-op: the server driver owns the session lifecycle, so there is nothing to
|
|
660
823
|
* tear down per session on the JS side.
|
|
@@ -772,6 +935,8 @@ var WebTransportDatagramDuplexStream = class {
|
|
|
772
935
|
session.setDatagramSink((data) => {
|
|
773
936
|
if ((rController.desiredSize ?? 1) > 0) {
|
|
774
937
|
rController.enqueue(data);
|
|
938
|
+
} else {
|
|
939
|
+
session.recordDroppedIncomingDatagram();
|
|
775
940
|
}
|
|
776
941
|
});
|
|
777
942
|
void session.closed.promise.then(
|
|
@@ -933,11 +1098,20 @@ var WebTransportReceiveStream = class extends ReadableStream {
|
|
|
933
1098
|
})
|
|
934
1099
|
);
|
|
935
1100
|
session.unregisterReceive(streamId);
|
|
1101
|
+
},
|
|
1102
|
+
onSessionClose(error) {
|
|
1103
|
+
try {
|
|
1104
|
+
controller.error(error);
|
|
1105
|
+
} catch {
|
|
1106
|
+
}
|
|
1107
|
+
session.unregisterReceive(streamId);
|
|
936
1108
|
}
|
|
937
1109
|
});
|
|
938
1110
|
this.streamId = streamId;
|
|
939
1111
|
}
|
|
940
1112
|
};
|
|
1113
|
+
var WebTransportSendGroup = class {
|
|
1114
|
+
};
|
|
941
1115
|
var WebTransportSendStream = class extends WritableStream {
|
|
942
1116
|
/**
|
|
943
1117
|
* The QUIC stream id of the underlying stream. Stable for the lifetime of the
|
|
@@ -945,6 +1119,16 @@ var WebTransportSendStream = class extends WritableStream {
|
|
|
945
1119
|
* one half of a {@link WebTransportBidirectionalStream}.
|
|
946
1120
|
*/
|
|
947
1121
|
streamId;
|
|
1122
|
+
/**
|
|
1123
|
+
* The {@link WebTransportSendGroup} this stream belongs to, or `null`.
|
|
1124
|
+
* Mutable per the W3C API; grouping is a best-effort scheduling hint.
|
|
1125
|
+
*/
|
|
1126
|
+
sendGroup;
|
|
1127
|
+
/**
|
|
1128
|
+
* Relative send priority within the send group. Higher values are nominally
|
|
1129
|
+
* sent first. Mutable per the W3C API; the effect on the wire is best-effort.
|
|
1130
|
+
*/
|
|
1131
|
+
sendOrder;
|
|
948
1132
|
/**
|
|
949
1133
|
* Wire a `WritableStream` up to a native send stream.
|
|
950
1134
|
*
|
|
@@ -968,7 +1152,7 @@ var WebTransportSendStream = class extends WritableStream {
|
|
|
968
1152
|
* A {@link ByteLengthQueuingStrategy} with a high-water mark of 1 MiB
|
|
969
1153
|
* (`1024 * 1024` bytes) bounds the JS-side write queue.
|
|
970
1154
|
*/
|
|
971
|
-
constructor(session, streamId) {
|
|
1155
|
+
constructor(session, streamId, options = {}) {
|
|
972
1156
|
let controller;
|
|
973
1157
|
super(
|
|
974
1158
|
{
|
|
@@ -1001,9 +1185,18 @@ var WebTransportSendStream = class extends WritableStream {
|
|
|
1001
1185
|
} catch {
|
|
1002
1186
|
}
|
|
1003
1187
|
session.unregisterSend(streamId);
|
|
1188
|
+
},
|
|
1189
|
+
onSessionClose(error) {
|
|
1190
|
+
try {
|
|
1191
|
+
controller.error(error);
|
|
1192
|
+
} catch {
|
|
1193
|
+
}
|
|
1194
|
+
session.unregisterSend(streamId);
|
|
1004
1195
|
}
|
|
1005
1196
|
});
|
|
1006
1197
|
this.streamId = streamId;
|
|
1198
|
+
this.sendGroup = options.sendGroup ?? null;
|
|
1199
|
+
this.sendOrder = options.sendOrder ?? 0;
|
|
1007
1200
|
}
|
|
1008
1201
|
};
|
|
1009
1202
|
var WebTransportBidirectionalStream = class {
|
|
@@ -1017,9 +1210,9 @@ var WebTransportBidirectionalStream = class {
|
|
|
1017
1210
|
* @param session - The session core backing both halves.
|
|
1018
1211
|
* @param streamId - The QUIC stream id shared by the readable and writable halves.
|
|
1019
1212
|
*/
|
|
1020
|
-
constructor(session, streamId) {
|
|
1213
|
+
constructor(session, streamId, options = {}) {
|
|
1021
1214
|
this.readable = new WebTransportReceiveStream(session, streamId);
|
|
1022
|
-
this.writable = new WebTransportSendStream(session, streamId);
|
|
1215
|
+
this.writable = new WebTransportSendStream(session, streamId, options);
|
|
1023
1216
|
}
|
|
1024
1217
|
};
|
|
1025
1218
|
|
|
@@ -1061,7 +1254,8 @@ function buildConfig(url, options) {
|
|
|
1061
1254
|
insecure: options.insecure ?? false,
|
|
1062
1255
|
origin: options.origin ?? null,
|
|
1063
1256
|
headerNames,
|
|
1064
|
-
headerValues
|
|
1257
|
+
headerValues,
|
|
1258
|
+
protocols: options.protocols ?? []
|
|
1065
1259
|
};
|
|
1066
1260
|
}
|
|
1067
1261
|
var WebTransportSession = class {
|
|
@@ -1175,6 +1369,32 @@ var WebTransportSession = class {
|
|
|
1175
1369
|
get closed() {
|
|
1176
1370
|
return this.core.closed.promise;
|
|
1177
1371
|
}
|
|
1372
|
+
/**
|
|
1373
|
+
* A promise that resolves when the peer signals it is draining the session
|
|
1374
|
+
* (a `DRAIN_WEBTRANSPORT_SESSION` capsule): it intends to close soon, so you
|
|
1375
|
+
* should stop opening new streams, but the session and its existing streams
|
|
1376
|
+
* stay usable until {@link closed}. Never rejects.
|
|
1377
|
+
* @returns The core's `draining` promise.
|
|
1378
|
+
*/
|
|
1379
|
+
get draining() {
|
|
1380
|
+
return this.core.draining.promise;
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* The reliability modes this session supports. `'pending'` until the session
|
|
1384
|
+
* is established, then `'supports-unreliable'` because this transport always
|
|
1385
|
+
* offers both reliable streams and unreliable datagrams.
|
|
1386
|
+
*/
|
|
1387
|
+
get reliability() {
|
|
1388
|
+
return this.core.isReady ? "supports-unreliable" : "pending";
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* The negotiated WebTransport subprotocol, or the empty string when none was
|
|
1392
|
+
* negotiated (or before the session is established). Matches the W3C
|
|
1393
|
+
* `WebTransport.protocol` attribute.
|
|
1394
|
+
*/
|
|
1395
|
+
get protocol() {
|
|
1396
|
+
return this.core.protocol;
|
|
1397
|
+
}
|
|
1178
1398
|
/**
|
|
1179
1399
|
* Open a new outbound bidirectional stream.
|
|
1180
1400
|
*
|
|
@@ -1184,9 +1404,9 @@ var WebTransportSession = class {
|
|
|
1184
1404
|
* @throws WebTransportError (the returned promise rejects) if the session is
|
|
1185
1405
|
* already closed or was never attached.
|
|
1186
1406
|
*/
|
|
1187
|
-
async createBidirectionalStream() {
|
|
1407
|
+
async createBidirectionalStream(options = {}) {
|
|
1188
1408
|
const id = await this.core.openStream(true);
|
|
1189
|
-
return new WebTransportBidirectionalStream(this.core, id);
|
|
1409
|
+
return new WebTransportBidirectionalStream(this.core, id, options);
|
|
1190
1410
|
}
|
|
1191
1411
|
/**
|
|
1192
1412
|
* Open a new outbound unidirectional (send-only) stream.
|
|
@@ -1196,9 +1416,16 @@ var WebTransportSession = class {
|
|
|
1196
1416
|
* @throws WebTransportError (the returned promise rejects) if the session is
|
|
1197
1417
|
* already closed or was never attached.
|
|
1198
1418
|
*/
|
|
1199
|
-
async createUnidirectionalStream() {
|
|
1419
|
+
async createUnidirectionalStream(options = {}) {
|
|
1200
1420
|
const id = await this.core.openStream(false);
|
|
1201
|
-
return new WebTransportSendStream(this.core, id);
|
|
1421
|
+
return new WebTransportSendStream(this.core, id, options);
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Create a {@link WebTransportSendGroup} for scheduling several streams'
|
|
1425
|
+
* sends relative to one another via each stream's `sendOrder`.
|
|
1426
|
+
*/
|
|
1427
|
+
createSendGroup() {
|
|
1428
|
+
return new WebTransportSendGroup();
|
|
1202
1429
|
}
|
|
1203
1430
|
/**
|
|
1204
1431
|
* Close the session gracefully, notifying the peer with an application code
|
|
@@ -1219,6 +1446,43 @@ var WebTransportSession = class {
|
|
|
1219
1446
|
this.closeCalled = true;
|
|
1220
1447
|
this.core.close(closeInfo.closeCode ?? 0, closeInfo.reason ?? "");
|
|
1221
1448
|
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Tell the peer this session is draining by sending a
|
|
1451
|
+
* `DRAIN_WEBTRANSPORT_SESSION` capsule: a graceful signal that you intend to
|
|
1452
|
+
* stop using it soon, while the session and its streams stay open until
|
|
1453
|
+
* {@link close}. The peer observes this through its {@link draining} promise.
|
|
1454
|
+
* A Node extension beyond the W3C API, useful for a server shedding load.
|
|
1455
|
+
*/
|
|
1456
|
+
drain() {
|
|
1457
|
+
this.core.drain();
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Snapshot connection statistics (bytes and packets transferred, RTT, and
|
|
1461
|
+
* datagram counters).
|
|
1462
|
+
* @returns A promise resolving to {@link WebTransportConnectionStats}.
|
|
1463
|
+
* @throws WebTransportError (the promise rejects) if the session is closed.
|
|
1464
|
+
*/
|
|
1465
|
+
getStats() {
|
|
1466
|
+
return this.core.getStats();
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* Export keying material from the session's TLS connection (RFC 5705),
|
|
1470
|
+
* matching the W3C `exportKeyingMaterial`. Both endpoints derive identical
|
|
1471
|
+
* bytes for the same `label`, `context`, and `outputLength`, and nothing
|
|
1472
|
+
* outside the TLS session can reproduce them, which makes the result
|
|
1473
|
+
* suitable for channel binding.
|
|
1474
|
+
*
|
|
1475
|
+
* @param label - The exporter label, a {@link BinarySource}.
|
|
1476
|
+
* @param context - The exporter context, a {@link BinarySource}; pass an
|
|
1477
|
+
* empty buffer for no application context.
|
|
1478
|
+
* @param outputLength - Number of bytes of keying material to produce.
|
|
1479
|
+
* @returns A promise resolving to a `Uint8Array` of `outputLength` bytes.
|
|
1480
|
+
* @throws WebTransportError (the promise rejects) if the session is closed or
|
|
1481
|
+
* the TLS export fails (for example, before the handshake completes).
|
|
1482
|
+
*/
|
|
1483
|
+
exportKeyingMaterial(label, context, outputLength) {
|
|
1484
|
+
return this.core.exportKeyingMaterial(toBytes(label), toBytes(context), outputLength);
|
|
1485
|
+
}
|
|
1222
1486
|
};
|
|
1223
1487
|
var WebTransport = class extends WebTransportSession {
|
|
1224
1488
|
/**
|
|
@@ -1239,6 +1503,14 @@ var WebTransport = class extends WebTransportSession {
|
|
|
1239
1503
|
constructor(url, options = {}) {
|
|
1240
1504
|
super(createClientSession(buildConfig(url, options)));
|
|
1241
1505
|
}
|
|
1506
|
+
/**
|
|
1507
|
+
* The headers from the server's Extended CONNECT `2xx` response, as a
|
|
1508
|
+
* `Headers` object (empty until the session is established). Matches the W3C
|
|
1509
|
+
* `WebTransport.responseHeaders` attribute.
|
|
1510
|
+
*/
|
|
1511
|
+
get responseHeaders() {
|
|
1512
|
+
return new Headers(this.core.responseHeaders);
|
|
1513
|
+
}
|
|
1242
1514
|
};
|
|
1243
1515
|
function safeClose(controller) {
|
|
1244
1516
|
try {
|
|
@@ -1272,6 +1544,8 @@ var WebTransportServerSession = class extends WebTransportSession {
|
|
|
1272
1544
|
origin;
|
|
1273
1545
|
/** Any additional (non-pseudo) request headers, keyed by header name. */
|
|
1274
1546
|
headers;
|
|
1547
|
+
/** The subprotocols the client offered in `wt-available-protocols`. */
|
|
1548
|
+
requestedProtocols;
|
|
1275
1549
|
/**
|
|
1276
1550
|
* The client's remote IP address, as reported by the transport when the
|
|
1277
1551
|
* session was established. The same for every stream and datagram on this
|
|
@@ -1296,6 +1570,7 @@ var WebTransportServerSession = class extends WebTransportSession {
|
|
|
1296
1570
|
this.path = request.path;
|
|
1297
1571
|
this.origin = request.origin;
|
|
1298
1572
|
this.headers = request.headers;
|
|
1573
|
+
this.requestedProtocols = request.requestedProtocols;
|
|
1299
1574
|
this.remoteAddress = request.remoteAddress;
|
|
1300
1575
|
this.remotePort = request.remotePort;
|
|
1301
1576
|
}
|
|
@@ -1350,12 +1625,22 @@ var WebTransportServer = class {
|
|
|
1350
1625
|
this.incomingController = c;
|
|
1351
1626
|
}
|
|
1352
1627
|
});
|
|
1628
|
+
const responseHeaderNames = [];
|
|
1629
|
+
const responseHeaderValues = [];
|
|
1630
|
+
for (const [name, value] of Object.entries(options.responseHeaders ?? {})) {
|
|
1631
|
+
responseHeaderNames.push(name);
|
|
1632
|
+
responseHeaderValues.push(value);
|
|
1633
|
+
}
|
|
1353
1634
|
this.handle = this.native.serverListen(
|
|
1354
1635
|
options.cert,
|
|
1355
1636
|
options.key,
|
|
1356
1637
|
options.host ?? "0.0.0.0",
|
|
1357
1638
|
options.port,
|
|
1358
1639
|
options.reusePort ?? false,
|
|
1640
|
+
options.supportedProtocols ?? [],
|
|
1641
|
+
options.allowedOrigins ?? null,
|
|
1642
|
+
responseHeaderNames,
|
|
1643
|
+
responseHeaderValues,
|
|
1359
1644
|
(ev) => this.onEvent(ev)
|
|
1360
1645
|
);
|
|
1361
1646
|
}
|
|
@@ -1437,6 +1722,8 @@ var WebTransportServer = class {
|
|
|
1437
1722
|
path: ev.path,
|
|
1438
1723
|
origin: ev.origin,
|
|
1439
1724
|
headers: ev.headers,
|
|
1725
|
+
requestedProtocols: ev.requestedProtocols,
|
|
1726
|
+
protocol: ev.protocol,
|
|
1440
1727
|
remoteAddress: ev.remoteAddress,
|
|
1441
1728
|
remotePort: ev.remotePort
|
|
1442
1729
|
});
|
|
@@ -1481,6 +1768,7 @@ function safeCloseController(controller) {
|
|
|
1481
1768
|
WebTransportDatagramDuplexStream,
|
|
1482
1769
|
WebTransportError,
|
|
1483
1770
|
WebTransportReceiveStream,
|
|
1771
|
+
WebTransportSendGroup,
|
|
1484
1772
|
WebTransportSendStream,
|
|
1485
1773
|
WebTransportServer,
|
|
1486
1774
|
WebTransportServerSession,
|