@node-webrtc-rust/bindings 0.1.5 → 0.2.1

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 (3) hide show
  1. package/README.md +53 -6
  2. package/index.d.ts +1 -1
  3. package/package.json +7 -8
package/README.md CHANGED
@@ -50,15 +50,62 @@ This produces a `node-webrtc-rust.<platform>.node` file in the current directory
50
50
 
51
51
  Set `WEBRTC_DEBUG=1` (or pass `debug: true` in `JsRTCConfiguration`) to emit `[webrtc-debug]` lines from native bindings and the Rust core. See the root README for details.
52
52
 
53
- ## How it works
53
+ ## How native loading works
54
54
 
55
- The `index.js` loader resolves the native binding in this order:
55
+ The root `@node-webrtc-rust/bindings` package ships **no binary** — only `index.js`, `index.d.ts`, and loader logic. The compiled addon lives in separate platform packages listed as **`optionalDependencies`**.
56
56
 
57
- 1. Try requiring the platform-specific npm package (e.g., `@node-webrtc-rust/bindings-darwin-arm64`)
58
- 2. Try loading a local `.node` file matching the current platform (dev builds)
59
- 3. Try loading `node-webrtc-rust.node` (generic local build)
57
+ ### At `npm install`
60
58
 
61
- If none succeed, an error is thrown with instructions.
59
+ The matching platform package is **installed during `npm install`**, not downloaded when your app first runs. Runtime `require()` only loads what is already in `node_modules`.
60
+
61
+ When you install `@node-webrtc-rust/bindings`, npm:
62
+
63
+ 1. Installs the root package (loader only — no `.node`).
64
+ 2. **Attempts each `optionalDependency`** (e.g. `bindings-darwin-arm64`, `bindings-linux-x64-gnu`, …).
65
+ 3. Keeps only packages whose `"os"` / `"cpu"` fields match your machine; others are skipped.
66
+ 4. Does **not** fail the install if a non-matching or unavailable optional package is skipped — that is what “optional” means.
67
+
68
+ On macOS arm64 you typically get:
69
+
70
+ ```text
71
+ node_modules/@node-webrtc-rust/bindings/ ← loader (index.js)
72
+ node_modules/@node-webrtc-rust/bindings-darwin-arm64/
73
+ node-webrtc-rust.darwin-arm64.node ← actual native addon
74
+ ```
75
+
76
+ Each platform package is a thin wrapper: its `"main"` field points directly at the `.node` file, so `require('@node-webrtc-rust/bindings-darwin-arm64')` loads the native module.
77
+
78
+ **When the binary might be missing after install:**
79
+
80
+ | Situation | Result |
81
+ | --- | --- |
82
+ | Normal install on a supported platform | Matching optional package is present |
83
+ | `npm install --omit=optional` | No platform package — runtime fails unless a local `.node` exists |
84
+ | Unsupported OS/arch | No matching optional package |
85
+ | Publish/version mismatch for the optional pkg | Install may succeed; `require()` fails at runtime |
86
+
87
+ ### At runtime (`require('@node-webrtc-rust/bindings')`)
88
+
89
+ `index.js` (auto-generated by NAPI-RS) picks the binary for the current process:
90
+
91
+ 1. **Detect platform** — `process.platform`, `process.arch`, and on Linux whether the libc is musl or glibc (`isMusl()`).
92
+ 2. **Local dev fallback** — if `node-webrtc-rust.<platform>.node` sits next to `index.js` (from `npm run build:local`), `require` that file directly.
93
+ 3. **Published path** — otherwise `require` the matching optional package (e.g. `@node-webrtc-rust/bindings-linux-x64-gnu`).
94
+ 4. **Re-export** — bind NAPI exports (`JsPeerConnection`, `JsConferenceRoom`, …) onto `module.exports`.
95
+
96
+ If both paths fail, Node throws with the underlying `loadError`.
97
+
98
+ ```mermaid
99
+ flowchart TD
100
+ A["require('@node-webrtc-rust/bindings')"] --> B[index.js]
101
+ B --> C{platform + arch + libc?}
102
+ C --> D{local .node beside index.js?}
103
+ D -->|yes| E["require('./node-webrtc-rust.*.node')"]
104
+ D -->|no| F["require('@node-webrtc-rust/bindings-…')"]
105
+ F --> G["platform pkg main → *.node"]
106
+ E --> H[Re-export NAPI symbols]
107
+ G --> H
108
+ ```
62
109
 
63
110
  ### TypeScript note
64
111
 
package/index.d.ts CHANGED
@@ -172,7 +172,7 @@ export declare class JsLocalAudioTrack {
172
172
  get streamId(): string
173
173
  get enabled(): boolean
174
174
  set enabled(enabled: boolean)
175
- /** Writes a PCM audio frame to the track. */
175
+ /** Writes interleaved stereo PCM; encoded to the negotiated RTP codec before send. */
176
176
  writeSample(data: Buffer, durationMs: number): Promise<void>
177
177
  }
178
178
  /** WebRTC peer connection exposed to JavaScript. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-webrtc-rust/bindings",
3
- "version": "0.1.5",
3
+ "version": "0.2.1",
4
4
  "description": "NAPI-RS native bindings for node-webrtc-rust — WebRTC peer connections, data channels, and conference audio mixing",
5
5
  "keywords": [
6
6
  "webrtc",
@@ -58,13 +58,12 @@
58
58
  "@napi-rs/cli": "^2.18.0"
59
59
  },
60
60
  "optionalDependencies": {
61
- "@node-webrtc-rust/bindings-win32-x64-msvc": "0.1.5",
62
- "@node-webrtc-rust/bindings-darwin-x64": "0.1.5",
63
- "@node-webrtc-rust/bindings-linux-x64-gnu": "0.1.5",
64
- "@node-webrtc-rust/bindings-darwin-arm64": "0.1.5",
65
- "@node-webrtc-rust/bindings-linux-arm64-gnu": "0.1.5",
66
- "@node-webrtc-rust/bindings-linux-arm64-musl": "0.1.4",
67
- "@node-webrtc-rust/bindings-linux-x64-musl": "0.1.5"
61
+ "@node-webrtc-rust/bindings-darwin-arm64": "0.2.1",
62
+ "@node-webrtc-rust/bindings-darwin-x64": "0.2.1",
63
+ "@node-webrtc-rust/bindings-linux-arm64-gnu": "0.2.1",
64
+ "@node-webrtc-rust/bindings-linux-x64-gnu": "0.2.1",
65
+ "@node-webrtc-rust/bindings-linux-x64-musl": "0.2.1",
66
+ "@node-webrtc-rust/bindings-win32-x64-msvc": "0.2.1"
68
67
  },
69
68
  "engines": {
70
69
  "node": ">=18"