@windowkit/appkit 0.30.2 → 0.31.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/README.md +98 -0
- package/binding.gyp +6 -2
- package/package.json +2 -2
- package/prebuilds/darwin-arm64/calayers.node +0 -0
- package/prebuilds/darwin-x64/calayers.node +0 -0
- package/src/addon.mm +4 -0
- package/src/backend.mm +16 -0
- package/src/capture.mm +1732 -0
package/README.md
CHANGED
|
@@ -705,6 +705,104 @@ height, duration }` once the item is ready, and again if either moves (`duration
|
|
|
705
705
|
tagged BT.709 — on a layer and copied into a surface beside it, and holds the two to
|
|
706
706
|
the same colour on screen: 211, 127, 67 and 211, 127, 68 on an M1 Pro.
|
|
707
707
|
|
|
708
|
+
## Capture: cameras, microphones, the audio out, the screen
|
|
709
|
+
|
|
710
|
+
The devices a renderer's media capture lists and opens (react-x11's
|
|
711
|
+
`getUserMedia`, `<video srcObject>`, `createAudioFrames`, `captureScreenshot`).
|
|
712
|
+
Listing asks for nothing and raises no prompt; opening a camera or a microphone
|
|
713
|
+
needs the grant `authorizationStatus` reads, and a renderer asks for it first
|
|
714
|
+
(`requestAuthorization`) so the open never has to.
|
|
715
|
+
|
|
716
|
+
**Devices.**
|
|
717
|
+
|
|
718
|
+
- **`native.captureDevices()`** → `[{ id, kind, name, isDefault, groupId?,
|
|
719
|
+
position?, formats? }]`, or **`native.captureDevices(cb)`**, which lists on a
|
|
720
|
+
queue of its own: the first listing in a process loads AVFoundation's camera
|
|
721
|
+
plug-ins, 100 ms to over a second that a UI thread should not wait out. `kind`
|
|
722
|
+
is `'camera'`, `'microphone'` or `'speaker'`; `id` is stable across launches
|
|
723
|
+
(a microphone's is its CoreAudio UID); a camera's `formats` are `[{ width,
|
|
724
|
+
height, minFrameRate, maxFrameRate }]` and its `position` `'front'`,
|
|
725
|
+
`'back'`, `'external'` or `'unspecified'`; `groupId` is set where a camera and
|
|
726
|
+
a microphone share a model. The private aggregate devices an audio engine
|
|
727
|
+
makes for itself are left out.
|
|
728
|
+
- Event **`capture-devices`** whenever a device comes or goes or the default
|
|
729
|
+
input or output moves — from the first listing on, and only when what a
|
|
730
|
+
listing shows changed.
|
|
731
|
+
|
|
732
|
+
**A camera.**
|
|
733
|
+
|
|
734
|
+
- **`native.openCamera(deviceId | null, { width, height, frameRate })`** →
|
|
735
|
+
`{ id, layer, width, height, frameRate, format, range, colorSpace }`: the
|
|
736
|
+
device's format nearest the size asked (a 4:2:0 YCbCr one where it has one —
|
|
737
|
+
every Mac camera seen so far has only those — so nothing is converted on the
|
|
738
|
+
way) at the rate asked, clamped to it; nothing asked is the largest within
|
|
739
|
+
1280x720. The session starts on a queue of its own, and `camera-started { id }`
|
|
740
|
+
or `camera-error { id, name, message }` follows — `name` is Media Capture's:
|
|
741
|
+
`NotFoundError`, `NotAllowedError`, `NotReadableError`. `layer` is an
|
|
742
|
+
`AVCaptureVideoPreviewLayer`, a handle every layer verb takes, filling its
|
|
743
|
+
bounds and never mirrored; the renderer fits and flips.
|
|
744
|
+
- **`native.cameraFrames(id, on)`** — while on, `camera-frame { id, width,
|
|
745
|
+
height, format, range, colorSpace, planes, strides, time }`: the frame's own
|
|
746
|
+
planes (NV12: Y, then CbCr) as `Buffer` copies, `time` in seconds on the
|
|
747
|
+
capture clock. The newest frame only: one that arrives while the last is
|
|
748
|
+
still on its way replaces it, in pump mode and through the channel alike.
|
|
749
|
+
Off by default, so a preview on the layer costs nothing in JS.
|
|
750
|
+
- **`native.cameraCopyFrame(id, surface)`** — `playerCopyFrame`'s contract:
|
|
751
|
+
the newest frame into a 2D surface of its size, in the layer's colours, or
|
|
752
|
+
`null` when none is newer than the last one copied.
|
|
753
|
+
- Events `camera-muted { id, muted }` (the session interrupted — another app
|
|
754
|
+
took the camera — and resumed) and `camera-ended { id }` (unplugged, or a
|
|
755
|
+
runtime error). **`native.closeCamera(id)`**.
|
|
756
|
+
|
|
757
|
+
**The audio.** One `AVAudioEngine` for every microphone and every output: an
|
|
758
|
+
echo canceller needs the far-end signal, so while an echo-cancelled microphone
|
|
759
|
+
is open voice processing is on for the engine's input and output both, and
|
|
760
|
+
every output plays through it.
|
|
761
|
+
|
|
762
|
+
- **`native.openMicrophone(deviceId | null, { sampleRate, channels,
|
|
763
|
+
echoCancellation, noiseSuppression, autoGainControl })`** → `{ id,
|
|
764
|
+
sampleRate, channels, echoCancellation, noiseSuppression, autoGainControl }`,
|
|
765
|
+
what was asked. The audio is resampled and mixed down here, so `{ sampleRate:
|
|
766
|
+
16000, channels: 1 }` arrives as asked. `microphone-started { id,
|
|
767
|
+
echoCancellation, noiseSuppression, autoGainControl, sampleRate, channels,
|
|
768
|
+
latency }` says what the engine did — voice processing engaged or not — and
|
|
769
|
+
`microphone-error { id, name, message }` what went wrong; then `audio-input
|
|
770
|
+
{ id, sampleRate, channels, frames, time, dropped? }` every 10 ms, a
|
|
771
|
+
`Float32Array` a channel. Nothing is dropped short of two seconds of chunks
|
|
772
|
+
waiting; past that, `dropped` counts them. One input device at a time.
|
|
773
|
+
**`native.closeMicrophone(id)`**.
|
|
774
|
+
- **`native.openAudioOutput({ sampleRate, channels, deviceId })`** → `{ id,
|
|
775
|
+
sampleRate, channels }`; **`native.audioOutputWrite(id, [Float32Array, …])`**
|
|
776
|
+
→ frames now queued (ten seconds at most); **`native.audioOutputState(id)`**
|
|
777
|
+
→ `{ currentTime, queued, latency }`, `currentTime` the seconds the device has
|
|
778
|
+
played since the first write, silence where the queue ran dry included;
|
|
779
|
+
**`native.closeAudioOutput(id)`**. One output device for the engine: the
|
|
780
|
+
first output's `deviceId` picks it.
|
|
781
|
+
|
|
782
|
+
**The screen.**
|
|
783
|
+
|
|
784
|
+
- **`native.captureScreenshot({ display, window, rect, cursor }, cb)`** — one
|
|
785
|
+
picture through ScreenCaptureKit (macOS 14): `cb({ width, height, scale,
|
|
786
|
+
data })` with `data` straight RGBA in sRGB, or `cb({ error, name })` —
|
|
787
|
+
`NotAllowedError` without the Screen Recording grant, `NotFoundError` for a
|
|
788
|
+
display or window that is not there, `NotSupportedError` before macOS 14.
|
|
789
|
+
`display` is a `screenCaptureDisplays` id (the main display without one),
|
|
790
|
+
`window` a window number, `rect` points within the display.
|
|
791
|
+
- **`native.screenCaptureDisplays()`** → `[{ id, name, x, y, width, height,
|
|
792
|
+
scale }]`, points from the top left of the main display; through a callback
|
|
793
|
+
off the main thread.
|
|
794
|
+
- **`native.setWindowSharing(win, 'none' | 'readOnly')`** — `NSWindow.sharingType`:
|
|
795
|
+
`'none'` keeps the window out of every screenshot and recording, this app's
|
|
796
|
+
own included. On macOS 15 such a window comes back with every pixel clear.
|
|
797
|
+
|
|
798
|
+
`test/capture.js` lists the devices both ways, opens a camera and a microphone
|
|
799
|
+
that are not there (refused by name, nothing prompted), plays 0.2 s through an
|
|
800
|
+
output on the device's clock, and — where Screen Recording is allowed — reads a
|
|
801
|
+
red window back as red and an excluded one as clear. A camera and a microphone
|
|
802
|
+
that this process may use are opened and read from; where it may not they are
|
|
803
|
+
skipped, never prompted. `test/capture-threaded.js` does the same from a
|
|
804
|
+
worker.
|
|
805
|
+
|
|
708
806
|
## Text: at a display's scale
|
|
709
807
|
|
|
710
808
|
A text verb's size is the caller's pixels, and a renderer that draws in device pixels hands
|
package/binding.gyp
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"src/screencolor.mm",
|
|
12
12
|
"src/threaded.mm",
|
|
13
13
|
"src/video.mm",
|
|
14
|
-
"src/player.mm"
|
|
14
|
+
"src/player.mm",
|
|
15
|
+
"src/capture.mm"
|
|
15
16
|
],
|
|
16
17
|
"include_dirs": [
|
|
17
18
|
"<!@(node -p \"require('node-addon-api').include\")"
|
|
@@ -39,7 +40,10 @@
|
|
|
39
40
|
"-framework IOKit",
|
|
40
41
|
"-framework ApplicationServices",
|
|
41
42
|
"-framework UserNotifications",
|
|
42
|
-
"-framework EventKit"
|
|
43
|
+
"-framework EventKit",
|
|
44
|
+
"-framework CoreAudio",
|
|
45
|
+
"-framework AudioToolbox",
|
|
46
|
+
"-weak_framework ScreenCaptureKit"
|
|
43
47
|
]
|
|
44
48
|
}
|
|
45
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windowkit/appkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Retained-mode AppKit backend for Node.js: Core Animation (CALayer) layer trees, CoreText layout and drawing, IOSurface presentation, NSMenu, and native control bezels — the macOS half of react-x11.",
|
|
5
5
|
"author": "Andrey Sidorov <andrey.sidorov@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"install": "node scripts/install.js",
|
|
44
44
|
"build": "node-gyp rebuild",
|
|
45
45
|
"demo": "node demo/demo.js",
|
|
46
|
-
"test": "node test/app-lifecycle.js && node test/animation.js && node test/layer-transform.js && node test/contents-gravity.js && node test/contents-center.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/popup-menu.js && node test/pasteboard-write.js && node test/surface-blit.js && node test/surface-faded.js && node test/image-smoothing.js && node test/surface-colorspace.js && node test/video-surface.js && node test/player.js && node test/player-vp9.js && node test/round-rect-xy.js && node test/clip-rule.js && node test/radial-gradient.js && node test/control-bezels.js && node test/text-features.js && node test/font-from-data.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/text-justify.js && node test/text-scale.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/notifications.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/window-states.js && node test/threaded-window-states.js && node test/activation-policy.js && node test/last-input.js"
|
|
46
|
+
"test": "node test/app-lifecycle.js && node test/animation.js && node test/layer-transform.js && node test/contents-gravity.js && node test/contents-center.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/popup-menu.js && node test/pasteboard-write.js && node test/surface-blit.js && node test/surface-faded.js && node test/image-smoothing.js && node test/surface-colorspace.js && node test/video-surface.js && node test/player.js && node test/player-vp9.js && node test/capture.js && node test/capture-threaded.js && node test/round-rect-xy.js && node test/clip-rule.js && node test/radial-gradient.js && node test/control-bezels.js && node test/text-features.js && node test/font-from-data.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/text-justify.js && node test/text-scale.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/notifications.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/window-states.js && node test/threaded-window-states.js && node test/activation-policy.js && node test/last-input.js"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"node-addon-api": "^8.3.0"
|
|
Binary file
|
|
Binary file
|
package/src/addon.mm
CHANGED
|
@@ -1868,6 +1868,9 @@ void InitVideo(Napi::Env env, Napi::Object exports);
|
|
|
1868
1868
|
// src/player.mm — a file or URL played by AVFoundation: an AVPlayer, its
|
|
1869
1869
|
// AVPlayerLayer as a layer handle, and the frame showing copied into a surface.
|
|
1870
1870
|
void InitPlayer(Napi::Env env, Napi::Object exports);
|
|
1871
|
+
// src/capture.mm — cameras, microphones, speakers and an audio out on one
|
|
1872
|
+
// voice-processing engine, and ScreenCaptureKit's screenshots.
|
|
1873
|
+
void InitCapture(Napi::Env env, Napi::Object exports);
|
|
1871
1874
|
|
|
1872
1875
|
static Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
1873
1876
|
#define FN(js, fn) exports.Set(js, Napi::Function::New(env, fn))
|
|
@@ -1916,6 +1919,7 @@ static Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
|
1916
1919
|
InitThreaded(env, exports);
|
|
1917
1920
|
InitVideo(env, exports);
|
|
1918
1921
|
InitPlayer(env, exports);
|
|
1922
|
+
InitCapture(env, exports);
|
|
1919
1923
|
return exports;
|
|
1920
1924
|
}
|
|
1921
1925
|
|
package/src/backend.mm
CHANGED
|
@@ -1197,6 +1197,21 @@ static Napi::Value SetWindowIgnoresMouseEvents(const Napi::CallbackInfo& info) {
|
|
|
1197
1197
|
return info.Env().Undefined();
|
|
1198
1198
|
}
|
|
1199
1199
|
|
|
1200
|
+
// setWindowSharing(win, 'none' | 'readOnly') — NSWindow.sharingType: 'none'
|
|
1201
|
+
// keeps the window out of every screenshot and screen recording, this app's
|
|
1202
|
+
// own included; 'readOnly' is the default.
|
|
1203
|
+
static Napi::Value SetWindowSharing(const Napi::CallbackInfo& info) {
|
|
1204
|
+
std::string mode = info.Length() > 1 && info[1].IsString() ? info[1].As<Napi::String>().Utf8Value() : "";
|
|
1205
|
+
if (mode != "none" && mode != "readOnly") {
|
|
1206
|
+
Napi::TypeError::New(info.Env(), "setWindowSharing(win, mode): mode is 'none' or 'readOnly'")
|
|
1207
|
+
.ThrowAsJavaScriptException();
|
|
1208
|
+
return info.Env().Undefined();
|
|
1209
|
+
}
|
|
1210
|
+
NSWindowSharingType type = mode == "none" ? NSWindowSharingNone : NSWindowSharingReadOnly;
|
|
1211
|
+
OnWindow(info[0], ^(NSWindow* win) { win.sharingType = type; });
|
|
1212
|
+
return info.Env().Undefined();
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1200
1215
|
// setWindowFrame(win, x, y, w, h) — any argument may be null to keep it.
|
|
1201
1216
|
// x/y are the content's top-left in global top-left coordinates, points.
|
|
1202
1217
|
static Napi::Value SetWindowFrame(const Napi::CallbackInfo& info) {
|
|
@@ -8143,6 +8158,7 @@ void InitBackend(Napi::Env env, Napi::Object exports) {
|
|
|
8143
8158
|
BFN("showWindow", ShowWindowFn);
|
|
8144
8159
|
BFN("hideWindow", HideWindowFn);
|
|
8145
8160
|
BFN("setWindowTitle", SetWindowTitle);
|
|
8161
|
+
BFN("setWindowSharing", SetWindowSharing);
|
|
8146
8162
|
BFN("setWindowIgnoresMouseEvents", SetWindowIgnoresMouseEvents);
|
|
8147
8163
|
BFN("windowNumberAtPoint", WindowNumberAtPoint);
|
|
8148
8164
|
BFN("setWindowFrame", SetWindowFrame);
|