@avatarsd-llc/libtracer-webtransport 0.3.0 → 0.5.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/dist/framing.d.ts +25 -13
- package/dist/framing.js +24 -17
- package/dist/index.d.ts +18 -0
- package/dist/index.js +18 -15
- package/dist/transport.d.ts +45 -35
- package/dist/transport.js +41 -32
- package/package.json +2 -2
package/dist/framing.d.ts
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* @brief The stream framing shared by every libtracer byte-stream transport
|
|
3
|
+
* (M6): each libtracer TLV frame travels as `u32-LE length ++ frame bytes`.
|
|
4
|
+
*
|
|
5
|
+
* This module is the pure, socket-free codec — byte-identical to the C++
|
|
6
|
+
* `tcp_transport_t` / `quic_transport_t` / `webtransport_transport_t` framing
|
|
7
|
+
* (the prefix is TRANSPORT framing, not part of the TLV).
|
|
8
|
+
*/
|
|
9
|
+
/** @brief The length prefix: 4 bytes, u32 little-endian. */
|
|
2
10
|
export declare const PREFIX_BYTES = 4;
|
|
3
11
|
/**
|
|
4
|
-
* The largest frame the prefix may announce (16 MiB — the C++
|
|
5
|
-
* cap).
|
|
6
|
-
*
|
|
12
|
+
* @brief The largest frame the prefix may announce (16 MiB — the C++
|
|
13
|
+
* `kMaxFrame` cap).
|
|
14
|
+
*
|
|
15
|
+
* A larger prefix is malformed: the stream has lost framing sync and cannot be
|
|
16
|
+
* trusted again.
|
|
7
17
|
*/
|
|
8
18
|
export declare const MAX_FRAME: number;
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
19
|
+
/**
|
|
20
|
+
* @brief Thrown by {@link FrameReassembler.push} on a prefix announcing more
|
|
21
|
+
* than {@link MAX_FRAME} bytes — the stream is desynced and must be torn down.
|
|
22
|
+
*/
|
|
11
23
|
export declare class MalformedPrefixError extends Error {
|
|
12
|
-
/** The length the malformed prefix announced. */
|
|
24
|
+
/** @brief The length the malformed prefix announced. */
|
|
13
25
|
readonly announced: number;
|
|
14
26
|
constructor(announced: number);
|
|
15
27
|
}
|
|
16
|
-
/** Encode one frame as a length-prefixed record: `u32-LE length ++ frame`. */
|
|
28
|
+
/** @brief Encode one frame as a length-prefixed record: `u32-LE length ++ frame`. */
|
|
17
29
|
export declare function encodeRecord(frame: Uint8Array): Uint8Array;
|
|
18
30
|
/**
|
|
19
|
-
* Reassemble length-prefixed records from arbitrary stream chunks (a
|
|
20
|
-
* stream delivers reads at transport-chosen boundaries: prefixes split
|
|
21
|
-
* chunks, records coalesced into one chunk — both are normal).
|
|
31
|
+
* @brief Reassemble length-prefixed records from arbitrary stream chunks (a
|
|
32
|
+
* QUIC stream delivers reads at transport-chosen boundaries: prefixes split
|
|
33
|
+
* across chunks, records coalesced into one chunk — both are normal).
|
|
22
34
|
*
|
|
23
35
|
* `push(chunk)` returns every COMPLETE frame the chunk finished; partial bytes
|
|
24
36
|
* are buffered for the next push. A zero-length record is a no-op (skipped,
|
|
@@ -28,8 +40,8 @@ export declare function encodeRecord(frame: Uint8Array): Uint8Array;
|
|
|
28
40
|
*/
|
|
29
41
|
export declare class FrameReassembler {
|
|
30
42
|
private pending;
|
|
31
|
-
/** Feed one stream chunk; returns the frames it completed (possibly none). */
|
|
43
|
+
/** @brief Feed one stream chunk; returns the frames it completed (possibly none). */
|
|
32
44
|
push(chunk: Uint8Array): Uint8Array[];
|
|
33
|
-
/** Bytes buffered awaiting the rest of a prefix/body (diagnostics). */
|
|
45
|
+
/** @brief Bytes buffered awaiting the rest of a prefix/body (diagnostics). */
|
|
34
46
|
get buffered(): number;
|
|
35
47
|
}
|
package/dist/framing.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @brief The stream framing shared by every libtracer byte-stream transport
|
|
5
|
+
* (M6): each libtracer TLV frame travels as `u32-LE length ++ frame bytes`.
|
|
6
|
+
*
|
|
7
|
+
* This module is the pure, socket-free codec — byte-identical to the C++
|
|
8
|
+
* `tcp_transport_t` / `quic_transport_t` / `webtransport_transport_t` framing
|
|
9
|
+
* (the prefix is TRANSPORT framing, not part of the TLV).
|
|
10
|
+
*/
|
|
11
|
+
/** @brief The length prefix: 4 bytes, u32 little-endian. */
|
|
9
12
|
export const PREFIX_BYTES = 4;
|
|
10
13
|
/**
|
|
11
|
-
* The largest frame the prefix may announce (16 MiB — the C++
|
|
12
|
-
* cap).
|
|
13
|
-
*
|
|
14
|
+
* @brief The largest frame the prefix may announce (16 MiB — the C++
|
|
15
|
+
* `kMaxFrame` cap).
|
|
16
|
+
*
|
|
17
|
+
* A larger prefix is malformed: the stream has lost framing sync and cannot be
|
|
18
|
+
* trusted again.
|
|
14
19
|
*/
|
|
15
20
|
export const MAX_FRAME = 16 * 1024 * 1024;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
21
|
+
/**
|
|
22
|
+
* @brief Thrown by {@link FrameReassembler.push} on a prefix announcing more
|
|
23
|
+
* than {@link MAX_FRAME} bytes — the stream is desynced and must be torn down.
|
|
24
|
+
*/
|
|
18
25
|
export class MalformedPrefixError extends Error {
|
|
19
26
|
constructor(announced) {
|
|
20
27
|
super(`malformed length prefix: ${announced} > MAX_FRAME (${MAX_FRAME})`);
|
|
@@ -22,7 +29,7 @@ export class MalformedPrefixError extends Error {
|
|
|
22
29
|
this.announced = announced;
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
|
-
/** Encode one frame as a length-prefixed record: `u32-LE length ++ frame`. */
|
|
32
|
+
/** @brief Encode one frame as a length-prefixed record: `u32-LE length ++ frame`. */
|
|
26
33
|
export function encodeRecord(frame) {
|
|
27
34
|
if (frame.byteLength > MAX_FRAME) {
|
|
28
35
|
throw new RangeError(`frame of ${frame.byteLength} bytes exceeds MAX_FRAME (${MAX_FRAME})`);
|
|
@@ -33,9 +40,9 @@ export function encodeRecord(frame) {
|
|
|
33
40
|
return out;
|
|
34
41
|
}
|
|
35
42
|
/**
|
|
36
|
-
* Reassemble length-prefixed records from arbitrary stream chunks (a
|
|
37
|
-
* stream delivers reads at transport-chosen boundaries: prefixes split
|
|
38
|
-
* chunks, records coalesced into one chunk — both are normal).
|
|
43
|
+
* @brief Reassemble length-prefixed records from arbitrary stream chunks (a
|
|
44
|
+
* QUIC stream delivers reads at transport-chosen boundaries: prefixes split
|
|
45
|
+
* across chunks, records coalesced into one chunk — both are normal).
|
|
39
46
|
*
|
|
40
47
|
* `push(chunk)` returns every COMPLETE frame the chunk finished; partial bytes
|
|
41
48
|
* are buffered for the next push. A zero-length record is a no-op (skipped,
|
|
@@ -47,7 +54,7 @@ export class FrameReassembler {
|
|
|
47
54
|
constructor() {
|
|
48
55
|
this.pending = new Uint8Array(0);
|
|
49
56
|
}
|
|
50
|
-
/** Feed one stream chunk; returns the frames it completed (possibly none). */
|
|
57
|
+
/** @brief Feed one stream chunk; returns the frames it completed (possibly none). */
|
|
51
58
|
push(chunk) {
|
|
52
59
|
if (this.pending.byteLength === 0) {
|
|
53
60
|
this.pending = chunk;
|
|
@@ -78,7 +85,7 @@ export class FrameReassembler {
|
|
|
78
85
|
this.pending = off === 0 ? this.pending : this.pending.slice(off);
|
|
79
86
|
return frames;
|
|
80
87
|
}
|
|
81
|
-
/** Bytes buffered awaiting the rest of a prefix/body (diagnostics). */
|
|
88
|
+
/** @brief Bytes buffered awaiting the rest of a prefix/body (diagnostics). */
|
|
82
89
|
get buffered() {
|
|
83
90
|
return this.pending.byteLength;
|
|
84
91
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief @avatarsd-llc/libtracer-webtransport — WebTransport transport for
|
|
3
|
+
* libtracer (ADR-0043 Phase B, the #92 browser->robot path recorded in
|
|
4
|
+
* ADR-0031).
|
|
5
|
+
*
|
|
6
|
+
* A transport is a vertex behind a swappable seam (ADR-0027); WebTransport is
|
|
7
|
+
* the browser-reachable form of QUIC (ADR-0031 ranks it above plain QUIC for
|
|
8
|
+
* the browser and above WebSocket for streams). This package carries libtracer
|
|
9
|
+
* TLV frames over ONE WebTransport bidirectional stream with 4-byte u32-LE
|
|
10
|
+
* length-prefix framing, wire-compatible with the C++
|
|
11
|
+
* `tr::net::webtransport_transport_t` (the libtracer_quic module).
|
|
12
|
+
*
|
|
13
|
+
* Two entry points:
|
|
14
|
+
* - the `framing` subpath: the pure, socket-free length-prefix record codec
|
|
15
|
+
* (shared with the C++ TCP/QUIC/WebTransport stream framing); and
|
|
16
|
+
* - this barrel: the `TransportWebTransport` client plus a re-export.
|
|
17
|
+
* The core (`@avatarsd-llc/libtracer`) is a peerDependency (ADR-0033).
|
|
18
|
+
*/
|
|
1
19
|
export declare const TRANSPORT: "webtransport";
|
|
2
20
|
export { PREFIX_BYTES, MAX_FRAME, MalformedPrefixError, encodeRecord, FrameReassembler, } from './framing.js';
|
|
3
21
|
export { TransportWebTransport } from './transport.js';
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @brief @avatarsd-llc/libtracer-webtransport — WebTransport transport for
|
|
5
|
+
* libtracer (ADR-0043 Phase B, the #92 browser->robot path recorded in
|
|
6
|
+
* ADR-0031).
|
|
7
|
+
*
|
|
8
|
+
* A transport is a vertex behind a swappable seam (ADR-0027); WebTransport is
|
|
9
|
+
* the browser-reachable form of QUIC (ADR-0031 ranks it above plain QUIC for
|
|
10
|
+
* the browser and above WebSocket for streams). This package carries libtracer
|
|
11
|
+
* TLV frames over ONE WebTransport bidirectional stream with 4-byte u32-LE
|
|
12
|
+
* length-prefix framing, wire-compatible with the C++
|
|
13
|
+
* `tr::net::webtransport_transport_t` (the libtracer_quic module).
|
|
14
|
+
*
|
|
15
|
+
* Two entry points:
|
|
16
|
+
* - the `framing` subpath: the pure, socket-free length-prefix record codec
|
|
17
|
+
* (shared with the C++ TCP/QUIC/WebTransport stream framing); and
|
|
18
|
+
* - this barrel: the `TransportWebTransport` client plus a re-export.
|
|
19
|
+
* The core (`@avatarsd-llc/libtracer`) is a peerDependency (ADR-0033).
|
|
20
|
+
*/
|
|
18
21
|
export const TRANSPORT = 'webtransport';
|
|
19
22
|
export { PREFIX_BYTES, MAX_FRAME, MalformedPrefixError, encodeRecord, FrameReassembler, } from './framing.js';
|
|
20
23
|
export { TransportWebTransport } from './transport.js';
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/** A received libtracer frame: the payload of one complete length-prefixed record. */
|
|
1
|
+
/** @brief A received libtracer frame: the payload of one complete length-prefixed record. */
|
|
2
2
|
export type FrameReceiver = (bytes: Uint8Array) => void;
|
|
3
|
-
/** Invoked once when an OPEN session closes/errors, with the cause when known. */
|
|
3
|
+
/** @brief Invoked once when an OPEN session closes/errors, with the cause when known. */
|
|
4
4
|
export type CloseHandler = (cause?: Error) => void;
|
|
5
|
-
/** One entry of `serverCertificateHashes` (the WebCrypto dev-trust pattern). */
|
|
5
|
+
/** @brief One entry of `serverCertificateHashes` (the WebCrypto dev-trust pattern). */
|
|
6
6
|
export interface WebTransportHash {
|
|
7
|
-
/** The digest algorithm; browsers accept `"sha-256"`. */
|
|
7
|
+
/** @brief The digest algorithm; browsers accept `"sha-256"`. */
|
|
8
8
|
algorithm: string;
|
|
9
|
-
/** The digest of the server certificate's DER bytes. */
|
|
9
|
+
/** @brief The digest of the server certificate's DER bytes. */
|
|
10
10
|
value: ArrayBuffer | ArrayBufferView;
|
|
11
11
|
}
|
|
12
|
-
/** The constructor options subset this transport forwards to `WebTransport`. */
|
|
12
|
+
/** @brief The constructor options subset this transport forwards to `WebTransport`. */
|
|
13
13
|
export interface WebTransportInit {
|
|
14
14
|
serverCertificateHashes?: WebTransportHash[];
|
|
15
15
|
}
|
|
16
|
-
/** The minimal reader surface of a `ReadableStream<Uint8Array>`. */
|
|
16
|
+
/** @brief The minimal reader surface of a `ReadableStream<Uint8Array>`. */
|
|
17
17
|
export interface StreamReaderLike {
|
|
18
18
|
read(): Promise<{
|
|
19
19
|
done: boolean;
|
|
@@ -21,12 +21,12 @@ export interface StreamReaderLike {
|
|
|
21
21
|
}>;
|
|
22
22
|
cancel(reason?: unknown): Promise<unknown> | void;
|
|
23
23
|
}
|
|
24
|
-
/** The minimal writer surface of a `WritableStream<Uint8Array>`. */
|
|
24
|
+
/** @brief The minimal writer surface of a `WritableStream<Uint8Array>`. */
|
|
25
25
|
export interface StreamWriterLike {
|
|
26
26
|
write(chunk: Uint8Array): Promise<void>;
|
|
27
27
|
close(): Promise<void>;
|
|
28
28
|
}
|
|
29
|
-
/** The minimal bidirectional-stream surface this transport relies on. */
|
|
29
|
+
/** @brief The minimal bidirectional-stream surface this transport relies on. */
|
|
30
30
|
export interface WebTransportBidiLike {
|
|
31
31
|
readable: {
|
|
32
32
|
getReader(): StreamReaderLike;
|
|
@@ -35,7 +35,7 @@ export interface WebTransportBidiLike {
|
|
|
35
35
|
getWriter(): StreamWriterLike;
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
/** The minimal `WebTransport` surface this transport relies on. */
|
|
38
|
+
/** @brief The minimal `WebTransport` surface this transport relies on. */
|
|
39
39
|
export interface WebTransportLike {
|
|
40
40
|
ready: Promise<unknown>;
|
|
41
41
|
closed: Promise<unknown>;
|
|
@@ -45,26 +45,30 @@ export interface WebTransportLike {
|
|
|
45
45
|
}): void;
|
|
46
46
|
createBidirectionalStream(): Promise<WebTransportBidiLike>;
|
|
47
47
|
}
|
|
48
|
-
/** Constructs a {@link WebTransportLike} for an `https://` URL. */
|
|
48
|
+
/** @brief Constructs a {@link WebTransportLike} for an `https://` URL. */
|
|
49
49
|
export type WebTransportCtor = new (url: string, options?: WebTransportInit) => WebTransportLike;
|
|
50
|
-
/** Options for {@link TransportWebTransport}. */
|
|
50
|
+
/** @brief Options for {@link TransportWebTransport}. */
|
|
51
51
|
export interface TransportWebTransportOptions {
|
|
52
52
|
/**
|
|
53
|
-
* The WebTransport implementation to dial with.
|
|
54
|
-
*
|
|
55
|
-
*
|
|
53
|
+
* @brief The WebTransport implementation to dial with.
|
|
54
|
+
*
|
|
55
|
+
* Defaults to the runtime global `WebTransport` (browsers; Node has no
|
|
56
|
+
* native client — use the mocked implementation in tests, or run the
|
|
57
|
+
* browser interop harness).
|
|
56
58
|
*/
|
|
57
59
|
WebTransport?: WebTransportCtor;
|
|
58
60
|
/**
|
|
59
|
-
* Dev-time certificate pinning: the SHA-256 hash(es) of the server's
|
|
60
|
-
* certificate (`openssl x509 -in cert.pem -outform der | openssl dgst
|
|
61
|
-
* -sha256`).
|
|
62
|
-
*
|
|
61
|
+
* @brief Dev-time certificate pinning: the SHA-256 hash(es) of the server's
|
|
62
|
+
* DER certificate (`openssl x509 -in cert.pem -outform der | openssl dgst
|
|
63
|
+
* -sha256`).
|
|
64
|
+
*
|
|
65
|
+
* Browsers require an ECDSA certificate valid <= 14 days for this path.
|
|
66
|
+
* Omit in deployment (real certificate).
|
|
63
67
|
*/
|
|
64
68
|
serverCertificateHashes?: WebTransportHash[];
|
|
65
69
|
}
|
|
66
70
|
/**
|
|
67
|
-
* A WebTransport-backed libtracer transport client.
|
|
71
|
+
* @brief A WebTransport-backed libtracer transport client.
|
|
68
72
|
*
|
|
69
73
|
* Lifecycle: construct with an `https://host:port/` URL, `await connect()`
|
|
70
74
|
* (session handshake + the bidirectional frame stream), then `send()` TLV
|
|
@@ -82,43 +86,49 @@ export declare class TransportWebTransport {
|
|
|
82
86
|
private closeHandler;
|
|
83
87
|
private closeNotified;
|
|
84
88
|
/**
|
|
89
|
+
* @brief Resolve the WebTransport implementation and remember the endpoint.
|
|
85
90
|
* @param url The `https://host:port/path` WebTransport endpoint to dial.
|
|
86
91
|
* @param options Transport options; see {@link TransportWebTransportOptions}.
|
|
87
92
|
*/
|
|
88
93
|
constructor(url: string, options?: TransportWebTransportOptions);
|
|
89
94
|
/**
|
|
90
|
-
* Register (or clear) the inbound-frame receiver.
|
|
91
|
-
*
|
|
92
|
-
*
|
|
95
|
+
* @brief Register (or clear) the inbound-frame receiver.
|
|
96
|
+
*
|
|
97
|
+
* Mirrors the C++ `set_receiver`: invoked once per complete length-prefixed
|
|
98
|
+
* record with that record's frame bytes.
|
|
93
99
|
*/
|
|
94
100
|
onFrame(receiver: FrameReceiver | null): void;
|
|
95
101
|
/**
|
|
96
|
-
* Register (or clear) the connection-closed notifier (the
|
|
97
|
-
* seam's optional close hook).
|
|
98
|
-
*
|
|
102
|
+
* @brief Register (or clear) the connection-closed notifier (the
|
|
103
|
+
* `ClientTransport` seam's optional close hook).
|
|
104
|
+
*
|
|
105
|
+
* Invoked at most once per session, when an OPEN session closes — remotely,
|
|
106
|
+
* on error, or via {@link close}.
|
|
99
107
|
*/
|
|
100
108
|
onClose(handler: CloseHandler | null): void;
|
|
101
|
-
/** Fire the close notifier exactly once for the current session. */
|
|
109
|
+
/** @brief Fire the close notifier exactly once for the current session. */
|
|
102
110
|
private notifyClose;
|
|
103
|
-
/** True once the session and its frame stream are up and not yet closed. */
|
|
111
|
+
/** @brief True once the session and its frame stream are up and not yet closed. */
|
|
104
112
|
get connected(): boolean;
|
|
105
113
|
/**
|
|
106
|
-
* Establish the WebTransport session (HTTP/3 extended CONNECT) and
|
|
107
|
-
* ONE bidirectional frame stream.
|
|
114
|
+
* @brief Establish the WebTransport session (HTTP/3 extended CONNECT) and
|
|
115
|
+
* open the ONE bidirectional frame stream.
|
|
108
116
|
*
|
|
109
117
|
* @param deadlineMs Reject if the session is not ready within this many
|
|
110
118
|
* milliseconds (default 5000). Uses events, never a sleep.
|
|
111
119
|
* @returns A promise that resolves when frames can flow.
|
|
112
120
|
*/
|
|
113
121
|
connect(deadlineMs?: number): Promise<void>;
|
|
114
|
-
/** Pump the frame stream through the reassembler until it ends. */
|
|
122
|
+
/** @brief Pump the frame stream through the reassembler until it ends. */
|
|
115
123
|
private readLoop;
|
|
116
124
|
/**
|
|
117
|
-
* Send one complete libtracer TLV as one length-prefixed record on
|
|
118
|
-
* stream.
|
|
119
|
-
*
|
|
125
|
+
* @brief Send one complete libtracer TLV as one length-prefixed record on
|
|
126
|
+
* the frame stream.
|
|
127
|
+
*
|
|
128
|
+
* Throws if not connected; a transmit failure surfaces through the session's
|
|
129
|
+
* close notifier (the underlying write is asynchronous).
|
|
120
130
|
*/
|
|
121
131
|
send(frame: Uint8Array): void;
|
|
122
|
-
/** Close the session. Resolves once the session has fully closed. */
|
|
132
|
+
/** @brief Close the session. Resolves once the session has fully closed. */
|
|
123
133
|
close(): Promise<void>;
|
|
124
134
|
}
|
package/dist/transport.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @brief TransportWebTransport — the browser WebTransport transport for
|
|
5
|
+
* libtracer (ADR-0043 Phase B / ADR-0031: the browser-facing low-latency form
|
|
6
|
+
* of QUIC).
|
|
7
|
+
*
|
|
8
|
+
* It mirrors the seam of the C++ `tr::net::webtransport_transport_t`
|
|
9
|
+
* (core/src/transport_webtransport.cpp) from the DIAL side: the runtime's
|
|
10
|
+
* `WebTransport` performs the HTTP/3 extended-CONNECT session handshake, then
|
|
11
|
+
* this transport opens ONE bidirectional stream (`createBidirectionalStream`)
|
|
12
|
+
* as the frame channel and carries each libtracer TLV as a `u32-LE length ++
|
|
13
|
+
* frame` record (./framing.ts) — the identical stream framing the C++ TCP,
|
|
14
|
+
* QUIC and WebTransport transports speak, so a browser interoperates with a
|
|
15
|
+
* C++ `webtransport_transport_t` listener directly.
|
|
16
|
+
*
|
|
17
|
+
* Dev-time trust uses the standard WebTransport pattern: pass the SHA-256 hash
|
|
18
|
+
* of the server's certificate via `serverCertificateHashes` (the certificate
|
|
19
|
+
* must be ECDSA and valid <= 14 days — a browser rule, not ours). Deployments
|
|
20
|
+
* use a real certificate and omit the option.
|
|
21
|
+
*/
|
|
19
22
|
import { FrameReassembler, encodeRecord } from './framing.js';
|
|
20
23
|
/**
|
|
21
|
-
* A WebTransport-backed libtracer transport client.
|
|
24
|
+
* @brief A WebTransport-backed libtracer transport client.
|
|
22
25
|
*
|
|
23
26
|
* Lifecycle: construct with an `https://host:port/` URL, `await connect()`
|
|
24
27
|
* (session handshake + the bidirectional frame stream), then `send()` TLV
|
|
@@ -28,6 +31,7 @@ import { FrameReassembler, encodeRecord } from './framing.js';
|
|
|
28
31
|
*/
|
|
29
32
|
export class TransportWebTransport {
|
|
30
33
|
/**
|
|
34
|
+
* @brief Resolve the WebTransport implementation and remember the endpoint.
|
|
31
35
|
* @param url The `https://host:port/path` WebTransport endpoint to dial.
|
|
32
36
|
* @param options Transport options; see {@link TransportWebTransportOptions}.
|
|
33
37
|
*/
|
|
@@ -47,22 +51,25 @@ export class TransportWebTransport {
|
|
|
47
51
|
this.hashes = options.serverCertificateHashes;
|
|
48
52
|
}
|
|
49
53
|
/**
|
|
50
|
-
* Register (or clear) the inbound-frame receiver.
|
|
51
|
-
*
|
|
52
|
-
*
|
|
54
|
+
* @brief Register (or clear) the inbound-frame receiver.
|
|
55
|
+
*
|
|
56
|
+
* Mirrors the C++ `set_receiver`: invoked once per complete length-prefixed
|
|
57
|
+
* record with that record's frame bytes.
|
|
53
58
|
*/
|
|
54
59
|
onFrame(receiver) {
|
|
55
60
|
this.receiver = receiver;
|
|
56
61
|
}
|
|
57
62
|
/**
|
|
58
|
-
* Register (or clear) the connection-closed notifier (the
|
|
59
|
-
* seam's optional close hook).
|
|
60
|
-
*
|
|
63
|
+
* @brief Register (or clear) the connection-closed notifier (the
|
|
64
|
+
* `ClientTransport` seam's optional close hook).
|
|
65
|
+
*
|
|
66
|
+
* Invoked at most once per session, when an OPEN session closes — remotely,
|
|
67
|
+
* on error, or via {@link close}.
|
|
61
68
|
*/
|
|
62
69
|
onClose(handler) {
|
|
63
70
|
this.closeHandler = handler;
|
|
64
71
|
}
|
|
65
|
-
/** Fire the close notifier exactly once for the current session. */
|
|
72
|
+
/** @brief Fire the close notifier exactly once for the current session. */
|
|
66
73
|
notifyClose(cause) {
|
|
67
74
|
if (this.closeNotified)
|
|
68
75
|
return;
|
|
@@ -70,13 +77,13 @@ export class TransportWebTransport {
|
|
|
70
77
|
if (this.closeHandler)
|
|
71
78
|
this.closeHandler(cause);
|
|
72
79
|
}
|
|
73
|
-
/** True once the session and its frame stream are up and not yet closed. */
|
|
80
|
+
/** @brief True once the session and its frame stream are up and not yet closed. */
|
|
74
81
|
get connected() {
|
|
75
82
|
return this.wt !== null && this.writer !== null;
|
|
76
83
|
}
|
|
77
84
|
/**
|
|
78
|
-
* Establish the WebTransport session (HTTP/3 extended CONNECT) and
|
|
79
|
-
* ONE bidirectional frame stream.
|
|
85
|
+
* @brief Establish the WebTransport session (HTTP/3 extended CONNECT) and
|
|
86
|
+
* open the ONE bidirectional frame stream.
|
|
80
87
|
*
|
|
81
88
|
* @param deadlineMs Reject if the session is not ready within this many
|
|
82
89
|
* milliseconds (default 5000). Uses events, never a sleep.
|
|
@@ -127,7 +134,7 @@ export class TransportWebTransport {
|
|
|
127
134
|
clearTimeout(timer);
|
|
128
135
|
}
|
|
129
136
|
}
|
|
130
|
-
/** Pump the frame stream through the reassembler until it ends. */
|
|
137
|
+
/** @brief Pump the frame stream through the reassembler until it ends. */
|
|
131
138
|
async readLoop(reader) {
|
|
132
139
|
const reassembler = new FrameReassembler();
|
|
133
140
|
try {
|
|
@@ -157,9 +164,11 @@ export class TransportWebTransport {
|
|
|
157
164
|
}
|
|
158
165
|
}
|
|
159
166
|
/**
|
|
160
|
-
* Send one complete libtracer TLV as one length-prefixed record on
|
|
161
|
-
* stream.
|
|
162
|
-
*
|
|
167
|
+
* @brief Send one complete libtracer TLV as one length-prefixed record on
|
|
168
|
+
* the frame stream.
|
|
169
|
+
*
|
|
170
|
+
* Throws if not connected; a transmit failure surfaces through the session's
|
|
171
|
+
* close notifier (the underlying write is asynchronous).
|
|
163
172
|
*/
|
|
164
173
|
send(frame) {
|
|
165
174
|
if (!this.writer)
|
|
@@ -170,7 +179,7 @@ export class TransportWebTransport {
|
|
|
170
179
|
/* surfaced via wt.closed */
|
|
171
180
|
});
|
|
172
181
|
}
|
|
173
|
-
/** Close the session. Resolves once the session has fully closed. */
|
|
182
|
+
/** @brief Close the session. Resolves once the session has fully closed. */
|
|
174
183
|
async close() {
|
|
175
184
|
const wt = this.wt;
|
|
176
185
|
if (!wt)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avatarsd-llc/libtracer-webtransport",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "WebTransport transport for libtracer (ADR-0043 Phase B) — a browser WebTransport client that carries libtracer TLV frames over ONE bidirectional stream with 4-byte u32-LE length-prefix framing, wire-compatible with the C++ tr::net::webtransport_transport_t (the libtracer_quic module). The core (@avatarsd-llc/libtracer) is a peerDependency. See docs/adr/0033-npm-subpackage-monorepo.md.",
|
|
5
5
|
"author": "avatarsd LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@avatarsd-llc/libtracer": ">=0.
|
|
40
|
+
"@avatarsd-llc/libtracer": ">=0.5.0 <0.6.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsc",
|