@octane-xplat/camera 0.18.0 → 0.20.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 +2 -132
- package/package.json +108 -103
- package/platforms/android/java/com/octanexplat/camera/CameraPreviewView.java +24 -0
- package/platforms/android/java/com/octanexplat/camera/CameraSessionBridge.java +153 -21
- package/platforms/ios/src/XplatSwitchingMovieWriter.swift +557 -0
- package/src/CameraView.android.tsrx +194 -118
- package/src/CameraView.ios.tsrx +129 -76
- package/src/CameraView.macos.tsrx +108 -70
- package/src/CameraView.tsrx +2 -0
- package/src/CameraView.web.tsrx +160 -125
- package/src/CameraView.windows.tsrx +141 -92
- package/src/camera-host.macos.ts +1059 -0
- package/src/camera-permission.mobile.ts +85 -81
- package/src/camera-permission.windows.ts +56 -53
- package/src/camera-session.ios.ts +89 -61
- package/src/camera-session.macos.ts +51 -49
- package/src/camera-session.windows.ts +113 -105
- package/src/host-movie.web.ts +266 -222
- package/src/index.ts +28 -26
- package/src/index.web.ts +27 -25
- package/src/layout-child.ts +88 -79
- package/src/layout-child.web.ts +57 -51
- package/src/layout-child.windows.ts +82 -71
- package/src/movie-metadata.web.ts +87 -74
- package/src/movie-storage.web.ts +142 -135
- package/src/movie-writer.ios.ts +170 -0
- package/src/photo-lifecycle.macos.ts +60 -0
- package/src/photo-sheet.macos.ts +505 -0
- package/src/preview-display.ios.ts +69 -0
- package/src/preview-pinch.ts +41 -0
- package/src/preview-tap.ts +22 -21
- package/src/props.ts +118 -68
- package/src/recording-haptics.ios.ts +39 -0
- package/src/recording-source.web.ts +159 -0
- package/src/session-backend.android.ts +552 -410
- package/src/session-backend.ios.ts +1500 -1148
- package/src/session-backend.linux.ts +886 -860
- package/src/session-backend.macos.ts +697 -679
- package/src/session-backend.ts +51 -49
- package/src/session-backend.web.ts +1181 -867
- package/src/session-backend.windows.ts +1556 -1467
- package/src/session-core.ts +925 -711
- package/src/session.ts +12 -12
- package/src/style-merge.ts +43 -43
- package/src/synthetic-session.ts +392 -333
- package/src/types.ts +384 -239
- package/types/generated/.tsrx-typegen-manifest.json +18 -0
- package/types/generated/CameraView.d.ts +2 -0
- package/types/generated/CameraView.web.d.ts +4 -0
- package/types/generated/camera-host.macos.d.ts +33 -0
- package/types/generated/index.d.ts +34 -0
- package/types/generated/layout-child.web.d.ts +7 -0
- package/types/generated/photo-lifecycle.macos.d.ts +12 -0
- package/types/generated/photo-sheet.macos.d.ts +36 -0
- package/types/generated/props.d.ts +111 -0
- package/types/generated/session-backend.d.ts +6 -0
- package/types/{session-core.d.ts → generated/session-core.d.ts} +30 -1
- package/types/generated/session.d.ts +16 -0
- package/types/{synthetic-session.d.ts → generated/synthetic-session.d.ts} +15 -1
- package/types/{types.d.ts → generated/types.d.ts} +145 -2
- package/LICENSE +0 -21
- package/platforms/macos/src/CameraOwnership.swift +0 -22
- package/platforms/macos/src/PhotoCaptureLifecycle.swift +0 -34
- package/platforms/macos/src/XplatCameraHost.swift +0 -639
- package/platforms/macos/src/XplatPhotoCaptureSheet.swift +0 -192
- package/types/index.d.ts +0 -48
- package/types/props.d.ts +0 -61
package/README.md
CHANGED
|
@@ -1,135 +1,5 @@
|
|
|
1
1
|
# `@octane-xplat/camera`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
pnpm add @octane-xplat/camera
|
|
5
|
-
```
|
|
3
|
+
[Documentation](https://octane-xplat.goddardai.org/package-camera).
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
`AVCaptureSession` on iOS, CameraX on Android,
|
|
9
|
-
`AVCaptureSession` + `AVCaptureVideoPreviewLayer` on macOS (AppKit), and
|
|
10
|
-
`MediaCapture` + `CaptureElement` on the Windows (WinUI 3) target.
|
|
11
|
-
|
|
12
|
-
```tsx
|
|
13
|
-
import { CameraView } from '@octane-xplat/camera'
|
|
14
|
-
|
|
15
|
-
export function Preview() {
|
|
16
|
-
return (
|
|
17
|
-
<CameraView
|
|
18
|
-
facing="back"
|
|
19
|
-
active
|
|
20
|
-
onReady={() => console.log('Preview running')}
|
|
21
|
-
onError={(error) => console.log(error.message)}
|
|
22
|
-
/>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
This is the preview surface only — for one-shot still capture and library
|
|
28
|
-
picking use [`@octane-xplat/media`](../media/README.md). Permissions are
|
|
29
|
-
requested when the session starts; `onError` is how a denial shows up.
|
|
30
|
-
`ref` hands you the platform surface (`HTMLVideoElement` on web) for
|
|
31
|
-
controls the shared props don't cover, and the `ios`/`android`/`web`/
|
|
32
|
-
`windows` escape props apply after the shared props. On macOS the leaf is a
|
|
33
|
-
compiled Swift `XplatCameraHost` that owns the capture session; the app bundle
|
|
34
|
-
needs `NSCameraUsageDescription` (and `NSMicrophoneUsageDescription` for
|
|
35
|
-
audio) declared through `xplat.targets.macos.package.infoPlist`.
|
|
36
|
-
|
|
37
|
-
```tsx
|
|
38
|
-
// Preview.web.tsx — browser properties belong in this platform file.
|
|
39
|
-
import { CameraView } from '@octane-xplat/camera'
|
|
40
|
-
|
|
41
|
-
export function Preview() {
|
|
42
|
-
return (
|
|
43
|
-
<CameraView
|
|
44
|
-
web={{ playsInline: true }}
|
|
45
|
-
ref={(handle) => console.log(handle.native)}
|
|
46
|
-
onError={(error) => console.log(error.message)}
|
|
47
|
-
/>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Tap-to-focus
|
|
53
|
-
|
|
54
|
-
`CameraView` reports where the user tapped as a normalized point —
|
|
55
|
-
`{x: 0, y: 0}` is the top-left corner of the preview, `{x: 1, y: 1}` the
|
|
56
|
-
bottom-right. Hand the point to a session's `focusAtPoint` to meter one
|
|
57
|
-
autofocus and auto-exposure pass there:
|
|
58
|
-
|
|
59
|
-
```tsx
|
|
60
|
-
import { CameraView, createCameraSession } from '@octane-xplat/camera'
|
|
61
|
-
|
|
62
|
-
const session = createCameraSession()
|
|
63
|
-
|
|
64
|
-
export function FocusablePreview() {
|
|
65
|
-
return <CameraView session={session} onTap={(point) => session.focusAtPoint(point)} />
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
`onTap` is a pure notification — it never takes over the gesture, so
|
|
70
|
-
double-tap and pan recognizers layered over the preview keep working.
|
|
71
|
-
`focusAtPoint` needs a session (it drives the camera the preview
|
|
72
|
-
attaches) and quietly does nothing on cameras that cannot meter at a
|
|
73
|
-
point — front cameras are often fixed-focus. Check
|
|
74
|
-
`capabilities().focusPointOfInterest` and `exposurePointOfInterest`
|
|
75
|
-
before showing focus UI. Metering lands on iOS, Android, and macOS; the
|
|
76
|
-
tap event fires on iOS, Android, and web.
|
|
77
|
-
|
|
78
|
-
## Movie recording
|
|
79
|
-
|
|
80
|
-
`createCameraSession` creates a shared camera owner: the same session can
|
|
81
|
-
drive a `CameraView` preview and one movie-recording attempt at a time.
|
|
82
|
-
Pass the session to `CameraView` instead of `facing`; the preview attaches
|
|
83
|
-
the camera the session owns. Recording requires an attached, ready preview.
|
|
84
|
-
|
|
85
|
-
```tsx
|
|
86
|
-
import { CameraView, createCameraSession } from '@octane-xplat/camera'
|
|
87
|
-
|
|
88
|
-
const session = createCameraSession({ camera: 'default' })
|
|
89
|
-
|
|
90
|
-
export function Recorder() {
|
|
91
|
-
return <CameraView session={session} />
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
A take settles after the movie is finalized, metadata is verified, and local
|
|
96
|
-
storage is committed. Native output lives in app-private files — including the
|
|
97
|
-
packaged Linux WebKitGTK host, which writes under the app's data directory;
|
|
98
|
-
Web uses persistent origin storage. Reopen it with `session.openOutput(output)`.
|
|
99
|
-
|
|
100
|
-
```ts
|
|
101
|
-
const take = session.startRecording({ maximumDurationMs: 30_000 })
|
|
102
|
-
// … later, on a stop press or a maximum-duration limit:
|
|
103
|
-
const outcome = await take.stop()
|
|
104
|
-
if (outcome.kind === 'clip') {
|
|
105
|
-
const clip = outcome.clip
|
|
106
|
-
console.log(clip.durationMs, clip.width, clip.height, clip.output)
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
One preview and one recording per session; a second `startRecording` throws
|
|
111
|
-
`CameraCaptureError` with `kind: 'busy'`. Check `session.capabilities()` for
|
|
112
|
-
`supported`/`available` before presenting capture UI, and `session.snapshot()`
|
|
113
|
-
or `session.subscribe` for state. iOS, Android, Web, macOS, the Windows WinUI
|
|
114
|
-
target, and the packaged Linux WebKitGTK host have recording adapters; Web
|
|
115
|
-
requires persistent origin storage.
|
|
116
|
-
macOS writes app-private MOV files through `AVCaptureMovieFileOutput` and
|
|
117
|
-
reports finalized track metadata; on macOS 14+ the four cardinal orientations
|
|
118
|
-
are lockable. Inside a qualified `xplat` WKWebView host the Web backend stores
|
|
119
|
-
output in the app's private storage root instead of IndexedDB. Windows records
|
|
120
|
-
through `MediaCapture` into app-private MP4 files and is pending real-host
|
|
121
|
-
qualification. On Linux the GJS/WebKitGTK host owns media permissions and
|
|
122
|
-
writes MP4 clips under the app's data directory.
|
|
123
|
-
See [Record and reopen a camera movie](../../docs/app/movie-capture.md) for
|
|
124
|
-
explicit permission actions, audio, local output, and qualification limits.
|
|
125
|
-
|
|
126
|
-
```ts
|
|
127
|
-
console.log(await session.permissions())
|
|
128
|
-
// Call from an app button:
|
|
129
|
-
await session.requestPermission('camera')
|
|
130
|
-
console.log(await session.capabilities())
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Guide: [Building screens](../../docs/app/primitives.md) (leaf components);
|
|
134
|
-
component index: [`docs/app/components.md`](../../docs/app/components.md).
|
|
135
|
-
Exercised by [`CameraDemo`](../demos/src/CameraDemo.tsrx).
|
|
5
|
+
[API reference](https://octane-xplat.goddardai.org/api-camera).
|
package/package.json
CHANGED
|
@@ -1,104 +1,109 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
2
|
+
"name": "@octane-xplat/camera",
|
|
3
|
+
"version": "0.20.0",
|
|
4
|
+
"description": "Live camera preview for Octane xplat — web getUserMedia + native capture (AVCapture / CameraX)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"android",
|
|
7
|
+
"camera",
|
|
8
|
+
"camera-preview",
|
|
9
|
+
"cross-platform",
|
|
10
|
+
"ios",
|
|
11
|
+
"nativescript",
|
|
12
|
+
"octane",
|
|
13
|
+
"photo",
|
|
14
|
+
"video-capture",
|
|
15
|
+
"web",
|
|
16
|
+
"xplat"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/camera",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/octane-xplat/octane-xplat",
|
|
23
|
+
"directory": "packages/camera"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"types/generated",
|
|
27
|
+
"src",
|
|
28
|
+
"platforms",
|
|
29
|
+
"!src/**/*.test.*",
|
|
30
|
+
"!src/**/*.spec.*"
|
|
31
|
+
],
|
|
32
|
+
"type": "module",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./types/generated/index.d.ts",
|
|
36
|
+
"linux": "./src/index.web.ts",
|
|
37
|
+
"web": "./src/index.web.ts",
|
|
38
|
+
"native": "./src/index.ts",
|
|
39
|
+
"default": "./src/index.ts"
|
|
40
|
+
},
|
|
41
|
+
"./photo-sheet.macos": {
|
|
42
|
+
"types": "./src/photo-sheet.macos.ts",
|
|
43
|
+
"native": "./src/photo-sheet.macos.ts",
|
|
44
|
+
"default": "./src/photo-sheet.macos.ts"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"typegen": "tsrx-typegen --target camera",
|
|
52
|
+
"prepack": "bun run typegen && tsrx-typegen --pack-check",
|
|
53
|
+
"test:ios-writer": "node tests/ios-writer-simulator.mjs",
|
|
54
|
+
"test:ios-device": "node tests/ios-device.mjs",
|
|
55
|
+
"test:packed": "node tests/packed-consumer.mjs",
|
|
56
|
+
"pack:check": "tsrx-typegen --pack-check",
|
|
57
|
+
"test": "vitest run && node --test tests/*.test.mjs",
|
|
58
|
+
"test:web": "node tests/browser-conformance.web.mjs",
|
|
59
|
+
"test:webkitgtk": "node tests/webkitgtk-conformance.linux.mjs",
|
|
60
|
+
"typecheck": "tsc --runExternalCode --noEmit -p tsconfig.types.json",
|
|
61
|
+
"test:macos-runtime": "node tests/packed-consumer.mjs --macos-native"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@octane-xplat/jsx": "0.20.0",
|
|
65
|
+
"@octane-xplat/platform": "0.20.0",
|
|
66
|
+
"mediabunny": "1.62.1"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@nativescript-community/octane": "0.2.5",
|
|
70
|
+
"@nativescript/core": "9.1.3",
|
|
71
|
+
"@octane-xplat/macos-appkit": "0.20.0",
|
|
72
|
+
"@octanejs/vite-plugin": "0.5.0",
|
|
73
|
+
"octane": "0.16.3",
|
|
74
|
+
"tsrx-typegen": "0.6.1",
|
|
75
|
+
"typescript": "7.1.0-beta",
|
|
76
|
+
"vite": "8.3.6",
|
|
77
|
+
"vitest": "4.1.11",
|
|
78
|
+
"@nativescript/macos-node-api": "0.5.0-beta.0",
|
|
79
|
+
"@tsrx/content-mapper": "0.1.2",
|
|
80
|
+
"typescript-classic": "npm:typescript@5.9.3"
|
|
81
|
+
},
|
|
82
|
+
"peerDependencies": {
|
|
83
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
84
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
85
|
+
"octane": ">=0.6.3 <1",
|
|
86
|
+
"@nativescript/macos-node-api": "0.5.0-beta.0"
|
|
87
|
+
},
|
|
88
|
+
"peerDependenciesMeta": {
|
|
89
|
+
"@nativescript-community/octane": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"@nativescript/core": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"octane": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"@nativescript/macos-node-api": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"nativescript": {
|
|
103
|
+
"platforms": {
|
|
104
|
+
"ios": "7.0.0",
|
|
105
|
+
"android": "7.0.0"
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"types": "./types/generated/index.d.ts"
|
|
109
|
+
}
|
|
@@ -3,6 +3,8 @@ package com.octanexplat.camera;
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.view.ViewGroup;
|
|
5
5
|
import android.widget.FrameLayout;
|
|
6
|
+
import android.widget.ImageView;
|
|
7
|
+
import android.graphics.Bitmap;
|
|
6
8
|
|
|
7
9
|
import androidx.camera.core.MeteringPoint;
|
|
8
10
|
import androidx.camera.core.Preview;
|
|
@@ -14,6 +16,7 @@ import androidx.lifecycle.LifecycleRegistry;
|
|
|
14
16
|
public final class CameraPreviewView extends FrameLayout implements LifecycleOwner {
|
|
15
17
|
private final LifecycleRegistry lifecycle;
|
|
16
18
|
private final PreviewView previewView;
|
|
19
|
+
private final ImageView heldPreview;
|
|
17
20
|
private boolean cameraActive = true;
|
|
18
21
|
private boolean attached;
|
|
19
22
|
|
|
@@ -22,6 +25,9 @@ public final class CameraPreviewView extends FrameLayout implements LifecycleOwn
|
|
|
22
25
|
lifecycle = new LifecycleRegistry(this);
|
|
23
26
|
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
|
24
27
|
previewView = new PreviewView(context);
|
|
28
|
+
// TextureView permits retaining the last preview frame during a
|
|
29
|
+
// live input swap. The recording itself stays in CameraX.
|
|
30
|
+
previewView.setImplementationMode(PreviewView.ImplementationMode.COMPATIBLE);
|
|
25
31
|
previewView.setScaleType(PreviewView.ScaleType.FILL_CENTER);
|
|
26
32
|
addView(
|
|
27
33
|
previewView,
|
|
@@ -30,6 +36,24 @@ public final class CameraPreviewView extends FrameLayout implements LifecycleOwn
|
|
|
30
36
|
ViewGroup.LayoutParams.MATCH_PARENT
|
|
31
37
|
)
|
|
32
38
|
);
|
|
39
|
+
heldPreview = new ImageView(context);
|
|
40
|
+
heldPreview.setScaleType(ImageView.ScaleType.FIT_XY);
|
|
41
|
+
heldPreview.setVisibility(GONE);
|
|
42
|
+
addView(heldPreview, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Retain this camera's already transformed preview pixels in memory;
|
|
46
|
+
* never persist them or use a separate camera acquisition. */
|
|
47
|
+
public boolean holdPreview() {
|
|
48
|
+
Bitmap frame = previewView.getBitmap();
|
|
49
|
+
if (frame == null) return false;
|
|
50
|
+
heldPreview.setImageBitmap(frame);
|
|
51
|
+
heldPreview.setVisibility(VISIBLE);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
public void releaseHeldPreview() {
|
|
55
|
+
heldPreview.setVisibility(GONE);
|
|
56
|
+
heldPreview.setImageDrawable(null);
|
|
33
57
|
}
|
|
34
58
|
|
|
35
59
|
@Override
|