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/rust/build.rs ADDED
@@ -0,0 +1,159 @@
1
+ use std::env;
2
+ use std::fs;
3
+ use std::io::Write;
4
+ use std::path::{Path, PathBuf};
5
+ use std::process::{Command, Stdio};
6
+
7
+ fn source_files(root: &Path, directory: &Path, files: &mut Vec<String>) {
8
+ for entry in fs::read_dir(directory).expect("native source directory must exist") {
9
+ let path = entry.expect("read native source entry").path();
10
+ if path.is_dir() {
11
+ source_files(root, &path, files);
12
+ } else if path.is_file() {
13
+ files.push(
14
+ path.strip_prefix(root)
15
+ .unwrap()
16
+ .to_str()
17
+ .unwrap()
18
+ .replace('\\', "/"),
19
+ );
20
+ }
21
+ }
22
+ }
23
+
24
+ fn quote(value: &str) -> String {
25
+ let mut out = String::from("\"");
26
+ for ch in value.chars() {
27
+ match ch {
28
+ '"' => out.push_str("\\\""),
29
+ '\\' => out.push_str("\\\\"),
30
+ '\n' => out.push_str("\\n"),
31
+ '\r' => out.push_str("\\r"),
32
+ '\t' => out.push_str("\\t"),
33
+ ch if ch.is_control() => out.push_str(&format!("\\u{:04x}", ch as u32)),
34
+ ch => out.push(ch),
35
+ }
36
+ }
37
+ out.push('"');
38
+ out
39
+ }
40
+
41
+ fn version(program: &str) -> String {
42
+ let output = Command::new(program)
43
+ .arg("--version")
44
+ .output()
45
+ .unwrap_or_else(|_| panic!("could not inspect native build tool {program}"));
46
+ assert!(
47
+ output.status.success(),
48
+ "native build tool {program} failed"
49
+ );
50
+ String::from_utf8(output.stdout)
51
+ .expect("build tool version must be UTF-8")
52
+ .lines()
53
+ .next()
54
+ .unwrap_or("")
55
+ .to_owned()
56
+ }
57
+
58
+ fn build_identity() {
59
+ let root = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
60
+ let mut files = [
61
+ "Cargo.toml",
62
+ "Cargo.lock",
63
+ "build.rs",
64
+ ".cargo/config.toml",
65
+ "include/reactor_effect_native.h",
66
+ ]
67
+ .map(str::to_owned)
68
+ .to_vec();
69
+ source_files(&root, &root.join("src"), &mut files);
70
+ files.sort();
71
+ let mut input = Vec::new();
72
+ for file in files {
73
+ println!("cargo:rerun-if-changed={file}");
74
+ input.extend_from_slice(file.as_bytes());
75
+ input.push(0);
76
+ input.extend_from_slice(&fs::read(root.join(file)).expect("read native build input"));
77
+ input.push(0);
78
+ }
79
+ let mut command = if cfg!(target_os = "macos") {
80
+ let mut command = Command::new("shasum");
81
+ command.args(["-a", "256"]);
82
+ command
83
+ } else {
84
+ Command::new("sha256sum")
85
+ };
86
+ let mut child = command
87
+ .stdin(Stdio::piped())
88
+ .stdout(Stdio::piped())
89
+ .spawn()
90
+ .expect("a SHA-256 tool is required to identify native build inputs");
91
+ child
92
+ .stdin
93
+ .take()
94
+ .unwrap()
95
+ .write_all(&input)
96
+ .expect("hash native build inputs");
97
+ let output = child.wait_with_output().expect("join native source hash");
98
+ assert!(output.status.success(), "native source hash failed");
99
+ let text = String::from_utf8(output.stdout).unwrap();
100
+ let digest = text.split_whitespace().next().unwrap();
101
+ assert!(digest.len() == 64 && digest.chars().all(|ch| ch.is_ascii_hexdigit()));
102
+
103
+ let cc = env::var("CC").unwrap_or_else(|_| "clang".into());
104
+ let cxx = env::var("CXX").unwrap_or_else(|_| "clang++".into());
105
+ let mut fields = vec![
106
+ "\"schemaVersion\":1".to_owned(),
107
+ "\"abiVersion\":2".to_owned(),
108
+ format!("\"sourceSha256\":{}", quote(digest)),
109
+ format!("\"target\":{}", quote(&env::var("TARGET").unwrap())),
110
+ format!("\"profile\":{}", quote(&env::var("PROFILE").unwrap())),
111
+ format!("\"rustc\":{}", quote(&version(&env::var("RUSTC").unwrap()))),
112
+ format!("\"cc\":{}", quote(&version(&cc))),
113
+ format!("\"cxx\":{}", quote(&version(&cxx))),
114
+ ];
115
+ for key in [
116
+ "CC",
117
+ "CXX",
118
+ "CARGO_ENCODED_RUSTFLAGS",
119
+ "CFLAGS",
120
+ "CXXFLAGS",
121
+ "MACOSX_DEPLOYMENT_TARGET",
122
+ ] {
123
+ println!("cargo:rerun-if-env-changed={key}");
124
+ if let Ok(value) = env::var(key) {
125
+ fields.push(format!("{}:{}", quote(key), quote(&value)));
126
+ }
127
+ }
128
+ println!(
129
+ "cargo:rustc-env=REACTOR_EFFECT_BUILD_IDENTITY={{{}}}",
130
+ fields.join(",")
131
+ );
132
+ }
133
+
134
+ fn main() {
135
+ build_identity();
136
+ if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("macos") {
137
+ return;
138
+ }
139
+
140
+ // The pinned Reactor libwebrtc archive contains ScreenCaptureKit objects
141
+ // produced by Clang. They reference compiler-rt's deployment-version helper,
142
+ // which rustc's macOS link line does not add on its own.
143
+ let cc = env::var("CC").unwrap_or_else(|_| "clang".to_owned());
144
+ let output = Command::new(cc)
145
+ .arg("-print-resource-dir")
146
+ .output()
147
+ .expect("clang is required to link the Reactor libwebrtc archive on macOS");
148
+ assert!(output.status.success(), "clang -print-resource-dir failed");
149
+ let resource = String::from_utf8(output.stdout).expect("clang resource path is not UTF-8");
150
+ let directory = PathBuf::from(resource.trim()).join("lib/darwin");
151
+ let runtime = directory.join("libclang_rt.osx.a");
152
+ assert!(
153
+ runtime.is_file(),
154
+ "missing macOS compiler-rt archive at {}",
155
+ runtime.display()
156
+ );
157
+ println!("cargo:rustc-link-search=native={}", directory.display());
158
+ println!("cargo:rustc-link-lib=static=clang_rt.osx");
159
+ }
@@ -0,0 +1,118 @@
1
+ #ifndef REACTOR_EFFECT_NATIVE_H
2
+ #define REACTOR_EFFECT_NATIVE_H
3
+
4
+ #include <stddef.h>
5
+ #include <stdint.h>
6
+
7
+ #ifdef __cplusplus
8
+ extern "C" {
9
+ #endif
10
+
11
+ typedef struct ReactorEffectPeer ReactorEffectPeer;
12
+
13
+ enum ReactorEffectStatus {
14
+ REACTOR_EFFECT_OK = 0,
15
+ REACTOR_EFFECT_AGAIN = 1,
16
+ REACTOR_EFFECT_BUFFER_TOO_SMALL = 2,
17
+ REACTOR_EFFECT_CLOSED = 3,
18
+ REACTOR_EFFECT_INVALID = -1,
19
+ REACTOR_EFFECT_NATIVE = -2,
20
+ REACTOR_EFFECT_OVERFLOW = -3
21
+ };
22
+
23
+ enum ReactorEffectCall {
24
+ REACTOR_EFFECT_PREPARE = 1,
25
+ REACTOR_EFFECT_ANSWER = 2,
26
+ REACTOR_EFFECT_DIRECTION = 3,
27
+ REACTOR_EFFECT_MAX_BITRATE = 4,
28
+ REACTOR_EFFECT_STATS = 5,
29
+ REACTOR_EFFECT_MEDIA_SNAPSHOT = 6
30
+ };
31
+
32
+ enum ReactorEffectChannel {
33
+ REACTOR_EFFECT_CONTROL = 0,
34
+ REACTOR_EFFECT_DATA = 1
35
+ };
36
+
37
+ uint32_t reactor_effect_abi_version(void);
38
+ /* Static source/build identity of this loaded image; never free the pointer. */
39
+ const char *reactor_effect_build_identity(void);
40
+
41
+ ReactorEffectPeer *reactor_effect_peer_create(void);
42
+
43
+ /*
44
+ * request is UTF-8. The response is UTF-8 JSON on both success and failure.
45
+ * Calls are serialized by the native peer owner and may block on libwebrtc.
46
+ */
47
+ int reactor_effect_peer_call(
48
+ ReactorEffectPeer *peer,
49
+ uint32_t operation,
50
+ const uint8_t *request,
51
+ size_t request_len,
52
+ uint8_t *response,
53
+ size_t response_cap,
54
+ size_t *response_len);
55
+
56
+ int reactor_effect_peer_send(
57
+ ReactorEffectPeer *peer,
58
+ uint32_t channel,
59
+ const uint8_t *data,
60
+ size_t data_len,
61
+ uint8_t *error,
62
+ size_t error_cap,
63
+ size_t *error_len);
64
+
65
+ /*
66
+ * Poll packets are [u32 little-endian header length][UTF-8 JSON header][payload].
67
+ * A zero-capacity call returns BUFFER_TOO_SMALL with the required packet size and
68
+ * retains that exact packet until copy or close. Retained packets count toward
69
+ * item and byte bounds and cannot be evicted by producer pressure. Each queue
70
+ * permits one reader across probe/copy; the host must serialize that pair.
71
+ * timeout_ms == 0 is a nonblocking poll.
72
+ */
73
+ int reactor_effect_peer_poll_event(
74
+ ReactorEffectPeer *peer,
75
+ uint32_t timeout_ms,
76
+ uint8_t *out,
77
+ size_t out_cap,
78
+ size_t *out_len);
79
+
80
+ int reactor_effect_peer_poll_video(
81
+ ReactorEffectPeer *peer,
82
+ uint32_t timeout_ms,
83
+ uint8_t *out,
84
+ size_t out_cap,
85
+ size_t *out_len);
86
+
87
+ int reactor_effect_peer_poll_audio(
88
+ ReactorEffectPeer *peer,
89
+ uint32_t timeout_ms,
90
+ uint8_t *out,
91
+ size_t out_cap,
92
+ size_t *out_len);
93
+
94
+ /* Immediate admission fence. No callback/event can be admitted after return. */
95
+ void reactor_effect_peer_close(ReactorEffectPeer *peer);
96
+
97
+ /*
98
+ * Drops channels/tracks/PeerConnection on the owner thread, waits for all native
99
+ * callback guards to leave, then joins that owner. Safe to call more than once.
100
+ */
101
+ int reactor_effect_peer_shutdown(
102
+ ReactorEffectPeer *peer,
103
+ uint8_t *error,
104
+ size_t error_cap,
105
+ size_t *error_len);
106
+
107
+ /*
108
+ * Performs shutdown if needed, then frees the opaque handle. The host must
109
+ * first join EVERY foreign call using this handle, including work still queued
110
+ * in its FFI executor. Native owner shutdown alone does not establish that.
111
+ */
112
+ void reactor_effect_peer_destroy(ReactorEffectPeer *peer);
113
+
114
+ #ifdef __cplusplus
115
+ }
116
+ #endif
117
+
118
+ #endif