@caprid/relay-quic 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,119 @@
1
- # Temporary Holding Version
1
+ # @caprid/relay-quic
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Relay SDK's transport adapter for Node. It carries MOQT straight on a QUIC connection (native QUIC, with
4
+ the MOQT ALPNs the SDK offers: `moqt-22`, then `moqt-20`), through a napi-rs addon over [quinn](https://github.com/quinn-rs/quinn), so a plain Node script can publish
5
+ and subscribe without a browser. It follows the transport adapter contract in
6
+ [`spec/transport-adapter.md`](../../../spec/transport-adapter.md) and passes its conformance suite. The design is
7
+ [ADR 0002](../../../docs/adr/0002-node-adapter-speaks-native-quic.md).
8
+
9
+ The package is private for now: its prebuilt binaries are built and packed in CI, but not yet published (#195).
10
+
11
+ ## Use
12
+
13
+ Most scripts need no code from this package: `@caprid/relay/node` uses it by default, and takes the trust options below
14
+ (see the [SDK README](../../README.md#node)). Install it next to `@caprid/relay`.
15
+
16
+ To use it with `@caprid/relay` directly, pass the factory as `createTransport`. The URL stays the same `https://` endpoint the browser uses: the adapter dials
17
+ only its host and port, and the core sends the path, the token and the authority in SETUP.
18
+
19
+ ```ts
20
+ import { connectRelayPublisher } from '@caprid/relay';
21
+ import { nativeQuicTransport } from '@caprid/relay-quic';
22
+
23
+ const publisher = await connectRelayPublisher({
24
+ url: 'https://relay.mux.global',
25
+ getToken: () => process.env.RELAY_TOKEN,
26
+ createTransport: nativeQuicTransport(),
27
+ });
28
+ ```
29
+
30
+ `nativeQuicTransport()` throws at once if the addon is missing for the platform or an option is invalid. Build it once
31
+ and reuse it for every connection.
32
+
33
+ ## Trust
34
+
35
+ By default a dial trusts the platform's root certificates.
36
+
37
+ - `ca`: extra trust anchors, PEM, as a string, bytes, or an array of either. They are added to the platform's roots.
38
+ - `serverCertificateHashes`: `[{ algorithm: 'sha-256', value }]`, in the W3C WebTransport shape. The server's
39
+ end-entity certificate must match one hash, and its chain is not validated. The handshake signature is still
40
+ checked. Unlike a browser, the adapter does not require the certificate to be valid for 14 days or less.
41
+
42
+ ## Process lifetime
43
+
44
+ An open session keeps the Node process alive, from the start of the dial until `closed` settles. After that the
45
+ adapter holds nothing: a script exits once it has closed its connections. Closing before the dial completes cancels
46
+ the dial and releases its socket.
47
+
48
+ ## Prebuilt binaries
49
+
50
+ Each platform's binary ships in its own package, which `@caprid/relay-quic` lists as an optional dependency, the napi-rs
51
+ convention. A package manager installs only the one whose `os`, `cpu` and `libc` match, so no Rust is needed.
52
+
53
+ | Platform package | Built on | Packed | Installed |
54
+ | --- | --- | --- | --- |
55
+ | `@caprid/relay-quic-darwin-arm64` | macos-14 | 1.14 MiB | 2.62 MiB |
56
+ | `@caprid/relay-quic-darwin-x64` | macos-14, cross | 1.21 MiB | 2.85 MiB |
57
+ | `@caprid/relay-quic-linux-arm64-gnu` | ubuntu-latest, zig | 1.19 MiB | 2.67 MiB |
58
+ | `@caprid/relay-quic-linux-arm64-musl` | ubuntu-latest, zig | 1.19 MiB | 2.67 MiB |
59
+ | `@caprid/relay-quic-linux-x64-gnu` | ubuntu-latest, zig | 1.26 MiB | 3.01 MiB |
60
+ | `@caprid/relay-quic-linux-x64-musl` | ubuntu-latest, zig | 1.26 MiB | 3.00 MiB |
61
+ | `@caprid/relay-quic-win32-x64-msvc` | windows-latest | 1.26 MiB | 3.33 MiB |
62
+
63
+ Installed is what an install puts on disk on that platform: this package, `@caprid/moq-core` and the one binary. The
64
+ sizes are from the 0.0.0 packages CI packed on 2026-10-01. The glibc builds need glibc 2.28 or later, which Node 24
65
+ needs too.
66
+
67
+ `src/addon.ts` loads a local build, `native/relay-quic.<platform>.node`, first, so a build from source always wins.
68
+ Without one it loads `@caprid/relay-quic-<platform>`. If neither is there, the error names both. A platform package that is
69
+ installed but cannot load (a wrong libc, say) throws its own error rather than being skipped.
70
+
71
+ The `relay-quic binaries` workflow (`.github/workflows/relay-quic-binaries.yml`) runs on each PR that touches the crate,
72
+ the loader or the packaging. It builds every target, and `scripts/pack.mjs` packs the main package, the platform
73
+ packages and `@caprid/moq-core`, with the sizes in the job summary. `scripts/smoke.mjs` then installs those tarballs with
74
+ npm on each platform (musl in Alpine, arm64 Linux under QEMU, darwin-x64 under Rosetta). It checks that npm picked only
75
+ the matching binary, that the loader finds it, and that a dial sends a QUIC Initial and can be cancelled. The
76
+ `Release TypeScript SDK` workflow (`release-ts.yml`) calls this one and publishes the tarballs it packs, with the rest of
77
+ the TypeScript packages ([releasing](../../../docs/releasing.md)).
78
+
79
+ The platform packages live in `npm/<platform>/`, generated by `napi create-npm-dirs` from `napi.targets`. The
80
+ optional dependencies on them are added only when packing, so the lockfile never names unpublished packages.
81
+ `pnpm check:boundaries` checks that the two agree.
82
+
83
+ ## Stability
84
+
85
+ Before 1.0, a minor version can break the API. This package and its platform packages release
86
+ together with `@caprid/relay` at the same version; see the [changelog](../../CHANGELOG.md).
87
+
88
+ ## Building the addon
89
+
90
+ To work on the crate, build the addon locally with Rust. The mise tasks bring the toolchain `mise.toml` pins; nothing
91
+ else in the repo installs one.
92
+
93
+ ```sh
94
+ mise run ts:test:conformance:node # builds the addon, then runs the conformance suite against it
95
+ mise run ts:check:native # cargo fmt --check, clippy and the unit tests
96
+ mise run ts:build:native -- --target aarch64-unknown-linux-musl -x # cross-compiles with zig, as CI does
97
+ ```
98
+
99
+ With a Rust toolchain of your own, `cd ts && pnpm --filter @caprid/relay-quic build:native` writes
100
+ `native/relay-quic.<platform>.node`. Cross-compiling with `-x` also needs `cargo-zigbuild` and the target's
101
+ `rustup target add`.
102
+
103
+ `build:native` also regenerates `src/native.d.ts`, the addon's typings, from the Rust. Commit it with any change to
104
+ the crate. CI checks that it matches.
105
+
106
+ `pnpm check` builds and checks the TypeScript only, so the rest of the workspace needs no Rust.
107
+
108
+ ## Layout
109
+
110
+ | Path | What it is |
111
+ | --- | --- |
112
+ | `src/index.ts` | `nativeQuicTransport` and its option and result types. |
113
+ | `src/transport.ts` | The `MoqtTransport`: the dial, `ready`, `protocol`, `closed`, `close()` and the incoming streams. |
114
+ | `src/streams.ts` | WHATWG streams over the addon's stream halves. |
115
+ | `src/errors.ts` | The addon's failures as the contract's error shapes (TA-22). |
116
+ | `src/addon.ts` | Finds and loads the addon for this platform: a local build, else the platform package. |
117
+ | `native/` | The Rust crate: trust (`tls.rs`), stream halves (`stream.rs`), failures as data (`failure.rs`), the dial and the session (`lib.rs`). |
118
+ | `npm/<platform>/` | The platform packages, one per `napi.targets` entry; CI puts each binary in its own. |
119
+ | `scripts/pack.mjs`, `scripts/smoke.mjs` | Pack the release tarballs with their sizes; install and smoke-load them. |
@@ -0,0 +1,16 @@
1
+ import type * as Addon from './native.js';
2
+ export type { BiStream, Client, Dial, Failure, ReadResult, RecvStream, SendStream, Session } from './native.js';
3
+ /** The addon's exports. */
4
+ export type NativeAddon = typeof Addon;
5
+ /** The platform suffix napi-rs gives the binary: `linux-x64-gnu`, `linux-x64-musl`, `darwin-arm64` and so on. */
6
+ export declare function platformSuffix(platform?: string, arch?: string, glibc?: boolean): string;
7
+ /** Where the addon for a platform suffix may be, in the order {@link loadAddon} tries them. */
8
+ export declare function addonCandidates(suffix?: string): [localFile: string, platformPackage: string];
9
+ /**
10
+ * The first of `candidates` that `load` finds. A candidate that is not there is skipped; one that is there but fails
11
+ * to load (a wrong libc, say) throws its own error. Throws, naming every place it looked, when none is there.
12
+ */
13
+ export declare function loadFirst(candidates: readonly string[], load: (id: string) => unknown, suffix: string): unknown;
14
+ /** The addon, loaded on first use. Throws, naming the places it looked, when there is no binary for this platform. */
15
+ export declare function loadAddon(): NativeAddon;
16
+ //# sourceMappingURL=addon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addon.d.ts","sourceRoot":"","sources":["../src/addon.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAC;AAE1C,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEhH,2BAA2B;AAC3B,MAAM,MAAM,WAAW,GAAG,OAAO,KAAK,CAAC;AAIvC,iHAAiH;AACjH,wBAAgB,cAAc,CAC5B,QAAQ,GAAE,MAAyB,EACnC,IAAI,GAAE,MAAqB,EAC3B,KAAK,GAAE,OAAoB,GAC1B,MAAM,CAIR;AAOD,+FAA+F;AAC/F,wBAAgB,eAAe,CAAC,MAAM,GAAE,MAAyB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,CAK/G;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAgB/G;AAQD,sHAAsH;AACtH,wBAAgB,SAAS,IAAI,WAAW,CAKvC"}
package/dist/addon.js ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Loads the native addon (`native/`, built by `napi build`) for this platform. A local build,
3
+ * `native/relay-quic.<platform>-<arch>[-<libc>].node`, wins; otherwise the binary comes from the prebuilt platform
4
+ * package `@caprid/relay-quic-<platform>-<arch>[-<libc>]`, one of this package's optional dependencies (#195).
5
+ */
6
+ import { createRequire } from 'node:module';
7
+ import { fileURLToPath } from 'node:url';
8
+ let addon;
9
+ /** The platform suffix napi-rs gives the binary: `linux-x64-gnu`, `linux-x64-musl`, `darwin-arm64` and so on. */
10
+ export function platformSuffix(platform = process.platform, arch = process.arch, glibc = hasGlibc()) {
11
+ if (platform === 'linux')
12
+ return `linux-${arch}-${glibc ? 'gnu' : 'musl'}`;
13
+ if (platform === 'win32')
14
+ return `win32-${arch}-msvc`;
15
+ return `${platform}-${arch}`;
16
+ }
17
+ function hasGlibc() {
18
+ const report = process.report?.getReport();
19
+ return typeof report?.header?.glibcVersionRuntime === 'string';
20
+ }
21
+ /** Where the addon for a platform suffix may be, in the order {@link loadAddon} tries them. */
22
+ export function addonCandidates(suffix = platformSuffix()) {
23
+ return [
24
+ fileURLToPath(new URL(`../native/relay-quic.${suffix}.node`, import.meta.url)),
25
+ `@caprid/relay-quic-${suffix}`,
26
+ ];
27
+ }
28
+ /**
29
+ * The first of `candidates` that `load` finds. A candidate that is not there is skipped; one that is there but fails
30
+ * to load (a wrong libc, say) throws its own error. Throws, naming every place it looked, when none is there.
31
+ */
32
+ export function loadFirst(candidates, load, suffix) {
33
+ const missing = [];
34
+ for (const candidate of candidates) {
35
+ try {
36
+ return load(candidate);
37
+ }
38
+ catch (error) {
39
+ if (!isNotFound(error, candidate))
40
+ throw error;
41
+ missing.push(error);
42
+ }
43
+ }
44
+ throw new Error(`@caprid/relay-quic has no native binary for this platform (${suffix}). Install its optional dependency ` +
45
+ `${candidates.at(-1)}, which a package manager skips when optional dependencies are off, or build ` +
46
+ `${candidates[0]} with \`pnpm --filter @caprid/relay-quic build:native\`, which needs a Rust toolchain.`, { cause: new AggregateError(missing, 'no candidate was found') });
47
+ }
48
+ /** Whether `error` says `id` itself is missing, rather than something it needs. */
49
+ function isNotFound(error, id) {
50
+ const { code, message } = error;
51
+ return code === 'MODULE_NOT_FOUND' && typeof message === 'string' && message.includes(`'${id}'`);
52
+ }
53
+ /** The addon, loaded on first use. Throws, naming the places it looked, when there is no binary for this platform. */
54
+ export function loadAddon() {
55
+ if (addon)
56
+ return addon;
57
+ const suffix = platformSuffix();
58
+ addon = loadFirst(addonCandidates(suffix), createRequire(import.meta.url), suffix);
59
+ return addon;
60
+ }
61
+ //# sourceMappingURL=addon.js.map
@@ -0,0 +1 @@
1
+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KAAK,EAAE,CAAC;YACf,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;gBAAE,MAAM,KAAK,CAAC;YAC/C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CACb,8DAA8D,MAAM,qCAAqC;QACvG,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,+EAA+E;QACnG,GAAG,UAAU,CAAC,CAAC,CAAC,wFAAwF,EAC1G,EAAE,KAAK,EAAE,IAAI,cAAc,CAAC,OAAO,EAAE,wBAAwB,CAAC,EAAE,CACjE,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,SAAS,UAAU,CAAC,KAAc,EAAE,EAAU;IAC5C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,KAA8C,CAAC;IACzE,OAAO,IAAI,KAAK,kBAAkB,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACnG,CAAC;AAED,sHAAsH;AACtH,MAAM,UAAU,SAAS;IACvB,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IACxB,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,KAAK,GAAG,SAAS,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAgB,CAAC;IAClG,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { Failure } from './addon.js';
2
+ /** A session failure (TA-22): the session is over, or the dial failed. */
3
+ export declare class NativeQuicSessionError extends Error {
4
+ readonly name = "NativeQuicSessionError";
5
+ /** Always `'session'`. */
6
+ readonly source = "session";
7
+ /** What ended the session, as the addon reports it: `application`, `transport`, `timeout`, `cancelled` and so on. */
8
+ readonly kind: string;
9
+ /** The peer's application close code, when the peer closed the session (TA-24). */
10
+ readonly closeCode?: number;
11
+ /** The peer's close reason, when the peer closed the session (TA-24). */
12
+ readonly reason?: string;
13
+ constructor(message: string, kind: string, close?: {
14
+ closeCode: number;
15
+ reason: string;
16
+ });
17
+ }
18
+ /** A decimal code as a number, or `null` above 2⁵³−1, where a number would round (TA-22). */
19
+ export declare function safeCode(code: string | undefined): number | null;
20
+ /** The code a reset or a stop carries for `reason` (TA-17): its integer `streamErrorCode` from 0 to 2³²−1, else 0. */
21
+ export declare function resetCode(reason: unknown): number;
22
+ /** The error an operation rejects with for `failure`. */
23
+ export declare function toError(failure: Failure): Error;
24
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,0EAA0E;AAC1E,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,SAAkB,IAAI,4BAA4B;IAClD,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,aAAa;IAC5B,qHAAqH;IACrH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mFAAmF;IACnF,SAAiB,SAAS,CAAC,EAAE,MAAM,CAAC;IACpC,yEAAyE;IACzE,SAAiB,MAAM,CAAC,EAAE,MAAM,CAAC;gBAErB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;CAQzF;AAID,6FAA6F;AAC7F,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAIhE;AAED,sHAAsH;AACtH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAMjD;AAED,yDAAyD;AACzD,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,KAAK,CAiB/C"}
package/dist/errors.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The addon's failures as the contract's error shapes (spec/transport-adapter.md TA-22): a stream error is the core's
3
+ * `MoqtStreamError`, a session error a {@link NativeQuicSessionError}. Codes cross from Rust as decimal strings, since a
4
+ * QUIC varint has 62 bits.
5
+ */
6
+ import { MoqtStreamError } from '@caprid/moq-core';
7
+ /** A session failure (TA-22): the session is over, or the dial failed. */
8
+ export class NativeQuicSessionError extends Error {
9
+ name = 'NativeQuicSessionError';
10
+ /** Always `'session'`. */
11
+ source = 'session';
12
+ /** What ended the session, as the addon reports it: `application`, `transport`, `timeout`, `cancelled` and so on. */
13
+ kind;
14
+ constructor(message, kind, close) {
15
+ super(message);
16
+ this.kind = kind;
17
+ if (close) {
18
+ this.closeCode = close.closeCode;
19
+ this.reason = close.reason;
20
+ }
21
+ }
22
+ }
23
+ const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
24
+ /** A decimal code as a number, or `null` above 2⁵³−1, where a number would round (TA-22). */
25
+ export function safeCode(code) {
26
+ if (code === undefined)
27
+ return null;
28
+ const value = BigInt(code);
29
+ return value <= MAX_SAFE ? Number(value) : null;
30
+ }
31
+ /** The code a reset or a stop carries for `reason` (TA-17): its integer `streamErrorCode` from 0 to 2³²−1, else 0. */
32
+ export function resetCode(reason) {
33
+ const code = typeof reason === 'object' && reason !== null
34
+ ? reason.streamErrorCode
35
+ : undefined;
36
+ return typeof code === 'number' && Number.isInteger(code) && code >= 0 && code <= 0xffff_ffff ? code : 0;
37
+ }
38
+ /** The error an operation rejects with for `failure`. */
39
+ export function toError(failure) {
40
+ switch (failure.source) {
41
+ case 'stream': {
42
+ const what = failure.kind === 'stopped' ? 'stopped' : 'reset';
43
+ const detail = failure.code === undefined ? '' : ` (code ${failure.code})`;
44
+ return new MoqtStreamError(`the peer ${what} the stream${detail}`, safeCode(failure.code));
45
+ }
46
+ case 'session': {
47
+ // The peer's close is a session error only on a stream; `closed` itself resolves with it (TA-9).
48
+ const close = failure.kind === 'application' ? { closeCode: safeCode(failure.code) ?? 0, reason: failure.reason } : undefined;
49
+ return new NativeQuicSessionError(sessionMessage(failure), failure.kind, close);
50
+ }
51
+ default:
52
+ // `credit` and `closed` are not stream or session failures, so they carry no `source` (TA-21, TA-23).
53
+ return new Error(failure.reason);
54
+ }
55
+ }
56
+ function sessionMessage({ kind, code, reason }) {
57
+ switch (kind) {
58
+ case 'application':
59
+ return `the peer closed the session (code ${code}${reason ? `, ${reason}` : ''})`;
60
+ case 'transport':
61
+ return `the QUIC connection failed: ${reason || 'no reason given'}${code === undefined ? '' : ` (code ${code})`}`;
62
+ default:
63
+ return reason;
64
+ }
65
+ }
66
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,0EAA0E;AAC1E,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC7B,IAAI,GAAG,wBAAwB,CAAC;IAClD,0BAA0B;IACjB,MAAM,GAAG,SAAS,CAAC;IAC5B,qHAAqH;IAC5G,IAAI,CAAS;IAMtB,YAAY,OAAe,EAAE,IAAY,EAAE,KAA6C;QACtF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;YACjC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC7B,CAAC;IACH,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEjD,6FAA6F;AAC7F,MAAM,UAAU,QAAQ,CAAC,IAAwB;IAC/C,IAAI,IAAI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,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;YAClH,OAAO,IAAI,sBAAsB,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAClF,CAAC;QACD;YACE,sGAAsG;YACtG,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAW;IACrD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,aAAa;YAChB,OAAO,qCAAqC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;QACpF,KAAK,WAAW;YACd,OAAO,+BAA+B,MAAM,IAAI,iBAAiB,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,IAAI,GAAG,EAAE,CAAC;QACpH;YACE,OAAO,MAAM,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `@caprid/relay-quic`: the Relay SDK's transport adapter for Node. It speaks MOQT directly on a QUIC connection (native
3
+ * QUIC, with the MOQT ALPNs it is given: `moqt-22`, then `moqt-20`), over quinn through a napi-rs addon, and follows the transport adapter contract
4
+ * (`spec/transport-adapter.md`). Pass {@link nativeQuicTransport}'s factory as `createTransport`.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import type { MoqtTransport } from '@caprid/moq-core';
9
+ /** A certificate hash the server's end-entity certificate must match, in the W3C WebTransport shape. */
10
+ export interface CertificateHash {
11
+ /** The hash algorithm; only `'sha-256'` is supported. */
12
+ algorithm: 'sha-256';
13
+ /** The SHA-256 of the certificate's DER encoding. */
14
+ value: BufferSource;
15
+ }
16
+ /** What {@link nativeQuicTransport}'s dials trust. With neither option, a dial trusts the platform's roots. */
17
+ export interface NativeQuicTransportOptions {
18
+ /**
19
+ * Extra trust anchors, PEM encoded, added to the platform's roots: one string or buffer may hold several
20
+ * certificates.
21
+ */
22
+ ca?: string | Uint8Array | readonly (string | Uint8Array)[];
23
+ /**
24
+ * Accept exactly the end-entity certificates with these hashes instead of validating a chain, as W3C WebTransport's
25
+ * `serverCertificateHashes` does. The TLS handshake signature is still verified; the 14-day validity limit browsers
26
+ * apply is not.
27
+ */
28
+ serverCertificateHashes?: readonly CertificateHash[];
29
+ }
30
+ /** The transport a {@link NativeQuicConnection} carries: a `MoqtTransport` that reports the selected protocol. */
31
+ export interface NativeQuicMoqtTransport extends MoqtTransport {
32
+ /** The ALPN identifier the peer selected; empty until `ready` resolves. */
33
+ readonly protocol: string;
34
+ }
35
+ /** What one call of a {@link NativeQuicTransportFactory} returns: the shape the SDK's `createTransport` expects. */
36
+ export interface NativeQuicConnection {
37
+ /** The transport the MOQT session runs on. */
38
+ transport: NativeQuicMoqtTransport;
39
+ /** Resolves once the QUIC handshake completed and the peer selected an offered protocol. */
40
+ ready: Promise<void>;
41
+ /** Always `'native-quic'`: the core sends the URL's path, query and authority in SETUP. */
42
+ framing: 'native-quic';
43
+ }
44
+ /**
45
+ * Dials `url`'s host and port (443 by default) over native QUIC, offering `protocols` as the ALPN list. The path and
46
+ * query are not used here: the core carries them in SETUP.
47
+ */
48
+ export type NativeQuicTransportFactory = (url: string, protocols: string[]) => NativeQuicConnection;
49
+ /**
50
+ * A transport factory for the SDK's `createTransport` option that connects over native QUIC from Node:
51
+ *
52
+ * ```ts
53
+ * import { connectRelayPublisher } from '@caprid/relay';
54
+ * import { nativeQuicTransport } from '@caprid/relay-quic';
55
+ *
56
+ * const publisher = await connectRelayPublisher({ url, getToken, createTransport: nativeQuicTransport() });
57
+ * ```
58
+ *
59
+ * Throws at once when the native addon is missing for this platform, a `ca` entry holds no PEM certificate, or a
60
+ * certificate hash is not a 32-byte SHA-256.
61
+ */
62
+ export declare function nativeQuicTransport(options?: NativeQuicTransportOptions): NativeQuicTransportFactory;
63
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAItD,wGAAwG;AACxG,MAAM,WAAW,eAAe;IAC9B,yDAAyD;IACzD,SAAS,EAAE,SAAS,CAAC;IACrB,qDAAqD;IACrD,KAAK,EAAE,YAAY,CAAC;CACrB;AAED,+GAA+G;AAC/G,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,CAAC;IAC5D;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;CACtD;AAED,kHAAkH;AAClH,MAAM,WAAW,uBAAwB,SAAQ,aAAa;IAC5D,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,oHAAoH;AACpH,MAAM,WAAW,oBAAoB;IACnC,8CAA8C;IAC9C,SAAS,EAAE,uBAAuB,CAAC;IACnC,4FAA4F;IAC5F,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,2FAA2F;IAC3F,OAAO,EAAE,aAAa,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,oBAAoB,CAAC;AAYpG;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,0BAA+B,GAAG,0BAA0B,CAkBxG"}
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ import { loadAddon } from './addon.js';
2
+ import { NativeQuicTransport } from './transport.js';
3
+ /** PEM text from a string or bytes. */
4
+ function pem(value) {
5
+ return typeof value === 'string' ? value : new TextDecoder().decode(value);
6
+ }
7
+ function bytesOf(value) {
8
+ if (value instanceof ArrayBuffer)
9
+ return new Uint8Array(value);
10
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
11
+ }
12
+ /**
13
+ * A transport factory for the SDK's `createTransport` option that connects over native QUIC from Node:
14
+ *
15
+ * ```ts
16
+ * import { connectRelayPublisher } from '@caprid/relay';
17
+ * import { nativeQuicTransport } from '@caprid/relay-quic';
18
+ *
19
+ * const publisher = await connectRelayPublisher({ url, getToken, createTransport: nativeQuicTransport() });
20
+ * ```
21
+ *
22
+ * Throws at once when the native addon is missing for this platform, a `ca` entry holds no PEM certificate, or a
23
+ * certificate hash is not a 32-byte SHA-256.
24
+ */
25
+ export function nativeQuicTransport(options = {}) {
26
+ const { Client } = loadAddon();
27
+ const ca = options.ca === undefined ? [] : Array.isArray(options.ca) ? options.ca : [options.ca];
28
+ const client = new Client({
29
+ ca: ca.map(pem),
30
+ serverCertificateHashes: (options.serverCertificateHashes ?? []).map((hash) => {
31
+ if (hash.algorithm !== 'sha-256')
32
+ throw new TypeError(`unsupported certificate hash algorithm ${hash.algorithm}`);
33
+ return bytesOf(hash.value);
34
+ }),
35
+ });
36
+ return (url, protocols) => {
37
+ // Only the host and port are read (TA-3): the path and query, token included, travel in SETUP.
38
+ const { hostname, port } = new URL(url);
39
+ const host = hostname.startsWith('[') ? hostname.slice(1, -1) : hostname;
40
+ const transport = new NativeQuicTransport(client.dial(host, port === '' ? 443 : Number(port), host, protocols));
41
+ return { transport, ready: transport.ready, framing: 'native-quic' };
42
+ };
43
+ }
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,YA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,CAAC,CAAC;KACH,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE;QACxB,+FAA+F;QAC/F,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACzE,MAAM,SAAS,GAAG,IAAI,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;QAChH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IACvE,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * WHATWG streams over the addon's stream halves (spec/transport-adapter.md, "Streams").
3
+ *
4
+ * A send stream resets from `controller.signal`, not from the sink's `abort()`: WHATWG holds `abort()` until a pending
5
+ * write or close settles, and TA-16 needs the reset while a write is blocked on flow control or a close waits for
6
+ * acknowledgement. It watches for STOP_SENDING from the start, so `writer.closed` rejects with the peer's code even
7
+ * when nothing is in flight (TA-20).
8
+ */
9
+ import type { BiStream, RecvStream, SendStream } from './addon.js';
10
+ /** A writable over `send`. */
11
+ export declare function sendWritable(send: SendStream): WritableStream<Uint8Array>;
12
+ /**
13
+ * A readable over `recv`. It reads only on demand; between reads a native watch waits for a peer reset (TA-19) or the
14
+ * session's end (TA-12) without reading, so either settles the readable even while nothing reads it. Cancelling sends
15
+ * STOP_SENDING with the reason's code and ends the readable (TA-18).
16
+ */
17
+ export declare function recvReadable(recv: RecvStream): ReadableStream<Uint8Array>;
18
+ /** Both halves of `stream`. */
19
+ export declare function bidirectional(stream: BiStream): {
20
+ readable: ReadableStream<Uint8Array>;
21
+ writable: WritableStream<Uint8Array>;
22
+ };
23
+ //# sourceMappingURL=streams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../src/streams.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAW,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAM5E,8BAA8B;AAC9B,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,CAgCzE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,CAmCzE;AAED,+BAA+B;AAC/B,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,GAAG;IAC/C,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IACrC,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CACtC,CAEA"}
@@ -0,0 +1,89 @@
1
+ import { resetCode, toError } from './errors.js';
2
+ /** The most a single read takes from quinn. */
3
+ const READ_CHUNK_BYTES = 64 * 1024;
4
+ /** A writable over `send`. */
5
+ export function sendWritable(send) {
6
+ let reset = false;
7
+ const resetOnce = (reason) => {
8
+ if (reset)
9
+ return;
10
+ reset = true;
11
+ void send.reset(resetCode(reason));
12
+ };
13
+ let signal;
14
+ // The abort reason, when the stream was aborted: a pending step it interrupted rejects with that, not the addon's own.
15
+ const failed = (error) => (signal?.aborted ? signal.reason : error);
16
+ return new WritableStream({
17
+ start(controller) {
18
+ signal = controller.signal;
19
+ controller.signal.addEventListener('abort', () => resetOnce(controller.signal.reason), { once: true });
20
+ void send.stopped().then((failure) => {
21
+ if (failure)
22
+ controller.error(toError(failure));
23
+ });
24
+ },
25
+ async write(chunk) {
26
+ if (!(chunk instanceof Uint8Array))
27
+ throw new TypeError('a native QUIC stream takes Uint8Array chunks');
28
+ // The addon reads the bytes off the JS thread while the write waits, so it gets a copy of its own: the caller may
29
+ // reuse, transfer or resize its buffer as soon as it likes. Not `slice()`, which a Node Buffer shares.
30
+ const failure = await send.write(new Uint8Array(chunk));
31
+ if (failure)
32
+ throw failed(toError(failure));
33
+ },
34
+ async close() {
35
+ const failure = await send.finish();
36
+ if (failure)
37
+ throw failed(toError(failure));
38
+ },
39
+ abort: resetOnce,
40
+ });
41
+ }
42
+ /**
43
+ * A readable over `recv`. It reads only on demand; between reads a native watch waits for a peer reset (TA-19) or the
44
+ * session's end (TA-12) without reading, so either settles the readable even while nothing reads it. Cancelling sends
45
+ * STOP_SENDING with the reason's code and ends the readable (TA-18).
46
+ */
47
+ export function recvReadable(recv) {
48
+ let ended = false;
49
+ const end = (controller, failure) => {
50
+ if (ended)
51
+ return;
52
+ ended = true;
53
+ if (failure)
54
+ controller.error(toError(failure));
55
+ else
56
+ controller.close();
57
+ };
58
+ const watch = (controller) => {
59
+ void recv.watch().then((failure) => {
60
+ // Bytes not yet read may be discarded on a reset (RFC 9000 §3.2).
61
+ if (failure)
62
+ end(controller, failure);
63
+ });
64
+ };
65
+ return new ReadableStream({
66
+ start: watch,
67
+ async pull(controller) {
68
+ const { chunk, fin, failure } = await recv.read(READ_CHUNK_BYTES);
69
+ if (ended)
70
+ return;
71
+ if (failure || fin) {
72
+ end(controller, failure);
73
+ return;
74
+ }
75
+ if (chunk)
76
+ controller.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
77
+ watch(controller);
78
+ },
79
+ async cancel(reason) {
80
+ ended = true;
81
+ await recv.stop(resetCode(reason));
82
+ },
83
+ }, { highWaterMark: 0 });
84
+ }
85
+ /** Both halves of `stream`. */
86
+ export function bidirectional(stream) {
87
+ return { writable: sendWritable(stream.takeSend()), readable: recvReadable(stream.takeRecv()) };
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,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YAClE,IAAI,KAAK;gBAAE,OAAO;YAClB,IAAI,OAAO,IAAI,GAAG,EAAE,CAAC;gBACnB,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;gBACzB,OAAO;YACT,CAAC;YACD,IAAI,KAAK;gBAAE,UAAU,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;YAChG,KAAK,CAAC,UAAU,CAAC,CAAC;QACpB,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,MAAM;YACjB,KAAK,GAAG,IAAI,CAAC;YACb,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QACrC,CAAC;KACF,EACD,EAAE,aAAa,EAAE,CAAC,EAAE,CACrB,CAAC;AACJ,CAAC;AAED,+BAA+B;AAC/B,MAAM,UAAU,aAAa,CAAC,MAAgB;IAI5C,OAAO,EAAE,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;AAClG,CAAC"}
@@ -0,0 +1,32 @@
1
+ /** A `MoqtTransport` over one native QUIC dial (spec/transport-adapter.md, "Session lifetime"). */
2
+ import type { BidirectionalStreamLike, MoqtSendStreamOptions, MoqtTransport } from '@caprid/moq-core';
3
+ import type { Dial } from './addon.js';
4
+ /** How `closed` resolves after an application close from either end (TA-9). */
5
+ export interface CloseInfo {
6
+ /** The application close code. */
7
+ closeCode: number;
8
+ /** The close reason. */
9
+ reason: string;
10
+ }
11
+ /** The transport for one dial. `ready` resolves once the peer selected a protocol; closing first cancels the dial. */
12
+ export declare class NativeQuicTransport implements MoqtTransport {
13
+ #private;
14
+ readonly incomingUnidirectionalStreams: ReadableStream<ReadableStream<Uint8Array>>;
15
+ readonly incomingBidirectionalStreams: ReadableStream<BidirectionalStreamLike>;
16
+ /** Resolves on an application close from either end and rejects with a session error otherwise (TA-9). */
17
+ readonly closed: Promise<CloseInfo>;
18
+ /** Resolves once the session is established (TA-7); rejects with a session error when the dial fails. */
19
+ readonly ready: Promise<void>;
20
+ constructor(dial: Dial);
21
+ /** The protocol the peer selected (TA-8); empty until `ready` resolves. */
22
+ get protocol(): string;
23
+ /** quinn schedules by stream priority, highest first, as WebTransport does by `sendOrder`. */
24
+ createUnidirectionalStream(options?: MoqtSendStreamOptions): Promise<WritableStream<Uint8Array>>;
25
+ createBidirectionalStream(): Promise<BidirectionalStreamLike>;
26
+ /** Close with an application CONNECTION_CLOSE (TA-10); before `ready`, cancel the dial instead (TA-11). */
27
+ close({ closeCode, reason }?: {
28
+ closeCode?: number;
29
+ reason?: string;
30
+ }): void;
31
+ }
32
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,OAAO,KAAK,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtG,OAAO,KAAK,EAAE,IAAI,EAAoB,MAAM,YAAY,CAAC;AAIzD,+EAA+E;AAC/E,MAAM,WAAW,SAAS;IACxB,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB;AAYD,sHAAsH;AACtH,qBAAa,mBAAoB,YAAW,aAAa;;IACvD,QAAQ,CAAC,6BAA6B,EAAE,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IACnF,QAAQ,CAAC,4BAA4B,EAAE,cAAc,CAAC,uBAAuB,CAAC,CAAC;IAC/E,0GAA0G;IAC1G,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,yGAAyG;IACzG,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;gBAOlB,IAAI,EAAE,IAAI;IAoBtB,2EAA2E;IAC3E,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,8FAA8F;IACxF,0BAA0B,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAMhG,yBAAyB,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAMnE,2GAA2G;IAC3G,KAAK,CAAC,EAAE,SAAa,EAAE,MAAW,EAAE,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,IAAI;CA4D1F"}
@@ -0,0 +1,125 @@
1
+ import { NativeQuicSessionError, safeCode, toError } from './errors.js';
2
+ import { bidirectional, recvReadable, sendWritable } from './streams.js';
3
+ function isFailure(value) {
4
+ return 'source' in value;
5
+ }
6
+ /** A send order as quinn's 32-bit stream priority: an integer, clamped to the range; anything else is no priority. */
7
+ function streamPriority(sendOrder) {
8
+ if (sendOrder === undefined || !Number.isInteger(sendOrder))
9
+ return undefined;
10
+ return Math.min(Math.max(sendOrder, -0x8000_0000), 0x7fff_ffff);
11
+ }
12
+ /** The transport for one dial. `ready` resolves once the peer selected a protocol; closing first cancels the dial. */
13
+ export class NativeQuicTransport {
14
+ incomingUnidirectionalStreams;
15
+ incomingBidirectionalStreams;
16
+ /** Resolves on an application close from either end and rejects with a session error otherwise (TA-9). */
17
+ closed;
18
+ /** Resolves once the session is established (TA-7); rejects with a session error when the dial fails. */
19
+ ready;
20
+ #dial;
21
+ #session;
22
+ #established;
23
+ #closeRequested;
24
+ constructor(dial) {
25
+ this.#dial = dial;
26
+ this.#session = dial.ready().then((result) => {
27
+ if (isFailure(result))
28
+ throw toError(result);
29
+ if (this.#closeRequested) {
30
+ // close() came while the handshake finished (TA-11): no session may outlive the cancelled dial.
31
+ result.close(this.#closeRequested.closeCode, this.#closeRequested.reason);
32
+ void result.closed();
33
+ throw cancelled();
34
+ }
35
+ this.#established = result;
36
+ return result;
37
+ });
38
+ this.#session.catch(() => { });
39
+ this.ready = this.#session.then(() => undefined);
40
+ this.closed = this.#session.then(async (session) => this.#closeInfo(await session.closed()));
41
+ this.incomingUnidirectionalStreams = this.#incoming((session) => session.acceptUni(), recvReadable);
42
+ this.incomingBidirectionalStreams = this.#incoming((session) => session.acceptBi(), bidirectional);
43
+ }
44
+ /** The protocol the peer selected (TA-8); empty until `ready` resolves. */
45
+ get protocol() {
46
+ return this.#established?.protocol ?? '';
47
+ }
48
+ /** quinn schedules by stream priority, highest first, as WebTransport does by `sendOrder`. */
49
+ async createUnidirectionalStream(options) {
50
+ const opened = (await this.#session).openUni(streamPriority(options?.sendOrder));
51
+ if (isFailure(opened))
52
+ throw toError(opened);
53
+ return sendWritable(opened);
54
+ }
55
+ async createBidirectionalStream() {
56
+ const opened = (await this.#session).openBi();
57
+ if (isFailure(opened))
58
+ throw toError(opened);
59
+ return bidirectional(opened);
60
+ }
61
+ /** Close with an application CONNECTION_CLOSE (TA-10); before `ready`, cancel the dial instead (TA-11). */
62
+ close({ closeCode = 0, reason = '' } = {}) {
63
+ if (this.#closeRequested)
64
+ return;
65
+ // An application close code is a 32-bit value, as on a WebTransport session.
66
+ const code = Number.isInteger(closeCode) && closeCode >= 0 && closeCode <= 0xffff_ffff ? closeCode : 0;
67
+ this.#closeRequested = { closeCode: code, reason };
68
+ if (this.#established)
69
+ this.#established.close(code, reason);
70
+ else
71
+ this.#dial.cancel();
72
+ }
73
+ #closeInfo(ended) {
74
+ if (ended.kind === 'local')
75
+ return this.#closeRequested ?? { closeCode: 0, reason: '' };
76
+ if (ended.kind === 'application')
77
+ return { closeCode: safeCode(ended.code) ?? 0, reason: ended.reason };
78
+ throw toError(ended);
79
+ }
80
+ /**
81
+ * Streams the peer opens. The readable closes after a clean end and errors otherwise (TA-12), when `closed` settles:
82
+ * a pending read is not needed for that.
83
+ */
84
+ #incoming(accept, wrap) {
85
+ return new ReadableStream({
86
+ start: (controller) => {
87
+ // Either throws once the readable already ended, which needs nothing more.
88
+ this.closed.then(() => {
89
+ try {
90
+ controller.close();
91
+ }
92
+ catch { }
93
+ }, (error) => {
94
+ try {
95
+ controller.error(error);
96
+ }
97
+ catch { }
98
+ });
99
+ },
100
+ pull: async (controller) => {
101
+ let session;
102
+ try {
103
+ session = await this.#session;
104
+ }
105
+ catch {
106
+ return; // `closed` rejects with the dial's failure, and `start` errors the readable with it.
107
+ }
108
+ // Nothing once the session is over: `start` ends the readable as `closed` settles.
109
+ const stream = await accept(session);
110
+ if (stream === null)
111
+ return;
112
+ try {
113
+ controller.enqueue(wrap(stream));
114
+ }
115
+ catch {
116
+ // The readable ended or was cancelled while the stream arrived; the session is going with it.
117
+ }
118
+ },
119
+ }, { highWaterMark: 0 });
120
+ }
121
+ }
122
+ function cancelled() {
123
+ return new NativeQuicSessionError('the dial was cancelled', 'cancelled');
124
+ }
125
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAUzE,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,QAAQ,IAAI,KAAK,CAAC;AAC3B,CAAC;AAED,sHAAsH;AACtH,SAAS,cAAc,CAAC,SAA6B;IACnD,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9E,OAAO,IAAI,CAAC,GAAG,CAAC,I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,IAAI,OAAgB,CAAC;gBACrB,IAAI,CAAC;oBACH,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC;gBAChC,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,CAAC,qFAAqF;gBAC/F,CAAC;gBACD,mFAAmF;gBACnF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;gBACrC,IAAI,MAAM,KAAK,IAAI;oBAAE,OAAO;gBAC5B,IAAI,CAAC;oBACH,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;gBACnC,CAAC;gBAAC,MAAM,CAAC;oBACP,8FAA8F;gBAChG,CAAC;YACH,CAAC;SACF,EACD,EAAE,aAAa,EAAE,CAAC,EAAE,CACrB,CAAC;IACJ,CAAC;CACF;AAED,SAAS,SAAS;IAChB,OAAO,IAAI,sBAAsB,CAAC,wBAAwB,EAAE,WAAW,CAAC,CAAC;AAC3E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@caprid/relay-quic",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Native QUIC transport adapter for the Relay SDK in Node",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/caprids/relay-sdks.git",
9
+ "directory": "ts/packages/relay-quic"
10
+ },
11
+ "type": "module",
12
+ "sideEffects": false,
13
+ "files": [
14
+ "dist",
15
+ "LICENSE"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "napi": {
24
+ "binaryName": "relay-quic",
25
+ "targets": [
26
+ "x86_64-unknown-linux-gnu",
27
+ "aarch64-unknown-linux-gnu",
28
+ "x86_64-unknown-linux-musl",
29
+ "aarch64-unknown-linux-musl",
30
+ "aarch64-apple-darwin",
31
+ "x86_64-apple-darwin",
32
+ "x86_64-pc-windows-msvc"
33
+ ]
34
+ },
35
+ "dependencies": {
36
+ "@caprid/moq-core": "0.1.0"
37
+ },
38
+ "devDependencies": {
39
+ "@napi-rs/cli": "3.10.5",
40
+ "@types/node": "24.12.2"
41
+ },
42
+ "engines": {
43
+ "node": ">=24"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "optionalDependencies": {
49
+ "@caprid/relay-quic-darwin-arm64": "0.1.0",
50
+ "@caprid/relay-quic-darwin-x64": "0.1.0",
51
+ "@caprid/relay-quic-linux-arm64-gnu": "0.1.0",
52
+ "@caprid/relay-quic-linux-arm64-musl": "0.1.0",
53
+ "@caprid/relay-quic-linux-x64-gnu": "0.1.0",
54
+ "@caprid/relay-quic-linux-x64-musl": "0.1.0",
55
+ "@caprid/relay-quic-win32-x64-msvc": "0.1.0"
56
+ },
57
+ "scripts": {
58
+ "build": "tsc -p tsconfig.json",
59
+ "build:native": "napi build --platform --release --manifest-path native/Cargo.toml --output-dir native --no-js --dts ../src/native.d.ts"
60
+ }
6
61
  }