grandi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +402 -0
- package/binding.gyp +200 -0
- package/lib/.clang-format +297 -0
- package/lib/grandi.cc +96 -0
- package/lib/grandi_find.cc +365 -0
- package/lib/grandi_find.h +41 -0
- package/lib/grandi_receive.cc +1155 -0
- package/lib/grandi_receive.h +63 -0
- package/lib/grandi_routing.cc +460 -0
- package/lib/grandi_routing.h +37 -0
- package/lib/grandi_send.cc +960 -0
- package/lib/grandi_send.h +45 -0
- package/lib/grandi_util.cc +323 -0
- package/lib/grandi_util.h +137 -0
- package/package.json +84 -0
- package/prebuilds/darwin-arm64/grandi.node +0 -0
- package/prebuilds/darwin-arm64/libndi.dylib +0 -0
- package/prebuilds/darwin-x64/grandi.node +0 -0
- package/prebuilds/darwin-x64/libndi.dylib +0 -0
- package/prebuilds/linux-arm/grandi.node +0 -0
- package/prebuilds/linux-arm/libndi.so.6 +0 -0
- package/prebuilds/linux-arm64/grandi.node +0 -0
- package/prebuilds/linux-arm64/libndi.so.6 +0 -0
- package/prebuilds/linux-ia32/grandi.node +0 -0
- package/prebuilds/linux-ia32/libndi.so.6 +0 -0
- package/prebuilds/linux-x64/grandi.node +0 -0
- package/prebuilds/linux-x64/libndi.so.6 +0 -0
- package/prebuilds/win32-ia32/Processing.NDI.Lib.x86.dll +0 -0
- package/prebuilds/win32-ia32/grandi.node +0 -0
- package/prebuilds/win32-x64/Processing.NDI.Lib.x64.dll +0 -0
- package/prebuilds/win32-x64/grandi.node +0 -0
- package/scripts/preinstall.mjs +429 -0
- package/src/index.ts +141 -0
- package/src/node-gyp-build.d.ts +5 -0
- package/src/types.ts +228 -0
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 [yyyy] [name of copyright owner]
|
|
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,21 @@
|
|
|
1
|
+
Grandi
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Grandi contributors
|
|
4
|
+
|
|
5
|
+
This product includes software developed by Streampunk Media Ltd. and is
|
|
6
|
+
derived in part from the project "Grandiose":
|
|
7
|
+
https://github.com/Streampunk/grandiose
|
|
8
|
+
licensed under the Apache License, Version 2.0.
|
|
9
|
+
|
|
10
|
+
Portions Copyright (c) 2018 Streampunk Media Ltd.
|
|
11
|
+
|
|
12
|
+
This project also retains and extends features originating from community forks,
|
|
13
|
+
including (but not limited to):
|
|
14
|
+
- https://github.com/rse/grandiose
|
|
15
|
+
- https://github.com/danjenkins/grandiose
|
|
16
|
+
- https://github.com/ianshade/grandiose
|
|
17
|
+
These upstream materials are used under the terms of the Apache License, Version 2.0.
|
|
18
|
+
|
|
19
|
+
NDI is a trademark of NewTek, Inc. NewTek NDI SDK headers/libraries are subject
|
|
20
|
+
to their respective licenses as provided by NewTek (see the repository's
|
|
21
|
+
license exceptions and the contents of the ndi/lib/ folder).
|
package/README.md
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
# Grandi
|
|
2
|
+
Grandi is a TypeScript-first native Node.js binding for NewTek NDI™ 6. It exposes the full NDI 6 SDK surface area through a Promise-based API, providing strongly typed helpers for sending and receiving professional video, audio, metadata, and tally data from Node.js applications. For more information on NDI™ , see <https://www.ndi.tv/>.
|
|
3
|
+
|
|
4
|
+
## Why this fork?
|
|
5
|
+
Grandi is a maintained fork of [Streampunk Grandiose](https://github.com/Streampunk/grandiose). The original `steampunk/grandiose` repository and the corresponding `grandiose` package on npm have not been updated since 2023, and major functionality such as data sending never landed upstream. This fork modernizes the build, rewrites the bindings in TypeScript, and delivers the outstanding features required for production projects while keeping a familiar API. Meaningful contributions were also carried forward from community forks:
|
|
6
|
+
|
|
7
|
+
- TypeScript-focused rewrite with complete binding coverage.
|
|
8
|
+
- Improved NDI SDK handling (versioning, download/packaging, and portability improvements).
|
|
9
|
+
- Added utilities to make common workflows easier.
|
|
10
|
+
- Audio frame sending support from the [rse/grandiose](https://github.com/rse/grandiose) fork.
|
|
11
|
+
- Ad-hoc download of NDI SDK assets.
|
|
12
|
+
- Portability fixes for Windows, macOS, and Linux drawn from multiple forks.
|
|
13
|
+
- Sender, routing, and type-definition improvements from [ianshade/grandiose](https://github.com/ianshade/grandiose) and [hopejr/grandiose](https://github.com/hopejr/grandiose).
|
|
14
|
+
|
|
15
|
+
## Why “Grandi”?
|
|
16
|
+
|
|
17
|
+
NDI™ was conceived as a grand vision for IP media transport. The earliest bindings leaned into that idea with the tongue‑in‑cheek name “gra‑NDI‑ose”. **Grandi** preserves the homage: it nods to “[grandiose](https://github.com/Streampunk/grandiose)”, itself drawn from the French word *grandi* (“grown”).
|
|
18
|
+
|
|
19
|
+
## Capabilities
|
|
20
|
+
- Native NDI™ 6 bindings written in modern TypeScript with out-of-the-box type definitions.
|
|
21
|
+
- Send and receive video, audio, metadata, and tally (program/preview) data streams.
|
|
22
|
+
- Promise-based API that keeps heavy lifting off the Node.js event loop.
|
|
23
|
+
- Helpers for working with choice of color formats, bandwidth limits, and audio layouts.
|
|
24
|
+
- Finder utilities for discovering sources on the local network or specified subnets.
|
|
25
|
+
- Built-in routing helpers for switching NDI sources without dropping frames.
|
|
26
|
+
|
|
27
|
+
### Missing & future work
|
|
28
|
+
- PTZ camera control APIs introduced in newer NDI SDK releases are not exposed yet.
|
|
29
|
+
- NDI receiver discovery (added in SDK v6.2) still needs bindings; today only sender discovery is available.
|
|
30
|
+
- Pull requests tackling these gaps (or other NDI 6.x+ features) are very welcome.
|
|
31
|
+
|
|
32
|
+
## Supported platforms
|
|
33
|
+
Grandi currently ships prebuilt binaries for the same platforms supported by the original project. Additional platforms can be compiled from source if the NDI SDK supports them.
|
|
34
|
+
|
|
35
|
+
| Operating system | Architectures | Status | Notes |
|
|
36
|
+
| --- | --- | --- | --- |
|
|
37
|
+
| Windows | x86, x64 | ✅ Prebuilt | Visual Studio 2013 C runtime only needed when building locally; prebuilt binaries include the required DLLs. |
|
|
38
|
+
| macOS | Universal (x64 + arm64) | ✅ Prebuilt | Ships with the official universal NDI™ driver, so Intel and Apple Silicon hosts run natively. |
|
|
39
|
+
| Linux | x86, x64, armv7l, arm64 | ✅ Prebuilt | Built against the glibc-based NDI™ SDK; requires `libavahi-common.so.3`, `libavahi-client.so.3`, and the `avahi-daemon` service. |
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
Install [Node.js](http://nodejs.org/) for your platform (tested against the current Long Term Support release). Then add the dependency to your project:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install grandi
|
|
46
|
+
# or
|
|
47
|
+
pnpm add grandi
|
|
48
|
+
# or
|
|
49
|
+
yarn add grandi
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
On Windows, you only need the Visual Studio 2013 C run-times when building from source (e.g., running `npm install` without matching prebuilds). You can grab them from <https://www.microsoft.com/en-us/download/details.aspx?id=40784>, but end users consuming the published prebuilt binaries do **not** need to install them.
|
|
53
|
+
|
|
54
|
+
Grandi is designed to be `require`d or `import`ed from your own applications:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import grandi from "grandi";
|
|
58
|
+
// or
|
|
59
|
+
const grandi = require("grandi");
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Build & distribution
|
|
63
|
+
The project uses [prebuildify](https://github.com/prebuild/prebuildify) to prebuild the Node.js addon and bundle the NDI SDK libraries for the supported targets shown above. Those prebuilds are resolved at runtime via [node-gyp-build](https://github.com/prebuild/node-gyp-build), so consumers do not need a compiler toolchain in most cases. When no prebuild matches the running platform, `node-gyp-build` falls back to compiling locally, letting advanced users add additional architectures.
|
|
64
|
+
|
|
65
|
+
## Using Grandi
|
|
66
|
+
This module allows a Node.js program to find, receive, and send NDI™ video, audio, metadata, and tally streams over IP networks. All calls are asynchronous and use JavaScript promises with all of the underlying work of NDI running on separate threads from the event loop. The following sections recap the most common workflows; for complete runnable demos, see `examples/simple-receiver.mjs` and `examples/simple-sender.mjs`.
|
|
67
|
+
|
|
68
|
+
### Finding streams
|
|
69
|
+
`grandi.find` resolves to a finder handle that can block for network updates and expose the discovered sources:
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
73
|
+
import grandi from "grandi";
|
|
74
|
+
|
|
75
|
+
async function pickSource() {
|
|
76
|
+
const finder = await grandi.find({ showLocalSources: true });
|
|
77
|
+
try {
|
|
78
|
+
for (let attempts = 0; attempts < 20; attempts++) {
|
|
79
|
+
finder.wait(250); // block for up to 250 ms of new announcements
|
|
80
|
+
const sources = finder.sources();
|
|
81
|
+
if (sources.length > 0) return sources[0];
|
|
82
|
+
await sleep(250);
|
|
83
|
+
}
|
|
84
|
+
throw new Error("No NDI sources found on the network.");
|
|
85
|
+
} finally {
|
|
86
|
+
finder.destroy();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`find` accepts a single options object. Common filters:
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
await grandi.find({
|
|
95
|
+
showLocalSources: true, // include sources on the same machine
|
|
96
|
+
groups: "studio3", // comma-separated list of group names
|
|
97
|
+
extraIPs: "192.168.1.122,mixer.local", // comma-separated IPs/hosts outside mDNS
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Receiving streams
|
|
102
|
+
First, find a stream or construct a `Source` object:
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
const grandi = require("grandi");
|
|
106
|
+
const source = { name: "<source_name>", urlAddress: "<ip>:<port>" };
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Create a receiver:
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
const receiver = await grandi.receive({ source });
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Example receiver object:
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
{
|
|
119
|
+
embedded: [External],
|
|
120
|
+
video: [Function],
|
|
121
|
+
audio: [Function],
|
|
122
|
+
metadata: [Function],
|
|
123
|
+
data: [Function],
|
|
124
|
+
source: { name: "LEMARR (Test Pattern)", urlAddress: "169.254.82.1:5961" },
|
|
125
|
+
colorFormat: 100, // grandi.COLOR_FORMAT_FASTEST
|
|
126
|
+
bandwidth: 100, // grandi.BANDWIDTH_HIGHEST
|
|
127
|
+
allowVideoFields: true
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Configure receivers via options:
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
const receiver = await grandi.receive({
|
|
135
|
+
source,
|
|
136
|
+
colorFormat: grandi.COLOR_FORMAT_UYVY_RGBA,
|
|
137
|
+
bandwidth: grandi.BANDWIDTH_AUDIO_ONLY,
|
|
138
|
+
allowVideoFields: true,
|
|
139
|
+
name: "rooftop"
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### Video
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
const timeout = 5000;
|
|
148
|
+
try {
|
|
149
|
+
for (let i = 0; i < 10; i++) {
|
|
150
|
+
const frame = await receiver.video(timeout);
|
|
151
|
+
console.log(frame);
|
|
152
|
+
}
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.error(err);
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Example frame:
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
{
|
|
162
|
+
type: "video",
|
|
163
|
+
xres: 1920,
|
|
164
|
+
yres: 1080,
|
|
165
|
+
frameRateN: 30000,
|
|
166
|
+
frameRateD: 1001,
|
|
167
|
+
pictureAspectRatio: 1.7777777910232544,
|
|
168
|
+
timestamp: [1538569443, 717845600],
|
|
169
|
+
frameFormatType: grandi.FORMAT_TYPE_INTERLACED,
|
|
170
|
+
timecode: [0, 0],
|
|
171
|
+
lineStrideBytes: 3840,
|
|
172
|
+
data: <Buffer 80 10 80 10 ... >
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### Audio
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
const audioFrame = await receiver.audio(
|
|
180
|
+
{
|
|
181
|
+
audioFormat: grandi.AUDIO_FORMAT_INT_16_INTERLEAVED,
|
|
182
|
+
referenceLevel: 0
|
|
183
|
+
},
|
|
184
|
+
8000
|
|
185
|
+
);
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Example result:
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
{
|
|
192
|
+
type: "audio",
|
|
193
|
+
audioFormat: grandi.AUDIO_FORMAT_INT_16_INTERLEAVED,
|
|
194
|
+
referenceLevel: 0,
|
|
195
|
+
sampleRate: 48000,
|
|
196
|
+
channels: 4,
|
|
197
|
+
samples: 4800,
|
|
198
|
+
channelStrideInBytes: 9600,
|
|
199
|
+
timestamp: [1538578787, 132614500],
|
|
200
|
+
timecode: [0, 800000000],
|
|
201
|
+
data: <Buffer 00 00 00 00 ... >
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### Metadata
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
const metadataFrame = await receiver.metadata();
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Returns a `{ type: "metadata", data: string, ... }` frame, typically XML.
|
|
212
|
+
|
|
213
|
+
#### Next available data
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
const prefs = { audioFormat: grandi.AUDIO_FORMAT_FLOAT_32_SEPARATE };
|
|
217
|
+
const payload = await receiver.data(prefs, 1000); // 1s timeout
|
|
218
|
+
if (payload.type === "video") {
|
|
219
|
+
// handle video frame
|
|
220
|
+
} else if (payload.type === "metadata") {
|
|
221
|
+
console.log(payload.data);
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Sending streams
|
|
226
|
+
Sending is fully supported. Call `grandi.send` with a `SendOptions` object to create a `Sender` instance capable of video, audio, metadata, and tally interactions:
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
const sender = await grandi.send({
|
|
230
|
+
name: "grandi-demo",
|
|
231
|
+
groups: "studio3",
|
|
232
|
+
clockVideo: true,
|
|
233
|
+
clockAudio: true
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const timecode = process.hrtime.bigint() / 100n;
|
|
237
|
+
const timestampNs = process.hrtime.bigint();
|
|
238
|
+
const timestamp = [
|
|
239
|
+
Number(timestampNs / 1_000_000_000n),
|
|
240
|
+
Number(timestampNs % 1_000_000_000n),
|
|
241
|
+
];
|
|
242
|
+
|
|
243
|
+
// Prepare frame payloads (see examples/simple-sender.mjs for helpers)
|
|
244
|
+
|
|
245
|
+
await sender.video({
|
|
246
|
+
xres: 1280,
|
|
247
|
+
yres: 720,
|
|
248
|
+
frameRateN: 30,
|
|
249
|
+
frameRateD: 1,
|
|
250
|
+
pictureAspectRatio: 16 / 9,
|
|
251
|
+
frameFormatType: grandi.FORMAT_TYPE_PROGRESSIVE,
|
|
252
|
+
lineStrideBytes: 1280 * 4,
|
|
253
|
+
data: whiteBuffer, // BGRA pixels
|
|
254
|
+
fourCC: grandi.FOURCC_BGRA,
|
|
255
|
+
timecode,
|
|
256
|
+
timestamp,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
await sender.audio({
|
|
260
|
+
sampleRate: 48_000,
|
|
261
|
+
noChannels: 2,
|
|
262
|
+
noSamples: 1600,
|
|
263
|
+
channelStrideBytes: 1600 * 4,
|
|
264
|
+
data: silentAudioBuffer,
|
|
265
|
+
fourCC: grandi.FOURCC_FLTp,
|
|
266
|
+
timecode,
|
|
267
|
+
timestamp,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
# Example metadata, that explicitly enable hardware acceleration in receiver
|
|
271
|
+
sender.metadata("<ndi_video_codec type=\"hardware\"/>");
|
|
272
|
+
|
|
273
|
+
const tally = sender.tally();
|
|
274
|
+
console.log(tally.on_program, tally.on_preview);
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Destroy senders and receivers explicitly when finished to release NDI resources.
|
|
278
|
+
|
|
279
|
+
### Other helpers
|
|
280
|
+
- `grandi.version()` returns the NDI SDK version string (e.g. `NDI SDK LINUX 10:24:11 Aug 21 2025 6.2.1.0`).
|
|
281
|
+
- `grandi.isSupportedCPU()` checks whether the host CPU can run the NDI SDK.
|
|
282
|
+
- `grandi.initialize()` / `grandi.destroy()` control the lifetime of the underlying library in advanced scenarios.
|
|
283
|
+
|
|
284
|
+
## Contributing
|
|
285
|
+
Ready to hack on Grandi? Here’s the typical workflow.
|
|
286
|
+
|
|
287
|
+
1. **Install prerequisites**
|
|
288
|
+
- Node.js ≥ 20.19.5 and a working C/C++ toolchain for your platform.
|
|
289
|
+
- Git LFS is *not* required; the NDI SDK is fetched dynamically.
|
|
290
|
+
2. **Download the NDI SDK + install deps**
|
|
291
|
+
- Run `npm install` (or `pnpm install`/`yarn install`). The `scripts/preinstall.mjs` hook downloads and unpacks the official NDI SDK into `ndi/`, then `node-gyp-build` compiles the native addon for your host platform. Re-run `npm install` after deleting `ndi/` if you need to refresh the SDK.
|
|
292
|
+
- To force-download all prebuild assets for release testing, run `npm run prebuild:download`.
|
|
293
|
+
- Set `NDI_FORCE=1` if you need to run the downloader in an unpacked tarball (normally it only runs inside the git repo).
|
|
294
|
+
3. **TypeScript build**
|
|
295
|
+
- `npm run build` compiles `src/` via `tsdown`, emitting ESM/CJS bundles and declaration files in `dist/`.
|
|
296
|
+
- `npm run prebuild` packages native binaries for distribution (requires the SDK assets fetched earlier).
|
|
297
|
+
4. **Native addon rebuild**
|
|
298
|
+
- If you change C/C++ files under `lib/`, recompile with `npx node-gyp-build` (or simply re-run `npm install`). This uses the same loader that consumers invoke at runtime.
|
|
299
|
+
5. **Testing**
|
|
300
|
+
- `npm test` runs the full Vitest suite (unit + integration stubs).
|
|
301
|
+
- `npm run test:unit` focuses on pure JS/TS tests.
|
|
302
|
+
- `RUN_NDI_TESTS=1 npm run test:integration` exercises the native bindings against a real NDI environment; ensure you have available senders/receivers before running.
|
|
303
|
+
- `npm run test:coverage` provides coverage data via `@vitest/coverage-v8`.
|
|
304
|
+
6. **Linting & formatting**
|
|
305
|
+
- `npm run lint` / `npm run format` cover the TypeScript/JavaScript sources via Biome.
|
|
306
|
+
- `npm run format:cpp` formats the native sources with `clang-format`.
|
|
307
|
+
7. **Manual verification**
|
|
308
|
+
- `node examples/simple-sender.mjs` and `node examples/simple-receiver.mjs` are quick smoke tests for the send/receive API.
|
|
309
|
+
- Use `NDI_FORCE=1 npm install` if you need to reassemble the NDI SDK artifacts even when they are already present.
|
|
310
|
+
|
|
311
|
+
Before opening a pull request, make sure the linter, formatter, and tests all pass, and include context for any platform-specific considerations (e.g., SDK versions, OS dependencies).
|
|
312
|
+
|
|
313
|
+
## API reference
|
|
314
|
+
This section documents every exported method and type surfaced by the module. Refer to `src/index.ts` and `src/types.ts` for authoritative definitions.
|
|
315
|
+
|
|
316
|
+
### Module exports
|
|
317
|
+
- `find(options?: FindOptions): Promise<Finder>` — discover available NDI sources, optionally filtering by groups, local visibility, or explicit IPs. Resolves to a finder handle whose `sources()` method returns the latest snapshot.
|
|
318
|
+
- `receive(options: ReceiveOptions): Promise<Receiver>` — create a receiver bound to a specific `Source`. Customize color format, bandwidth caps, interlaced support, and a friendly name.
|
|
319
|
+
- `send(options: SendOptions): Promise<Sender>` — create a sender that can push video, audio, metadata, and tally updates into the NDI network.
|
|
320
|
+
- `routing(params: { name?: string; groups?: string }): Promise<Routing>` — build an NDI router that can switch downstream destinations to new sources via `routing.change`.
|
|
321
|
+
- `initialize(): boolean` / `destroy(): boolean` — manually initialize or tear down the shared NDI state. Automatically handled when using `send`/`receive`, but exposed for completeness.
|
|
322
|
+
- `version(): string` — report the bundled NDI SDK version.
|
|
323
|
+
- `isSupportedCPU(): boolean` — guard call that reports whether the host CPU meets the NDI SDK requirements.
|
|
324
|
+
- Enum exports: `ColorFormat`, `AudioFormat`, `Bandwidth`, `FrameType`, `FourCC`.
|
|
325
|
+
- Default export: the `grandi` object containing the methods above plus constant aliases such as `COLOR_FORMAT_FASTEST`, `BANDWIDTH_HIGHEST`, etc.
|
|
326
|
+
|
|
327
|
+
### Receiver interface
|
|
328
|
+
`Receiver` instances expose:
|
|
329
|
+
|
|
330
|
+
- `video(timeoutMs?: number): Promise<ReceivedVideoFrame>` — obtain the next video frame.
|
|
331
|
+
- `audio(optionsOrTimeout?: AudioReceiveOptions | number, timeoutMs?: number): Promise<ReceivedAudioFrame>` — fetch audio, optionally overriding format or reference level per call.
|
|
332
|
+
- `metadata(timeoutMs?: number): Promise<ReceivedMetadataFrame>` — resolve metadata frames (strings, typically XML).
|
|
333
|
+
- `data(optionsOrTimeout?: AudioReceiveOptions | number, timeoutMs?: number): Promise<ReceiverDataFrame>` — return whichever payload (video, audio, metadata, source change, status change) arrives first.
|
|
334
|
+
- `tally(state: ReceiverTallyState): boolean` — push tally states (program/preview) upstream to the sender.
|
|
335
|
+
- `destroy(): boolean` — release the underlying NDI receiver.
|
|
336
|
+
- Properties: `embedded`, `source`, `colorFormat`, `bandwidth`, `allowVideoFields`, `name`.
|
|
337
|
+
|
|
338
|
+
### Sender interface
|
|
339
|
+
`Sender` instances surface:
|
|
340
|
+
|
|
341
|
+
- `video(frame: VideoFrame): Promise<void>` — send a video frame.
|
|
342
|
+
- `audio(frame: AudioFrame): Promise<void>` — send an audio frame.
|
|
343
|
+
- `metadata(data: string): boolean` — send metadata strings (XML).
|
|
344
|
+
- `tally(): SenderTally` — retrieve current tally state (program/preview booleans plus `changed` flag).
|
|
345
|
+
- `connections(): number` — how many actively connected receivers see this sender.
|
|
346
|
+
- `sourcename(): string` — fully qualified source name visible on the network.
|
|
347
|
+
- `destroy(): boolean` — dispose the sender and release network resources.
|
|
348
|
+
- Properties: `embedded`, `name`, `groups`, `clockVideo`, `clockAudio`.
|
|
349
|
+
|
|
350
|
+
### Routing interface
|
|
351
|
+
- `change(source: Source): boolean` — switch destinations to a new source.
|
|
352
|
+
- `clear(): boolean` — disconnect the current source.
|
|
353
|
+
- `connections(): number` — monitor downstream subscriptions.
|
|
354
|
+
- `sourcename(): string` — current routed source name.
|
|
355
|
+
- `destroy(): boolean` — cleanly shut down.
|
|
356
|
+
|
|
357
|
+
### Finder interface
|
|
358
|
+
- `sources(): Source[]` — latest snapshot of discovered sources.
|
|
359
|
+
- `wait(timeoutMs?: number): boolean` — block for network updates up to the given timeout.
|
|
360
|
+
- `destroy(): boolean` — dispose the finder and associated background threads.
|
|
361
|
+
|
|
362
|
+
### Options and helper types
|
|
363
|
+
- `Source` — `{ name: string; urlAddress?: string }`.
|
|
364
|
+
- `FindOptions` — `{ showLocalSources?: boolean; groups?: string; extraIPs?: string; }`.
|
|
365
|
+
- `ReceiveOptions` — `{ source: Source; colorFormat?: ColorFormat; bandwidth?: Bandwidth; allowVideoFields?: boolean; name?: string; }`.
|
|
366
|
+
- `SendOptions` — `{ name: string; groups?: string; clockVideo?: boolean; clockAudio?: boolean; }`.
|
|
367
|
+
- `AudioReceiveOptions` — `{ audioFormat?: AudioFormat; referenceLevel?: number; }` used when calling `receiver.audio` or `receiver.data`.
|
|
368
|
+
- `ReceiverTallyState` — `{ onProgram?: boolean; onPreview?: boolean; }`, used by `receiver.tally`.
|
|
369
|
+
- `SenderTally` — `{ changed: boolean; on_program: boolean; on_preview: boolean; }`, returned by `sender.tally`.
|
|
370
|
+
- `PtpTimestamp` — `[seconds, nanoseconds]` tuple aligning with the NDI SDK timestamp APIs.
|
|
371
|
+
- `Timecode` — `bigint | number | PtpTimestamp`, matching how timecodes are expressed throughout the SDK.
|
|
372
|
+
|
|
373
|
+
### Frame payload types
|
|
374
|
+
- `VideoFrame` — describes outbound frames: resolution, frame rate (`frameRateN`, `frameRateD`), aspect ratio, `fourCC`, `frameFormatType`, `lineStrideBytes`, `data`, optional `timecode`, `timestamp`, `metadata`.
|
|
375
|
+
- `ReceivedVideoFrame` — extends `VideoFrame` with guaranteed `type: "video"` plus non-optional `timecode`/`timestamp`.
|
|
376
|
+
- `AudioFrame` — outbound audio payload (sample rate, number of channels/samples, stride, `data`, `fourCC`, optional timing/metadata).
|
|
377
|
+
- `ReceivedAudioFrame` — inbound audio payload including `audioFormat`, `referenceLevel`, `timecode`, `timestamp`.
|
|
378
|
+
- `ReceivedMetadataFrame` — metadata payloads (`type: "metadata"`, `length`, `timecode`, `timestamp`, `data` string).
|
|
379
|
+
- `ReceiverDataFrame` — discriminated union of `ReceivedVideoFrame | ReceivedAudioFrame | ReceivedMetadataFrame | SourceChangeEvent | StatusChangeEvent`.
|
|
380
|
+
- `SourceChangeEvent` / `StatusChangeEvent` — internal notifications delivered via `receiver.data` when the remote sender changes or becomes unavailable.
|
|
381
|
+
|
|
382
|
+
### Enum reference
|
|
383
|
+
- `ColorFormat` — enumerates `BGRX_BGRA`, `UYVY_BGRA`, `RGBX_RGBA`, `UYVY_RGBA`, `Fastest`, `Best`, and `BGRX_BGRA_FLIPPED`. The `grandi.COLOR_FORMAT_*` constants map to these values.
|
|
384
|
+
- `AudioFormat` — `Float32Separate`, `Float32Interleaved`, `Int16Interleaved`. Access via `grandi.AUDIO_FORMAT_*`.
|
|
385
|
+
- `Bandwidth` — `MetadataOnly`, `AudioOnly`, `Lowest`, `Highest`. Access via `grandi.BANDWIDTH_*`.
|
|
386
|
+
- `FrameType` — `Interlaced`, `Progressive`, `Field0`, `Field1`. Access via `grandi.FORMAT_TYPE_*`.
|
|
387
|
+
- `FourCC` — common pixel/audio format codes (`UYVY`, `UYVA`, `P216`, `PA16`, `YV12`, `I420`, `NV12`, `BGRA`, `BGRX`, `RGBA`, `RGBX`, `FLTp`). Helper constants exist on the default export.
|
|
388
|
+
|
|
389
|
+
## Status, support, and further development
|
|
390
|
+
Support for sending and receiving streams across Windows, macOS, and Linux platforms is actively maintained. Contributions are welcome via pull requests, and enhancements or bug reports can be filed as GitHub issues.
|
|
391
|
+
|
|
392
|
+
## License
|
|
393
|
+
Apart from the exceptions below, this software is released under the Apache 2.0 license. See [LICENSE](./LICENSE) for details. Attribution: this project remains a maintained fork of Streampunk Grandiose, and portions derive from that project and community forks. See [NOTICE](./NOTICE) for attributions.
|
|
394
|
+
|
|
395
|
+
### License exceptions
|
|
396
|
+
The software uses libraries provided under a royalty-free license from NewTek, Inc. (see the [NDI SDK License](https://ndi.link/ndisdk_license) for full terms):
|
|
397
|
+
|
|
398
|
+
- The `ndi/include` includes files are licensed separately by NewTek under the MIT license.
|
|
399
|
+
- The DLL and library files are provided for installation convenience and are covered by the NewTek license in the `prebuild/` folder.
|
|
400
|
+
|
|
401
|
+
## Trademarks
|
|
402
|
+
NDI™ is a trademark of NewTek, Inc.
|