reactor-effect-native 0.0.0-reserved.0 → 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.
Files changed (111) hide show
  1. package/Dockerfile +38 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +28 -0
  4. package/README.md +106 -2
  5. package/dist/_internal/bridge.d.ts +49 -0
  6. package/dist/_internal/bridge.d.ts.map +1 -0
  7. package/dist/_internal/bridge.js +452 -0
  8. package/dist/_internal/bridge.js.map +1 -0
  9. package/dist/_internal/peer.d.ts +57 -0
  10. package/dist/_internal/peer.d.ts.map +1 -0
  11. package/dist/_internal/peer.js +479 -0
  12. package/dist/_internal/peer.js.map +1 -0
  13. package/dist/index.d.ts +25 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +41 -0
  16. package/dist/index.js.map +1 -0
  17. package/lib/darwin-arm64/libreactor_effect_native.dylib +0 -0
  18. package/lib/darwin-arm64/native-identity.json +18 -0
  19. package/lib/linux-x64/libreactor_effect_native.so +0 -0
  20. package/lib/linux-x64/native-identity.json +20 -0
  21. package/notices/effect-LICENSE +21 -0
  22. package/notices/native-rust/NOTICE.md +27 -0
  23. package/notices/native-rust/bytes-1.12.1-LICENSE +25 -0
  24. package/notices/native-rust/itoa-1.0.18-LICENSE-APACHE +176 -0
  25. package/notices/native-rust/memchr-2.8.3-LICENSE-MIT +21 -0
  26. package/notices/native-rust/prost-0.13.5-LICENSE +201 -0
  27. package/notices/native-rust/serde-1.0.229-LICENSE-APACHE +176 -0
  28. package/notices/native-rust/serde_json-1.0.151-LICENSE-APACHE +176 -0
  29. package/notices/native-rust/zmij-1.0.23-LICENSE-MIT +23 -0
  30. package/notices/reactor-webrtc/WebRTC-LICENSE +29 -0
  31. package/notices/reactor-webrtc/WebRTC-PATENTS +24 -0
  32. package/notices/reactor-webrtc/reactor-webrtc-linux-x64-release.sbom.json +660 -0
  33. package/notices/reactor-webrtc/reactor-webrtc-mac-arm64-release.sbom.json +631 -0
  34. package/notices/reactor-webrtc/third-party/README.md +58 -0
  35. package/notices/reactor-webrtc/third-party/abseil-cpp/LICENSE +203 -0
  36. package/notices/reactor-webrtc/third-party/abseil-cpp/README.chromium +55 -0
  37. package/notices/reactor-webrtc/third-party/boringssl/LICENSE +238 -0
  38. package/notices/reactor-webrtc/third-party/boringssl/README.chromium +15 -0
  39. package/notices/reactor-webrtc/third-party/compiler-rt/LICENSE.TXT +311 -0
  40. package/notices/reactor-webrtc/third-party/compiler-rt/README.chromium +15 -0
  41. package/notices/reactor-webrtc/third-party/cpuinfo/LICENSE +27 -0
  42. package/notices/reactor-webrtc/third-party/cpuinfo/README.chromium +15 -0
  43. package/notices/reactor-webrtc/third-party/dav1d/LICENSE +23 -0
  44. package/notices/reactor-webrtc/third-party/dav1d/README.chromium +40 -0
  45. package/notices/reactor-webrtc/third-party/farmhash/LICENSE +19 -0
  46. package/notices/reactor-webrtc/third-party/farmhash/README.chromium +21 -0
  47. package/notices/reactor-webrtc/third-party/fft2d/LICENSE +3 -0
  48. package/notices/reactor-webrtc/third-party/fft2d/README.chromium +24 -0
  49. package/notices/reactor-webrtc/third-party/flatbuffers/LICENSE +202 -0
  50. package/notices/reactor-webrtc/third-party/flatbuffers/README.chromium +18 -0
  51. package/notices/reactor-webrtc/third-party/fp16/LICENSE +12 -0
  52. package/notices/reactor-webrtc/third-party/fp16/README.chromium +16 -0
  53. package/notices/reactor-webrtc/third-party/fxdiv/LICENSE +10 -0
  54. package/notices/reactor-webrtc/third-party/fxdiv/README.chromium +16 -0
  55. package/notices/reactor-webrtc/third-party/gemmlowp/LICENSE +202 -0
  56. package/notices/reactor-webrtc/third-party/gemmlowp/README.chromium +14 -0
  57. package/notices/reactor-webrtc/third-party/grpc/LICENSE +610 -0
  58. package/notices/reactor-webrtc/third-party/grpc/README.chromium +30 -0
  59. package/notices/reactor-webrtc/third-party/jsoncpp/LICENSE +55 -0
  60. package/notices/reactor-webrtc/third-party/jsoncpp/README.chromium +20 -0
  61. package/notices/reactor-webrtc/third-party/libaom/LICENSE +27 -0
  62. package/notices/reactor-webrtc/third-party/libaom/PATENTS +108 -0
  63. package/notices/reactor-webrtc/third-party/libaom/README.chromium +61 -0
  64. package/notices/reactor-webrtc/third-party/libgav1/LICENSE +202 -0
  65. package/notices/reactor-webrtc/third-party/libgav1/README.chromium +33 -0
  66. package/notices/reactor-webrtc/third-party/libjpeg_turbo/LICENSE.md.chromium +236 -0
  67. package/notices/reactor-webrtc/third-party/libjpeg_turbo/README.chromium +66 -0
  68. package/notices/reactor-webrtc/third-party/libsrtp/LICENSE +35 -0
  69. package/notices/reactor-webrtc/third-party/libsrtp/README.chromium +17 -0
  70. package/notices/reactor-webrtc/third-party/libvpx/LICENSE +31 -0
  71. package/notices/reactor-webrtc/third-party/libvpx/PATENTS +23 -0
  72. package/notices/reactor-webrtc/third-party/libvpx/README.chromium +73 -0
  73. package/notices/reactor-webrtc/third-party/libyuv/LICENSE +29 -0
  74. package/notices/reactor-webrtc/third-party/libyuv/README.chromium +13 -0
  75. package/notices/reactor-webrtc/third-party/neon_2_sse/LICENSE +29 -0
  76. package/notices/reactor-webrtc/third-party/neon_2_sse/README.chromium +21 -0
  77. package/notices/reactor-webrtc/third-party/opus/COPYING +44 -0
  78. package/notices/reactor-webrtc/third-party/opus/README.chromium +41 -0
  79. package/notices/reactor-webrtc/third-party/perfetto/LICENSE +285 -0
  80. package/notices/reactor-webrtc/third-party/perfetto/README.chromium +12 -0
  81. package/notices/reactor-webrtc/third-party/pffft/LICENSE +45 -0
  82. package/notices/reactor-webrtc/third-party/pffft/README.chromium +43 -0
  83. package/notices/reactor-webrtc/third-party/protobuf/LICENSE +32 -0
  84. package/notices/reactor-webrtc/third-party/protobuf/README.chromium +325 -0
  85. package/notices/reactor-webrtc/third-party/pthreadpool/LICENSE +26 -0
  86. package/notices/reactor-webrtc/third-party/pthreadpool/README.chromium +19 -0
  87. package/notices/reactor-webrtc/third-party/re2/LICENSE +27 -0
  88. package/notices/reactor-webrtc/third-party/re2/README.chromium +15 -0
  89. package/notices/reactor-webrtc/third-party/rnnoise/COPYING +31 -0
  90. package/notices/reactor-webrtc/third-party/rnnoise/README.chromium +30 -0
  91. package/notices/reactor-webrtc/third-party/ruy/LICENSE +202 -0
  92. package/notices/reactor-webrtc/third-party/ruy/README.chromium +20 -0
  93. package/notices/reactor-webrtc/third-party/tflite/LICENSE +203 -0
  94. package/notices/reactor-webrtc/third-party/tflite/README.chromium +22 -0
  95. package/notices/reactor-webrtc/third-party/xnnpack/LICENSE +31 -0
  96. package/notices/reactor-webrtc/third-party/xnnpack/README.chromium +18 -0
  97. package/notices/reactor-webrtc/third-party/zlib/LICENSE +22 -0
  98. package/notices/reactor-webrtc/third-party/zlib/README.chromium +38 -0
  99. package/notices/reactor-webrtc-LICENSE +201 -0
  100. package/notices/reactor-webrtc-NOTICE.md +32 -0
  101. package/package.json +54 -4
  102. package/rust/.cargo/config.toml +5 -0
  103. package/rust/Cargo.lock +208 -0
  104. package/rust/Cargo.toml +19 -0
  105. package/rust/build.rs +159 -0
  106. package/rust/include/reactor_effect_native.h +118 -0
  107. package/rust/src/lib.rs +2343 -0
  108. package/scripts/build.sh +35 -0
  109. package/scripts/install-linux-toolchain.sh +47 -0
  110. package/scripts/stage.mjs +107 -0
  111. package/scripts/stage.sh +31 -0
package/Dockerfile ADDED
@@ -0,0 +1,38 @@
1
+ # syntax=docker/dockerfile:1.7
2
+ FROM --platform=linux/amd64 rust:1.90.0-bookworm@sha256:3914072ca0c3b8aad871db9169a651ccfce30cf58303e5d6f2db16d1d8a7e58f AS build
3
+
4
+ WORKDIR /work
5
+ COPY scripts/install-linux-toolchain.sh ./scripts/install-linux-toolchain.sh
6
+ RUN chmod 755 scripts/install-linux-toolchain.sh \
7
+ && scripts/install-linux-toolchain.sh
8
+ RUN apt-get update \
9
+ && apt-get install -y --no-install-recommends \
10
+ file \
11
+ git \
12
+ tar \
13
+ zstd \
14
+ && rm -rf /var/lib/apt/lists/*
15
+
16
+ RUN rustup component add clippy rustfmt
17
+
18
+ COPY rust/Cargo.toml rust/Cargo.lock rust/build.rs ./rust/
19
+ COPY rust/.cargo/config.toml ./rust/.cargo/config.toml
20
+ COPY rust/src ./rust/src
21
+ COPY rust/include ./rust/include
22
+
23
+ ENV CARGO_TARGET_DIR=/target \
24
+ CC=clang-21 \
25
+ CXX=clang++-21
26
+
27
+ # reactor-webrtc-sys downloads the pinned Linux x64 libwebrtc prebuilt,
28
+ # verifies its published SHA-256, and compiles its C++ glue with pinned LLVM 21.
29
+ RUN cargo fmt --manifest-path rust/Cargo.toml -- --check
30
+ RUN cargo test --locked --manifest-path rust/Cargo.toml -- --nocapture
31
+ RUN cargo clippy --locked --manifest-path rust/Cargo.toml --all-targets -- -D warnings
32
+ RUN cargo build --locked --manifest-path rust/Cargo.toml --release
33
+ RUN test "$(uname -m)" = "x86_64" \
34
+ && file /target/release/libreactor_effect_native.so \
35
+ && ldd /target/release/libreactor_effect_native.so
36
+
37
+ FROM scratch AS artifact
38
+ COPY --from=build /target/release/libreactor_effect_native.so /libreactor_effect_native.so
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Reactor Technologies, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,28 @@
1
+ reactor-effect-native
2
+
3
+ This independent SDK is not an official Reactor SDK.
4
+
5
+ The native transport is built from the Rust bridge in rust/ against:
6
+ reactor-webrtc, commit bebf63e42624ee440e066b692494dd3229d29ae7 (Apache-2.0).
7
+ It incorporates upstream Google WebRTC binaries and associated third-party code.
8
+ The pinned reactor-webrtc Apache terms are retained in
9
+ notices/reactor-webrtc-LICENSE. Exact macOS arm64 and Linux x64 prebuilt SBOMs,
10
+ plus the pinned WebRTC BSD license and patent grant, are retained under
11
+ notices/reactor-webrtc/. Component-specific third-party redistribution texts
12
+ for every component named by those SBOMs are retained under
13
+ notices/reactor-webrtc/third-party/; its README names the exact pinned source
14
+ revision and retained license/copyright or patent file for each component.
15
+ The Rust crates linked into the native bridge and their selected license texts
16
+ are recorded under notices/native-rust/.
17
+ Native builds pin and verify the upstream binary artifact checksum.
18
+ No reactor-ffi or reactor-core session implementation is included.
19
+
20
+ Protocol material, the canonical session implementation and their upstream
21
+ notices are distributed with the reactor-effect-client package this host
22
+ depends on.
23
+
24
+ Effect is MIT-licensed. The package declares Effect as a peer dependency; its
25
+ license is retained in notices/effect-LICENSE. Koffi is an optional dependency
26
+ used only by this native implementation; its installed distribution retains its
27
+ upstream license. Development tooling and node_modules are excluded from the
28
+ npm package.
package/README.md CHANGED
@@ -1,5 +1,109 @@
1
1
  # reactor-effect-native
2
2
 
3
- Namespace-only bootstrap for npm trusted publishing from [mannyc2/reactor-effect-client](https://github.com/mannyc2/reactor-effect-client).
3
+ Native WebRTC host for [`reactor-effect-client`](https://www.npmjs.com/package/reactor-effect-client). `reactor-effect-native` is a small Rust `cdylib` over the pinned `reactor-webrtc` revision, loaded through the optional [Koffi](https://koffi.dev) FFI dependency. Reactor session ownership, HTTP, command correlation, cancellation, and model policy stay in `reactor-effect-client`; this package owns transport and decoded media only.
4
4
 
5
- This package contains no SDK, executable code, scripts, or dependencies. Wait for the qualified SDK release before installing.
5
+ This is not an official Reactor SDK. Native WebRTC dependencies are attributed in [NOTICE](./NOTICE) and [`notices/`](./notices/).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install reactor-effect-client reactor-effect-native effect@4.0.0-rc.115 @effect/platform-node@4.0.0-rc.115
11
+ ```
12
+
13
+ `reactor-effect-client` and Effect `4.0.0-rc.115` are exact peer dependencies. Koffi is an optional dependency; it and the shared library are loaded only when native preflight runs, so merely importing this module remains safe when the optional dependency is absent. `@effect/platform-node` supplies the Node services an application provides around its scoped operation; a consumer using that prerelease should retain the root override `"@effect/platform-node-shared": "4.0.0-rc.115"`, because the platform's caret range otherwise permits a later prerelease with a different Effect peer.
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { Effect, Layer } from "effect";
19
+ import * as NodeServices from "@effect/platform-node/NodeServices";
20
+ import * as Reactor from "reactor-effect-client";
21
+ import * as Native from "reactor-effect-native";
22
+
23
+ const clientLayer = Reactor.layer().pipe(
24
+ Layer.provide(Layer.mergeAll(Reactor.FetchHttp.layer, NodeServices.layer, Native.layer())),
25
+ );
26
+ ```
27
+
28
+ `Native.make(configuration, nativeOptions)` constructs the canonical factory with the native peer already selected, and `Native.layer(nativeOptions)` supplies the `PeerFactory` for `Reactor.layer()`. Constructing a factory makes no allocation. `nativeOptions.libraryPath` can select a staged native artifact; its caller owns artifact provenance. The separate `Native.uploadFile` helper requires the host file services when used.
29
+
30
+ `Native.media(session)` obtains a decoded-media generation after the session connects. `media.video(name)` emits owned BGRA frames and `media.audio(name)` emits owned interleaved signed 16-bit PCM. Frame IDs and microsecond timestamps use `bigint`. Retaining a frame retains JavaScript-owned bytes, and native media has no browser track handles. Media values stay bound to their negotiated generation: a reconnect creates a new generation and existing readers end or fail with their source.
31
+
32
+ Native transport provides:
33
+
34
+ - STUN/TURN ICE configuration and offerer signaling;
35
+ - reliable ordered binary `control` and `data` channels;
36
+ - transceiver direction and sender bitrate controls;
37
+ - WebRTC statistics;
38
+ - owned decoded BGRA video with Reactor frame metadata;
39
+ - owned interleaved signed 16-bit PCM audio;
40
+ - immediate close fencing plus joined callback quiescence during shutdown.
41
+
42
+ The current public native peer accepts at most one incoming video track and one incoming audio track. Pinned `reactor-webrtc` delivers `RemoteTrack` callbacks without the transceiver MID/native identity needed to join multiple same-kind callbacks to SDP mappings without relying on arrival order. `NativePeer.prepare` therefore rejects an ambiguous declaration with `UnsupportedCapability` before native negotiation. Multiple outgoing tracks remain distinct by their declared transceivers.
43
+
44
+ ## Package layout
45
+
46
+ | Path | Contents |
47
+ | ------------------------------------ | ---------------------------------------------------------------------------------------- |
48
+ | `dist/` | The compiled TypeScript entry point and its declarations |
49
+ | `lib/<platform>-<arch>/` | The staged shared library and its `native-identity.json` sidecar for each shipped host |
50
+ | `rust/` | The `reactor-effect-native` crate: Cargo manifest and lock, build script, header, source |
51
+ | `scripts/build.sh` | Builds the crate for the current host and stages it |
52
+ | `scripts/stage.sh`, `stage.mjs` | Stage an already built library; `stage.mjs` is the single staging owner |
53
+ | `scripts/install-linux-toolchain.sh` | Explicit root-only LLVM 21 installer for opted-in Debian/Ubuntu build environments |
54
+
55
+ The bridge owns one libwebrtc peer on a Rust thread. libwebrtc callbacks copy their data into bounded Rust queues; they never invoke JavaScript. ABI 2 retains the exact packet selected by a size probe until it is copied or the queue is closed. Its bytes and item still count toward the queue limits. Producer pressure may evict other queued media; it cannot change the reader's packet.
56
+
57
+ `close()` fences new callback and host-call admission immediately. The host registers every operation before dispatching to Koffi and keeps that ownership until the foreign call actually returns, even when its Effect waiter is interrupted. `shutdown()` drains those active and queued foreign calls, joins the Rust owner and callback guards, then destroys the handle once. The C ABI requires other hosts to perform the same foreign-call drain before destruction. Joining the Rust owner alone cannot observe calls queued in a host executor.
58
+
59
+ ## Build and stage
60
+
61
+ Native code requires Rust 1.90, Clang 21 on Linux (the platform compiler on macOS), curl, tar with zstd support (or `zstd`), and a SHA-256 tool. From the workspace root:
62
+
63
+ ```sh
64
+ bun run native:build # sh packages/native/scripts/build.sh
65
+ ```
66
+
67
+ The pinned `reactor-webrtc-sys` build downloads its matching libwebrtc prebuilt and verifies the published SHA-256 before linking. macOS prebuilts target macOS 13.0 or later. The script uses the checked-in Cargo configuration and stages the result under `lib/<platform>-<arch>/`. `scripts/stage.mjs` verifies the library's embedded ABI, target, release profile and source SHA-256 against the current native build inputs, then writes the binary and `native-identity.json` with its SHA-256 and build identity. The source identity covers the Cargo manifest/lock, build script, Cargo configuration, C header and Rust source; build identity also records compiler versions and relevant build flags. A stale binary is rejected before it can be staged. `node scripts/stage.mjs --source-hash` prints the identity of the current sources; pull-request CI keys its staged-artifact cache on it (with the build recipe, toolchain and runner image) and skips the Rust build when none of them changed, while a run on `main` always builds the library it qualifies.
68
+
69
+ Native tests and normal installed-package preflight use this staged artifact. Preflight verifies the binary hash and compares its loaded build identity with the sidecar. There is no fallback to `rust/target/debug` or `release`.
70
+
71
+ Linux native builds require LLVM/Clang 21. The pinned libwebrtc prebuilt ships the matching libc++ headers, and older distro Clang releases are not a supported compiler for this native bridge. `scripts/build.sh` and `scripts/test.sh` never install system packages: on Linux they use an explicit `CC`/`CXX` when supplied, otherwise they require `clang-21` and `clang++-21` on `PATH` and fail with a toolchain-specific error if unavailable. macOS compiler selection is unchanged.
72
+
73
+ For opted-in Debian 12 (bookworm) or Ubuntu 24.04 (noble) build environments, the package includes an explicit root-only installer:
74
+
75
+ ```sh
76
+ sudo ./packages/native/scripts/install-linux-toolchain.sh
77
+ ```
78
+
79
+ The installer uses the official apt.llvm.org LLVM 21 repository, verifies the repository signing key fingerprint `6084F3CF814B57C1CF12EFD515CF4D18AF4F7421` before adding the repository, and installs only the `clang-21` toolchain package after its bootstrap HTTPS/GPG requirements. The pinned libwebrtc artifact supplies the libc++/libc++abi headers and static archives used by the glue build, so system libc++ packages are intentionally not installed. The installer does not invoke `sudo` itself and is only called explicitly by Docker/CI recipes; ordinary local build/test scripts never modify the host package set.
80
+
81
+ ## Qualification
82
+
83
+ Local qualification is credential-free:
84
+
85
+ ```sh
86
+ bun run native:test # sh packages/native/scripts/test.sh
87
+ ```
88
+
89
+ The script checks Rust formatting, runs the Rust tests and clippy with warnings denied, then runs the JavaScript ABI/parser/session-boundary tests (Node/Vitest in `packages/native/test`) against the staged artifact; it never restages a second release library. The loopback test negotiates two local peers and exercises real libwebrtc ICE/DTLS/SCTP, both binary channels, video encode/decode, PCM audio, per-frame metadata, stream stats, direction changes, bitrate controls, and callback quiescence. It does not contact Reactor or generate paid media.
90
+
91
+ Additional tests force differently sized media eviction between the size probe and copying calls, and block foreign calls while interrupting their Effect waiters. The lifetime fixture drains queued calls while one active call remains held, verifies that shutdown/destruction have not run, then releases the final call and verifies one destruction. Its tombstone reports unsafe ordering without intentionally dereferencing freed memory. These checks establish ownership and ordering; they do not claim an observed heap-corruption incident.
92
+
93
+ `scripts/stage.sh` stages an already-built shared library under the package runtime layout, `lib/<platform>-<arch>/`. For example:
94
+
95
+ ```sh
96
+ ./packages/native/scripts/stage.sh packages/native/rust/target/release/libreactor_effect_native.dylib darwin-arm64
97
+ ```
98
+
99
+ Linux x64 has a reproducible container build that starts from the package source, installs Rust 1.90 plus the package-owned LLVM 21 recipe and auxiliary archive tools, runs the native Rust tests and clippy, and exports only the resulting shared library. It requires an explicit Docker context so the script never changes the caller's active context:
100
+
101
+ ```sh
102
+ DOCKER_CONTEXT=default bun run native:linux-x64
103
+ ```
104
+
105
+ That stages `lib/linux-x64/libreactor_effect_native.so`. The final runtime image only needs the packaged shared object and its normal glibc system dependencies; Cargo, clang and the libwebrtc archive are build-time inputs.
106
+
107
+ ## License
108
+
109
+ Apache-2.0. See [NOTICE](./NOTICE) and [`notices/`](./notices/).
@@ -0,0 +1,49 @@
1
+ export declare const NativeCall: Readonly<{
2
+ readonly Prepare: 1;
3
+ readonly Answer: 2;
4
+ readonly Direction: 3;
5
+ readonly MaxBitrate: 4;
6
+ readonly Stats: 5;
7
+ readonly MediaSnapshot: 6;
8
+ }>;
9
+ export type NativeCall = (typeof NativeCall)[keyof typeof NativeCall];
10
+ export declare const resolveNativeBridge: (path?: string) => Promise<string>;
11
+ export declare const checkNativeBridge: (path?: string) => Promise<void>;
12
+ /** Validate the staged artifact used by both source and installed-package tests. */
13
+ export declare const verifyStagedNativeBridge: (path: string) => Promise<Readonly<Record<string, unknown>>>;
14
+ export interface NativePacket {
15
+ readonly header: Readonly<Record<string, unknown>>;
16
+ readonly payload: Uint8Array<ArrayBuffer>;
17
+ }
18
+ export type NativePoll = {
19
+ readonly _tag: "Packet";
20
+ readonly packet: NativePacket;
21
+ } | {
22
+ readonly _tag: "Again";
23
+ } | {
24
+ readonly _tag: "Closed";
25
+ };
26
+ export declare class NativeBridge {
27
+ private readonly api;
28
+ private handle;
29
+ private closed;
30
+ private readonly active;
31
+ private readonly readers;
32
+ private requestBytes;
33
+ private shutdownTask;
34
+ constructor(path: string);
35
+ private require;
36
+ private withHandle;
37
+ call(operation: NativeCall, request?: Uint8Array): Promise<unknown>;
38
+ send(channel: "control" | "data", bytes: Uint8Array): Promise<void>;
39
+ private poll;
40
+ pollEvent(timeoutMs?: number): Promise<NativePoll>;
41
+ pollVideo(timeoutMs?: number): Promise<NativePoll>;
42
+ pollAudio(timeoutMs?: number): Promise<NativePoll>;
43
+ close(): void;
44
+ shutdown(): Promise<void>;
45
+ private finishShutdown;
46
+ }
47
+ export declare const encodeNativeJson: (value: unknown) => Uint8Array<ArrayBuffer>;
48
+ export declare const encodeNativeText: (value: string) => Uint8Array<ArrayBuffer>;
49
+ //# sourceMappingURL=bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/_internal/bridge.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,UAAU;sBACZ,CAAC;qBACF,CAAC;wBACE,CAAC;yBACA,CAAC;oBACN,CAAC;4BACO,CAAC;EACP,CAAC;AAEZ,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AA+JtE,eAAO,MAAM,mBAAmB,UAAiB,MAAM,KAAG,OAAO,CAAC,MAAM,CAmBvE,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAiB,MAAM,KAAG,OAAO,CAAC,IAAI,CAEnE,CAAC;AAkCF,oFAAoF;AACpF,eAAO,MAAM,wBAAwB,SAC7B,MAAM,KACX,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAgD3C,CAAC;AAuBF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;CAC3C;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAchC,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAY;IAChC,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IACnD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;IAC1D,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,YAAY,CAA4B;IAChD,YAAY,IAAI,EAAE,MAAM,EAQvB;IAED,OAAO,CAAC,OAAO;YAQD,UAAU;IA4BlB,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,GAAE,UAA6B,GAAG,OAAO,CAAC,OAAO,CAAC,CAqC1F;IAEK,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAgCxE;YAEa,IAAI;IA0DlB,SAAS,CAAC,SAAS,SAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAE9C;IACD,SAAS,CAAC,SAAS,SAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAE9C;IACD,SAAS,CAAC,SAAS,SAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAE9C;IAED,KAAK,IAAI,IAAI,CAKZ;IAED,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAOxB;YAEa,cAAc;CA4B7B;AAED,eAAO,MAAM,gBAAgB,UAAW,OAAO,KAAG,UAAU,CAAC,WAAW,CACN,CAAC;AACnE,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,UAAU,CAAC,WAAW,CACrB,CAAC"}