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.
- package/Dockerfile +38 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +106 -2
- package/dist/_internal/bridge.d.ts +49 -0
- package/dist/_internal/bridge.d.ts.map +1 -0
- package/dist/_internal/bridge.js +452 -0
- package/dist/_internal/bridge.js.map +1 -0
- package/dist/_internal/peer.d.ts +57 -0
- package/dist/_internal/peer.d.ts.map +1 -0
- package/dist/_internal/peer.js +479 -0
- package/dist/_internal/peer.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/lib/darwin-arm64/libreactor_effect_native.dylib +0 -0
- package/lib/darwin-arm64/native-identity.json +18 -0
- package/lib/linux-x64/libreactor_effect_native.so +0 -0
- package/lib/linux-x64/native-identity.json +20 -0
- package/notices/effect-LICENSE +21 -0
- package/notices/native-rust/NOTICE.md +27 -0
- package/notices/native-rust/bytes-1.12.1-LICENSE +25 -0
- package/notices/native-rust/itoa-1.0.18-LICENSE-APACHE +176 -0
- package/notices/native-rust/memchr-2.8.3-LICENSE-MIT +21 -0
- package/notices/native-rust/prost-0.13.5-LICENSE +201 -0
- package/notices/native-rust/serde-1.0.229-LICENSE-APACHE +176 -0
- package/notices/native-rust/serde_json-1.0.151-LICENSE-APACHE +176 -0
- package/notices/native-rust/zmij-1.0.23-LICENSE-MIT +23 -0
- package/notices/reactor-webrtc/WebRTC-LICENSE +29 -0
- package/notices/reactor-webrtc/WebRTC-PATENTS +24 -0
- package/notices/reactor-webrtc/reactor-webrtc-linux-x64-release.sbom.json +660 -0
- package/notices/reactor-webrtc/reactor-webrtc-mac-arm64-release.sbom.json +631 -0
- package/notices/reactor-webrtc/third-party/README.md +58 -0
- package/notices/reactor-webrtc/third-party/abseil-cpp/LICENSE +203 -0
- package/notices/reactor-webrtc/third-party/abseil-cpp/README.chromium +55 -0
- package/notices/reactor-webrtc/third-party/boringssl/LICENSE +238 -0
- package/notices/reactor-webrtc/third-party/boringssl/README.chromium +15 -0
- package/notices/reactor-webrtc/third-party/compiler-rt/LICENSE.TXT +311 -0
- package/notices/reactor-webrtc/third-party/compiler-rt/README.chromium +15 -0
- package/notices/reactor-webrtc/third-party/cpuinfo/LICENSE +27 -0
- package/notices/reactor-webrtc/third-party/cpuinfo/README.chromium +15 -0
- package/notices/reactor-webrtc/third-party/dav1d/LICENSE +23 -0
- package/notices/reactor-webrtc/third-party/dav1d/README.chromium +40 -0
- package/notices/reactor-webrtc/third-party/farmhash/LICENSE +19 -0
- package/notices/reactor-webrtc/third-party/farmhash/README.chromium +21 -0
- package/notices/reactor-webrtc/third-party/fft2d/LICENSE +3 -0
- package/notices/reactor-webrtc/third-party/fft2d/README.chromium +24 -0
- package/notices/reactor-webrtc/third-party/flatbuffers/LICENSE +202 -0
- package/notices/reactor-webrtc/third-party/flatbuffers/README.chromium +18 -0
- package/notices/reactor-webrtc/third-party/fp16/LICENSE +12 -0
- package/notices/reactor-webrtc/third-party/fp16/README.chromium +16 -0
- package/notices/reactor-webrtc/third-party/fxdiv/LICENSE +10 -0
- package/notices/reactor-webrtc/third-party/fxdiv/README.chromium +16 -0
- package/notices/reactor-webrtc/third-party/gemmlowp/LICENSE +202 -0
- package/notices/reactor-webrtc/third-party/gemmlowp/README.chromium +14 -0
- package/notices/reactor-webrtc/third-party/grpc/LICENSE +610 -0
- package/notices/reactor-webrtc/third-party/grpc/README.chromium +30 -0
- package/notices/reactor-webrtc/third-party/jsoncpp/LICENSE +55 -0
- package/notices/reactor-webrtc/third-party/jsoncpp/README.chromium +20 -0
- package/notices/reactor-webrtc/third-party/libaom/LICENSE +27 -0
- package/notices/reactor-webrtc/third-party/libaom/PATENTS +108 -0
- package/notices/reactor-webrtc/third-party/libaom/README.chromium +61 -0
- package/notices/reactor-webrtc/third-party/libgav1/LICENSE +202 -0
- package/notices/reactor-webrtc/third-party/libgav1/README.chromium +33 -0
- package/notices/reactor-webrtc/third-party/libjpeg_turbo/LICENSE.md.chromium +236 -0
- package/notices/reactor-webrtc/third-party/libjpeg_turbo/README.chromium +66 -0
- package/notices/reactor-webrtc/third-party/libsrtp/LICENSE +35 -0
- package/notices/reactor-webrtc/third-party/libsrtp/README.chromium +17 -0
- package/notices/reactor-webrtc/third-party/libvpx/LICENSE +31 -0
- package/notices/reactor-webrtc/third-party/libvpx/PATENTS +23 -0
- package/notices/reactor-webrtc/third-party/libvpx/README.chromium +73 -0
- package/notices/reactor-webrtc/third-party/libyuv/LICENSE +29 -0
- package/notices/reactor-webrtc/third-party/libyuv/README.chromium +13 -0
- package/notices/reactor-webrtc/third-party/neon_2_sse/LICENSE +29 -0
- package/notices/reactor-webrtc/third-party/neon_2_sse/README.chromium +21 -0
- package/notices/reactor-webrtc/third-party/opus/COPYING +44 -0
- package/notices/reactor-webrtc/third-party/opus/README.chromium +41 -0
- package/notices/reactor-webrtc/third-party/perfetto/LICENSE +285 -0
- package/notices/reactor-webrtc/third-party/perfetto/README.chromium +12 -0
- package/notices/reactor-webrtc/third-party/pffft/LICENSE +45 -0
- package/notices/reactor-webrtc/third-party/pffft/README.chromium +43 -0
- package/notices/reactor-webrtc/third-party/protobuf/LICENSE +32 -0
- package/notices/reactor-webrtc/third-party/protobuf/README.chromium +325 -0
- package/notices/reactor-webrtc/third-party/pthreadpool/LICENSE +26 -0
- package/notices/reactor-webrtc/third-party/pthreadpool/README.chromium +19 -0
- package/notices/reactor-webrtc/third-party/re2/LICENSE +27 -0
- package/notices/reactor-webrtc/third-party/re2/README.chromium +15 -0
- package/notices/reactor-webrtc/third-party/rnnoise/COPYING +31 -0
- package/notices/reactor-webrtc/third-party/rnnoise/README.chromium +30 -0
- package/notices/reactor-webrtc/third-party/ruy/LICENSE +202 -0
- package/notices/reactor-webrtc/third-party/ruy/README.chromium +20 -0
- package/notices/reactor-webrtc/third-party/tflite/LICENSE +203 -0
- package/notices/reactor-webrtc/third-party/tflite/README.chromium +22 -0
- package/notices/reactor-webrtc/third-party/xnnpack/LICENSE +31 -0
- package/notices/reactor-webrtc/third-party/xnnpack/README.chromium +18 -0
- package/notices/reactor-webrtc/third-party/zlib/LICENSE +22 -0
- package/notices/reactor-webrtc/third-party/zlib/README.chromium +38 -0
- package/notices/reactor-webrtc-LICENSE +201 -0
- package/notices/reactor-webrtc-NOTICE.md +32 -0
- package/package.json +54 -4
- package/rust/.cargo/config.toml +5 -0
- package/rust/Cargo.lock +208 -0
- package/rust/Cargo.toml +19 -0
- package/rust/build.rs +159 -0
- package/rust/include/reactor_effect_native.h +118 -0
- package/rust/src/lib.rs +2343 -0
- package/scripts/build.sh +35 -0
- package/scripts/install-linux-toolchain.sh +47 -0
- package/scripts/stage.mjs +107 -0
- package/scripts/stage.sh +31 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import { ReactorError, ErrorCode } from "reactor-effect-client";
|
|
9
|
+
const ABI_VERSION = 2;
|
|
10
|
+
const CALL_BUFFER_BYTES = 4 * 1024 * 1024;
|
|
11
|
+
const ERROR_BUFFER_BYTES = 4096;
|
|
12
|
+
const MAX_PACKET_BYTES = 96 * 1024 * 1024;
|
|
13
|
+
const MAX_IN_FLIGHT_CALLS = 128;
|
|
14
|
+
const MAX_IN_FLIGHT_REQUEST_BYTES = 16 * 1024 * 1024;
|
|
15
|
+
const MAX_REQUEST_BYTES = 1024 * 1024;
|
|
16
|
+
const MAX_MESSAGE_BYTES = 262_144;
|
|
17
|
+
const STATUS_OK = 0;
|
|
18
|
+
const STATUS_AGAIN = 1;
|
|
19
|
+
const STATUS_BUFFER_TOO_SMALL = 2;
|
|
20
|
+
const STATUS_CLOSED = 3;
|
|
21
|
+
export const NativeCall = Object.freeze({
|
|
22
|
+
Prepare: 1,
|
|
23
|
+
Answer: 2,
|
|
24
|
+
Direction: 3,
|
|
25
|
+
MaxBitrate: 4,
|
|
26
|
+
Stats: 5,
|
|
27
|
+
MediaSnapshot: 6,
|
|
28
|
+
});
|
|
29
|
+
const APIs = new Map();
|
|
30
|
+
const libraryName = () => {
|
|
31
|
+
switch (process.platform) {
|
|
32
|
+
case "darwin":
|
|
33
|
+
return "libreactor_effect_native.dylib";
|
|
34
|
+
case "win32":
|
|
35
|
+
return "reactor_effect_native.dll";
|
|
36
|
+
default:
|
|
37
|
+
return "libreactor_effect_native.so";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const defaultPaths = () => {
|
|
41
|
+
const name = libraryName();
|
|
42
|
+
const platform = `${process.platform}-${process.arch}`;
|
|
43
|
+
// The staged library lives beside the package's compiled and source trees:
|
|
44
|
+
// lib/<platform>-<arch>/ resolves identically from dist/ and from src/.
|
|
45
|
+
return [fileURLToPath(new URL(`../../lib/${platform}/${name}`, import.meta.url))];
|
|
46
|
+
};
|
|
47
|
+
const asAsync = (value, symbol) => {
|
|
48
|
+
if (typeof value !== "function" || !("async" in value)) {
|
|
49
|
+
throw new ReactorError("Native", `native library symbol ${symbol} does not support asynchronous calls`);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
};
|
|
53
|
+
const importKoffi = async () => {
|
|
54
|
+
try {
|
|
55
|
+
const module = await import("koffi");
|
|
56
|
+
return module.default;
|
|
57
|
+
}
|
|
58
|
+
catch (cause) {
|
|
59
|
+
throw new ReactorError("UnsupportedHost", "the native export requires the optional koffi dependency", { detail: cause, outcome: "not-submitted" });
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const loadAt = async (path) => {
|
|
63
|
+
const cached = APIs.get(path);
|
|
64
|
+
if (cached !== undefined)
|
|
65
|
+
return cached;
|
|
66
|
+
const koffi = await importKoffi();
|
|
67
|
+
let library;
|
|
68
|
+
let binarySha256;
|
|
69
|
+
try {
|
|
70
|
+
binarySha256 = createHash("sha256")
|
|
71
|
+
.update(await readFile(path))
|
|
72
|
+
.digest("hex");
|
|
73
|
+
library = koffi.load(path);
|
|
74
|
+
}
|
|
75
|
+
catch (cause) {
|
|
76
|
+
throw new ReactorError("Native", `could not load native WebRTC bridge at ${path}`, {
|
|
77
|
+
detail: cause,
|
|
78
|
+
outcome: "not-submitted",
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const symbol = (prototype) => {
|
|
82
|
+
try {
|
|
83
|
+
return library.func(prototype);
|
|
84
|
+
}
|
|
85
|
+
catch (cause) {
|
|
86
|
+
throw new ReactorError("Native", `native WebRTC bridge is incompatible: missing ${prototype.split("(")[0] ?? prototype}`, { detail: cause, outcome: "not-submitted" });
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const abi = symbol("uint32_t reactor_effect_abi_version(void)");
|
|
90
|
+
const actual = abi();
|
|
91
|
+
if (actual !== ABI_VERSION)
|
|
92
|
+
throw new ReactorError("Native", `native WebRTC ABI mismatch: expected ${ABI_VERSION}, received ${actual}`, { outcome: "not-submitted" });
|
|
93
|
+
const api = {
|
|
94
|
+
library,
|
|
95
|
+
binarySha256,
|
|
96
|
+
buildIdentity: symbol("const char *reactor_effect_build_identity(void)")(),
|
|
97
|
+
create: symbol("void *reactor_effect_peer_create(void)"),
|
|
98
|
+
call: asAsync(symbol("int reactor_effect_peer_call(void *peer, uint32_t operation, const uint8_t *request, size_t request_len, _Out_ uint8_t *response, size_t response_cap, _Out_ size_t *response_len)"), "reactor_effect_peer_call"),
|
|
99
|
+
send: asAsync(symbol("int reactor_effect_peer_send(void *peer, uint32_t channel, const uint8_t *data, size_t data_len, _Out_ uint8_t *error, size_t error_cap, _Out_ size_t *error_len)"), "reactor_effect_peer_send"),
|
|
100
|
+
pollEvent: asAsync(symbol("int reactor_effect_peer_poll_event(void *peer, uint32_t timeout_ms, _Out_ uint8_t *out, size_t out_cap, _Out_ size_t *out_len)"), "reactor_effect_peer_poll_event"),
|
|
101
|
+
pollVideo: asAsync(symbol("int reactor_effect_peer_poll_video(void *peer, uint32_t timeout_ms, _Out_ uint8_t *out, size_t out_cap, _Out_ size_t *out_len)"), "reactor_effect_peer_poll_video"),
|
|
102
|
+
pollAudio: asAsync(symbol("int reactor_effect_peer_poll_audio(void *peer, uint32_t timeout_ms, _Out_ uint8_t *out, size_t out_cap, _Out_ size_t *out_len)"), "reactor_effect_peer_poll_audio"),
|
|
103
|
+
close: symbol("void reactor_effect_peer_close(void *peer)"),
|
|
104
|
+
shutdown: asAsync(symbol("int reactor_effect_peer_shutdown(void *peer, _Out_ uint8_t *error, size_t error_cap, _Out_ size_t *error_len)"), "reactor_effect_peer_shutdown"),
|
|
105
|
+
destroy: symbol("void reactor_effect_peer_destroy(void *peer)"),
|
|
106
|
+
};
|
|
107
|
+
APIs.set(path, api);
|
|
108
|
+
return api;
|
|
109
|
+
};
|
|
110
|
+
export const resolveNativeBridge = async (path) => {
|
|
111
|
+
if (path !== undefined) {
|
|
112
|
+
await loadAt(path);
|
|
113
|
+
return path;
|
|
114
|
+
}
|
|
115
|
+
const failures = [];
|
|
116
|
+
for (const candidate of defaultPaths()) {
|
|
117
|
+
try {
|
|
118
|
+
await verifyStagedNativeBridge(candidate);
|
|
119
|
+
return candidate;
|
|
120
|
+
}
|
|
121
|
+
catch (cause) {
|
|
122
|
+
failures.push(cause instanceof Error ? cause.message : String(cause));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
throw new ReactorError("Native", "native WebRTC bridge is not staged or its identity is invalid; run bun run native:build or provide an explicit library path", { detail: failures, outcome: "not-submitted" });
|
|
126
|
+
};
|
|
127
|
+
export const checkNativeBridge = async (path) => {
|
|
128
|
+
await resolveNativeBridge(path);
|
|
129
|
+
};
|
|
130
|
+
const checked = (path) => {
|
|
131
|
+
const api = APIs.get(path);
|
|
132
|
+
if (api === undefined)
|
|
133
|
+
throw new ReactorError("InvalidState", "native WebRTC bridge was not preflighted; run PeerFactory.check before make", { outcome: "not-submitted" });
|
|
134
|
+
return api;
|
|
135
|
+
};
|
|
136
|
+
const toNumber = (value, name) => {
|
|
137
|
+
const number = typeof value === "bigint" ? Number(value) : value;
|
|
138
|
+
if (typeof number !== "number" || !Number.isSafeInteger(number) || number < 0)
|
|
139
|
+
throw new ReactorError("Protocol", `native ${name} is outside the safe integer range`);
|
|
140
|
+
return number;
|
|
141
|
+
};
|
|
142
|
+
const jsonRecord = (bytes, operation) => {
|
|
143
|
+
let value;
|
|
144
|
+
try {
|
|
145
|
+
value = JSON.parse(new TextDecoder().decode(bytes));
|
|
146
|
+
}
|
|
147
|
+
catch (cause) {
|
|
148
|
+
throw new ReactorError("Protocol", `native ${operation} returned invalid JSON`, {
|
|
149
|
+
detail: cause,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
153
|
+
throw new ReactorError("Protocol", `native ${operation} returned a non-object response`);
|
|
154
|
+
return value;
|
|
155
|
+
};
|
|
156
|
+
/** Validate the staged artifact used by both source and installed-package tests. */
|
|
157
|
+
export const verifyStagedNativeBridge = async (path) => {
|
|
158
|
+
try {
|
|
159
|
+
const [manifestBytes, binary] = await Promise.all([
|
|
160
|
+
readFile(join(dirname(path), "native-identity.json")),
|
|
161
|
+
readFile(path),
|
|
162
|
+
]);
|
|
163
|
+
const manifest = jsonRecord(manifestBytes, "artifact identity");
|
|
164
|
+
if (manifest.schemaVersion !== 1 ||
|
|
165
|
+
manifest.platform !== `${process.platform}-${process.arch}` ||
|
|
166
|
+
manifest.library !== libraryName() ||
|
|
167
|
+
manifest.sha256 !== createHash("sha256").update(binary).digest("hex")) {
|
|
168
|
+
throw new ReactorError("Native", "native artifact does not match its staged identity");
|
|
169
|
+
}
|
|
170
|
+
const api = await loadAt(path);
|
|
171
|
+
if (api.binarySha256 !== manifest.sha256) {
|
|
172
|
+
throw new ReactorError("Native", "staged native artifact changed after this process loaded it");
|
|
173
|
+
}
|
|
174
|
+
const prefix = "reactor-effect-native:build-identity:", suffix = ":end";
|
|
175
|
+
if (!api.buildIdentity.startsWith(prefix) || !api.buildIdentity.endsWith(suffix)) {
|
|
176
|
+
throw new ReactorError("Native", "loaded native artifact omitted its source/build identity");
|
|
177
|
+
}
|
|
178
|
+
const build = jsonRecord(Buffer.from(api.buildIdentity.slice(prefix.length, -suffix.length)), "build identity");
|
|
179
|
+
if (build.abiVersion !== ABI_VERSION ||
|
|
180
|
+
build.profile !== "release" ||
|
|
181
|
+
JSON.stringify(build) !== JSON.stringify(manifest.build)) {
|
|
182
|
+
throw new ReactorError("Native", "loaded native build identity differs from its staged artifact");
|
|
183
|
+
}
|
|
184
|
+
return Object.freeze(manifest);
|
|
185
|
+
}
|
|
186
|
+
catch (cause) {
|
|
187
|
+
throw new ReactorError("Native", "native staged artifact verification failed", {
|
|
188
|
+
detail: cause,
|
|
189
|
+
outcome: "not-submitted",
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const isErrorCode = Schema.is(ErrorCode);
|
|
194
|
+
const operationError = (status, bytes, operation) => {
|
|
195
|
+
const response = bytes.length === 0 ? {} : jsonRecord(bytes, operation);
|
|
196
|
+
const rawCode = typeof response.code === "string" ? response.code : undefined;
|
|
197
|
+
const code = isErrorCode(rawCode) ? rawCode : status === STATUS_CLOSED ? "Closed" : "Native";
|
|
198
|
+
// A native status/code does not establish whether a side effect executed.
|
|
199
|
+
// Keep backend messages for explicit inspection rather than diagnostics: a
|
|
200
|
+
// libwebrtc error can contain peer SDP or caller-supplied signaling material.
|
|
201
|
+
return new ReactorError(code, `native ${operation} failed (${code})`, {
|
|
202
|
+
operation,
|
|
203
|
+
outcome: "unknown",
|
|
204
|
+
detail: response,
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
const asyncStatus = (fn, args) => new Promise((resolve, reject) => {
|
|
208
|
+
fn.async(...args, (error, result) => (error == null ? resolve(result) : reject(error)));
|
|
209
|
+
});
|
|
210
|
+
const parsePacket = (bytes) => {
|
|
211
|
+
if (bytes.length < 4)
|
|
212
|
+
throw new ReactorError("Protocol", "native packet omitted its header length");
|
|
213
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
214
|
+
const headerLength = view.getUint32(0, true);
|
|
215
|
+
if (headerLength > bytes.length - 4)
|
|
216
|
+
throw new ReactorError("Protocol", "native packet header length exceeds packet size");
|
|
217
|
+
const header = jsonRecord(bytes.subarray(4, 4 + headerLength), "packet");
|
|
218
|
+
const payload = Uint8Array.from(bytes.subarray(4 + headerLength));
|
|
219
|
+
return { header: Object.freeze(header), payload };
|
|
220
|
+
};
|
|
221
|
+
export class NativeBridge {
|
|
222
|
+
api;
|
|
223
|
+
handle;
|
|
224
|
+
closed = false;
|
|
225
|
+
active = new Set();
|
|
226
|
+
readers = new Set();
|
|
227
|
+
requestBytes = 0;
|
|
228
|
+
shutdownTask;
|
|
229
|
+
constructor(path) {
|
|
230
|
+
this.api = checked(path);
|
|
231
|
+
const handle = this.api.create();
|
|
232
|
+
if (handle === null)
|
|
233
|
+
throw new ReactorError("Native", "native WebRTC peer allocation failed", {
|
|
234
|
+
outcome: "not-submitted",
|
|
235
|
+
});
|
|
236
|
+
this.handle = handle;
|
|
237
|
+
}
|
|
238
|
+
require() {
|
|
239
|
+
if (this.closed || this.handle === undefined)
|
|
240
|
+
throw new ReactorError("Closed", "native WebRTC peer is closed", {
|
|
241
|
+
outcome: "not-submitted",
|
|
242
|
+
});
|
|
243
|
+
return this.handle;
|
|
244
|
+
}
|
|
245
|
+
async withHandle(bytes, body) {
|
|
246
|
+
const handle = this.require();
|
|
247
|
+
if (this.active.size >= MAX_IN_FLIGHT_CALLS ||
|
|
248
|
+
this.requestBytes + bytes > MAX_IN_FLIGHT_REQUEST_BYTES) {
|
|
249
|
+
throw new ReactorError("Overflow", "native foreign-call admission bound exceeded", {
|
|
250
|
+
outcome: "not-submitted",
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
let release;
|
|
254
|
+
const lease = new Promise((resolve) => {
|
|
255
|
+
release = resolve;
|
|
256
|
+
});
|
|
257
|
+
// Register before dispatching to Koffi. Effect interruption may abandon the
|
|
258
|
+
// waiter, but the lease belongs to actual native completion, including time
|
|
259
|
+
// spent queued on Koffi's executor and both halves of a packet poll.
|
|
260
|
+
this.active.add(lease);
|
|
261
|
+
this.requestBytes += bytes;
|
|
262
|
+
try {
|
|
263
|
+
return await body(handle);
|
|
264
|
+
}
|
|
265
|
+
finally {
|
|
266
|
+
this.requestBytes -= bytes;
|
|
267
|
+
this.active.delete(lease);
|
|
268
|
+
release();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async call(operation, request = new Uint8Array()) {
|
|
272
|
+
if (request.byteLength > MAX_REQUEST_BYTES)
|
|
273
|
+
throw new ReactorError("Overflow", "native request exceeds 1 MiB", {
|
|
274
|
+
outcome: "not-submitted",
|
|
275
|
+
});
|
|
276
|
+
return this.withHandle(CALL_BUFFER_BYTES + request.byteLength, async (handle) => {
|
|
277
|
+
const response = Buffer.allocUnsafe(CALL_BUFFER_BYTES), responseLength = [0];
|
|
278
|
+
const input = Buffer.from(request);
|
|
279
|
+
let status;
|
|
280
|
+
try {
|
|
281
|
+
status = await asyncStatus(this.api.call, [
|
|
282
|
+
handle,
|
|
283
|
+
operation,
|
|
284
|
+
input,
|
|
285
|
+
input.byteLength,
|
|
286
|
+
response,
|
|
287
|
+
response.byteLength,
|
|
288
|
+
responseLength,
|
|
289
|
+
]);
|
|
290
|
+
}
|
|
291
|
+
catch (cause) {
|
|
292
|
+
throw new ReactorError("Native", "native WebRTC call completion failed", {
|
|
293
|
+
detail: cause,
|
|
294
|
+
outcome: "unknown",
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
const length = toNumber(responseLength[0], "call response length");
|
|
298
|
+
if (length > response.byteLength)
|
|
299
|
+
throw new ReactorError("Protocol", "native call response exceeded its declared buffer");
|
|
300
|
+
const bytes = Uint8Array.from(response.subarray(0, length));
|
|
301
|
+
if (status !== STATUS_OK)
|
|
302
|
+
throw operationError(status, bytes, `call:${operation}`);
|
|
303
|
+
try {
|
|
304
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
305
|
+
}
|
|
306
|
+
catch (cause) {
|
|
307
|
+
throw new ReactorError("Protocol", "native call returned invalid JSON", { detail: cause });
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
async send(channel, bytes) {
|
|
312
|
+
if (bytes.byteLength > MAX_MESSAGE_BYTES)
|
|
313
|
+
throw new ReactorError("Overflow", "native data channel message exceeds 262144 bytes", {
|
|
314
|
+
outcome: "not-submitted",
|
|
315
|
+
});
|
|
316
|
+
return this.withHandle(ERROR_BUFFER_BYTES + bytes.byteLength, async (handle) => {
|
|
317
|
+
const error = Buffer.allocUnsafe(ERROR_BUFFER_BYTES), errorLength = [0];
|
|
318
|
+
const input = Buffer.from(bytes);
|
|
319
|
+
let status;
|
|
320
|
+
try {
|
|
321
|
+
status = await asyncStatus(this.api.send, [
|
|
322
|
+
handle,
|
|
323
|
+
channel === "control" ? 0 : 1,
|
|
324
|
+
input,
|
|
325
|
+
input.byteLength,
|
|
326
|
+
error,
|
|
327
|
+
error.byteLength,
|
|
328
|
+
errorLength,
|
|
329
|
+
]);
|
|
330
|
+
}
|
|
331
|
+
catch (cause) {
|
|
332
|
+
throw new ReactorError("Native", `native ${channel} send completion failed`, {
|
|
333
|
+
detail: cause,
|
|
334
|
+
outcome: "unknown",
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
const length = toNumber(errorLength[0], "send error length");
|
|
338
|
+
if (length > error.byteLength)
|
|
339
|
+
throw new ReactorError("Protocol", "native send error exceeded its declared buffer");
|
|
340
|
+
if (status !== STATUS_OK)
|
|
341
|
+
throw operationError(status, Uint8Array.from(error.subarray(0, length)), `send:${channel}`);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
async poll(fn, timeoutMs) {
|
|
345
|
+
if (this.closed)
|
|
346
|
+
return { _tag: "Closed" };
|
|
347
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0 || timeoutMs > 0xffffffff) {
|
|
348
|
+
throw new ReactorError("InvalidInput", "native poll timeout must be an unsigned 32-bit integer", { outcome: "not-submitted" });
|
|
349
|
+
}
|
|
350
|
+
if (this.readers.has(fn))
|
|
351
|
+
throw new ReactorError("AlreadyReading", "native packet queue already has a reader", {
|
|
352
|
+
outcome: "not-submitted",
|
|
353
|
+
});
|
|
354
|
+
this.readers.add(fn);
|
|
355
|
+
try {
|
|
356
|
+
return await this.withHandle(0, async (handle) => {
|
|
357
|
+
const needed = [0];
|
|
358
|
+
let status;
|
|
359
|
+
try {
|
|
360
|
+
status = await asyncStatus(fn, [handle, timeoutMs, null, 0, needed]);
|
|
361
|
+
}
|
|
362
|
+
catch (cause) {
|
|
363
|
+
throw new ReactorError("Native", "native event poll could not execute", {
|
|
364
|
+
detail: cause,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
if (this.closed)
|
|
368
|
+
return { _tag: "Closed" };
|
|
369
|
+
if (status === STATUS_AGAIN)
|
|
370
|
+
return { _tag: "Again" };
|
|
371
|
+
if (status === STATUS_CLOSED)
|
|
372
|
+
return { _tag: "Closed" };
|
|
373
|
+
if (status !== STATUS_BUFFER_TOO_SMALL)
|
|
374
|
+
throw new ReactorError("Native", `native event poll failed with status ${status}`);
|
|
375
|
+
const length = toNumber(needed[0], "packet length");
|
|
376
|
+
if (length < 4 || length > MAX_PACKET_BYTES)
|
|
377
|
+
throw new ReactorError("Overflow", `native packet size ${length} exceeds the local bound`);
|
|
378
|
+
const output = Buffer.allocUnsafe(length), actual = [0];
|
|
379
|
+
try {
|
|
380
|
+
status = await asyncStatus(fn, [handle, 0, output, output.byteLength, actual]);
|
|
381
|
+
}
|
|
382
|
+
catch (cause) {
|
|
383
|
+
throw new ReactorError("Native", "native packet copy could not execute", {
|
|
384
|
+
detail: cause,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
if (this.closed || status === STATUS_CLOSED)
|
|
388
|
+
return { _tag: "Closed" };
|
|
389
|
+
if (status !== STATUS_OK)
|
|
390
|
+
throw new ReactorError("Native", `native packet copy failed with status ${status}`);
|
|
391
|
+
const actualLength = toNumber(actual[0], "copied packet length");
|
|
392
|
+
if (actualLength !== length)
|
|
393
|
+
throw new ReactorError("Protocol", "native packet changed between size and copy polls");
|
|
394
|
+
return { _tag: "Packet", packet: parsePacket(Uint8Array.from(output)) };
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
finally {
|
|
398
|
+
this.readers.delete(fn);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
pollEvent(timeoutMs = 100) {
|
|
402
|
+
return this.poll(this.api.pollEvent, timeoutMs);
|
|
403
|
+
}
|
|
404
|
+
pollVideo(timeoutMs = 100) {
|
|
405
|
+
return this.poll(this.api.pollVideo, timeoutMs);
|
|
406
|
+
}
|
|
407
|
+
pollAudio(timeoutMs = 100) {
|
|
408
|
+
return this.poll(this.api.pollAudio, timeoutMs);
|
|
409
|
+
}
|
|
410
|
+
close() {
|
|
411
|
+
if (this.closed)
|
|
412
|
+
return;
|
|
413
|
+
this.closed = true;
|
|
414
|
+
const handle = this.handle;
|
|
415
|
+
if (handle !== undefined)
|
|
416
|
+
this.api.close(handle);
|
|
417
|
+
}
|
|
418
|
+
shutdown() {
|
|
419
|
+
if (this.shutdownTask !== undefined)
|
|
420
|
+
return this.shutdownTask;
|
|
421
|
+
const handle = this.handle;
|
|
422
|
+
if (handle === undefined)
|
|
423
|
+
return Promise.resolve();
|
|
424
|
+
this.close();
|
|
425
|
+
this.shutdownTask = this.finishShutdown(handle);
|
|
426
|
+
return this.shutdownTask;
|
|
427
|
+
}
|
|
428
|
+
async finishShutdown(handle) {
|
|
429
|
+
// close() fences new host admission and wakes native polls. Drain all host
|
|
430
|
+
// foreign calls before joining and destroying the native owner. A native
|
|
431
|
+
// owner join cannot see work that is still queued in Koffi.
|
|
432
|
+
await Promise.all(this.active);
|
|
433
|
+
const error = Buffer.allocUnsafe(ERROR_BUFFER_BYTES), errorLength = [0];
|
|
434
|
+
let status;
|
|
435
|
+
try {
|
|
436
|
+
status = await asyncStatus(this.api.shutdown, [handle, error, error.byteLength, errorLength]);
|
|
437
|
+
}
|
|
438
|
+
catch (cause) {
|
|
439
|
+
throw new ReactorError("Shutdown", "native WebRTC owner join could not execute; handle retained", { detail: cause });
|
|
440
|
+
}
|
|
441
|
+
const length = toNumber(errorLength[0], "shutdown error length");
|
|
442
|
+
if (length > error.byteLength)
|
|
443
|
+
throw new ReactorError("Shutdown", "native shutdown error exceeded its declared buffer");
|
|
444
|
+
if (status !== STATUS_OK)
|
|
445
|
+
throw new ReactorError("Shutdown", operationError(status, Uint8Array.from(error.subarray(0, length)), "shutdown").message);
|
|
446
|
+
this.api.destroy(handle);
|
|
447
|
+
this.handle = undefined;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
export const encodeNativeJson = (value) => Uint8Array.from(new TextEncoder().encode(JSON.stringify(value)));
|
|
451
|
+
export const encodeNativeText = (value) => Uint8Array.from(new TextEncoder().encode(value));
|
|
452
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/_internal/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,OAAO,MAAM,cA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MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,OAAO,CACvF,CAAC;QACJ,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAA2B,EAAE,CAC1E,UAAU,CAAC,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAA2B,EAAE,CACzE,UAAU,CAAC,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import type * as Scope from "effect/Scope";
|
|
3
|
+
import { ReactorError } from "reactor-effect-client";
|
|
4
|
+
import type { Track } from "reactor-effect-client";
|
|
5
|
+
import type { AudioFrame, Channel, IceServer, MediaPressure, MediaTrack, Peer, PeerEvent, Prepared, RawMedia, VideoFrame } from "reactor-effect-client/host";
|
|
6
|
+
import { type NativePacket } from "./bridge.js";
|
|
7
|
+
declare const validateNativeTracks: (tracks: readonly Track[]) => void;
|
|
8
|
+
declare const parsePrepared: (value: unknown) => Prepared;
|
|
9
|
+
declare const parseEvent: (packet: NativePacket) => PeerEvent;
|
|
10
|
+
declare const parseVideo: (packet: NativePacket) => VideoFrame;
|
|
11
|
+
declare const parseAudio: (packet: NativePacket) => AudioFrame;
|
|
12
|
+
declare const parseSnapshot: (value: unknown) => MediaPressure;
|
|
13
|
+
declare const statsValue: (value: unknown) => unknown;
|
|
14
|
+
export declare class NativePeer implements Peer {
|
|
15
|
+
readonly nativeTracks = false;
|
|
16
|
+
readonly rawMedia: RawMedia;
|
|
17
|
+
private readonly bridge;
|
|
18
|
+
private readonly video;
|
|
19
|
+
private readonly audio;
|
|
20
|
+
private readonly incoming;
|
|
21
|
+
private emit;
|
|
22
|
+
private closed;
|
|
23
|
+
private failureEmitted;
|
|
24
|
+
private failure;
|
|
25
|
+
constructor(libraryPath: string);
|
|
26
|
+
private requireIncoming;
|
|
27
|
+
private videoFeed;
|
|
28
|
+
private audioFeed;
|
|
29
|
+
private fail;
|
|
30
|
+
private pumpEvents;
|
|
31
|
+
private pumpVideo;
|
|
32
|
+
private pumpAudio;
|
|
33
|
+
prepare(servers: readonly IceServer[], tracks: readonly Track[], emit: (event: PeerEvent) => void): Effect.Effect<Prepared, ReactorError, Scope.Scope>;
|
|
34
|
+
answer(sdp: string): Effect.Effect<void, ReactorError>;
|
|
35
|
+
send(channel: Channel, bytes: Uint8Array<ArrayBuffer>): Effect.Effect<void, ReactorError>;
|
|
36
|
+
direction(name: string, active: boolean): Effect.Effect<void, ReactorError>;
|
|
37
|
+
maxBitrate(name: string, bitsPerSecond: number): Effect.Effect<void, ReactorError>;
|
|
38
|
+
stats(): Effect.Effect<readonly unknown[], ReactorError>;
|
|
39
|
+
private mediaSnapshot;
|
|
40
|
+
lease(): MediaTrack;
|
|
41
|
+
release(): void;
|
|
42
|
+
replace(): Effect.Effect<void, ReactorError>;
|
|
43
|
+
close(): void;
|
|
44
|
+
shutdown(): Effect.Effect<void, ReactorError>;
|
|
45
|
+
}
|
|
46
|
+
/** Internal test surface. This module is not a package export. */
|
|
47
|
+
export declare const nativePeerTesting: Readonly<{
|
|
48
|
+
parsePrepared: typeof parsePrepared;
|
|
49
|
+
parseEvent: typeof parseEvent;
|
|
50
|
+
parseVideo: typeof parseVideo;
|
|
51
|
+
parseAudio: typeof parseAudio;
|
|
52
|
+
parseSnapshot: typeof parseSnapshot;
|
|
53
|
+
statsValue: typeof statsValue;
|
|
54
|
+
validateNativeTracks: typeof validateNativeTracks;
|
|
55
|
+
}>;
|
|
56
|
+
export {};
|
|
57
|
+
//#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