@octane-xplat/camera 0.17.1 → 0.19.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 +9 -9
- package/package.json +113 -103
- package/src/CameraView.android.tsrx +64 -21
- package/src/CameraView.ios.tsrx +48 -9
- package/src/CameraView.macos.tsrx +38 -7
- package/src/CameraView.web.tsrx +35 -11
- package/src/CameraView.windows.tsrx +56 -16
- package/src/host-movie.web.ts +22 -4
- package/src/layout-child.ts +3 -1
- package/src/layout-child.web.ts +6 -1
- package/src/layout-child.windows.ts +6 -1
- package/src/movie-metadata.web.ts +11 -1
- package/src/props.ts +28 -0
- package/src/session-backend.windows.ts +25 -9
- package/src/session-core.ts +4 -1
- package/src/style-merge.ts +3 -6
- package/src/synthetic-session.ts +7 -0
- package/src/types.ts +72 -1
- package/types/generated/.tsrx-typegen-manifest.json +38 -0
- package/types/generated/CameraView.android.d.ts +9 -0
- package/types/generated/CameraView.ios.d.ts +5 -0
- package/types/generated/CameraView.macos.d.ts +5 -0
- package/types/generated/CameraView.mobile.d.ts +5 -0
- package/types/generated/CameraView.web.d.ts +4 -0
- package/types/generated/CameraView.windows.d.ts +11 -0
- package/types/generated/camera-permission.mobile.d.ts +2 -0
- package/types/generated/camera-permission.windows.d.ts +6 -0
- package/types/generated/camera-session.ios.d.ts +2 -0
- package/types/generated/camera-session.macos.d.ts +10 -0
- package/types/generated/camera-session.windows.d.ts +9 -0
- package/types/generated/host-movie.web.d.ts +100 -0
- package/types/generated/index.d.ts +33 -0
- package/types/generated/index.web.d.ts +7 -0
- package/types/generated/layout-child.d.ts +11 -0
- package/types/generated/layout-child.web.d.ts +7 -0
- package/types/generated/layout-child.windows.d.ts +13 -0
- package/types/generated/movie-metadata.web.d.ts +9 -0
- package/types/generated/movie-storage.web.d.ts +5 -0
- package/types/generated/preview-tap.d.ts +7 -0
- package/types/{props.d.ts → generated/props.d.ts} +29 -1
- package/types/generated/session-backend.android.d.ts +3 -0
- package/types/generated/session-backend.d.ts +6 -0
- package/types/generated/session-backend.ios.d.ts +5 -0
- package/types/generated/session-backend.linux.d.ts +3 -0
- package/types/generated/session-backend.macos.d.ts +8 -0
- package/types/generated/session-backend.web.d.ts +3 -0
- package/types/generated/session-backend.windows.d.ts +37 -0
- package/types/{session-core.d.ts → generated/session-core.d.ts} +1 -1
- package/types/generated/session.d.ts +16 -0
- package/types/generated/style-merge.d.ts +8 -0
- package/types/{synthetic-session.d.ts → generated/synthetic-session.d.ts} +8 -1
- package/types/{types.d.ts → generated/types.d.ts} +70 -1
- package/LICENSE +0 -21
- package/types/index.d.ts +0 -48
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# `@octane-xplat/camera`
|
|
2
2
|
|
|
3
|
-
```sh
|
|
4
|
-
pnpm add @octane-xplat/camera
|
|
5
|
-
```
|
|
6
|
-
|
|
7
3
|
Live camera preview for Octane xplat apps: `getUserMedia` video on web,
|
|
8
4
|
`AVCaptureSession` on iOS, CameraX on Android,
|
|
9
5
|
`AVCaptureSession` + `AVCaptureVideoPreviewLayer` on macOS (AppKit), and
|
|
10
6
|
`MediaCapture` + `CaptureElement` on the Windows (WinUI 3) target.
|
|
11
7
|
|
|
8
|
+
```sh
|
|
9
|
+
bun add @octane-xplat/camera
|
|
10
|
+
```
|
|
11
|
+
|
|
12
12
|
```tsx
|
|
13
13
|
import { CameraView } from '@octane-xplat/camera'
|
|
14
14
|
|
|
@@ -25,7 +25,7 @@ export function Preview() {
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
This is the preview surface only — for one-shot still capture and library
|
|
28
|
-
picking use [`@octane-xplat/media`](
|
|
28
|
+
picking use [`@octane-xplat/media`](https://github.com/octane-xplat/octane-xplat/blob/main/packages/media/README.md). Permissions are
|
|
29
29
|
requested when the session starts; `onError` is how a denial shows up.
|
|
30
30
|
`ref` hands you the platform surface (`HTMLVideoElement` on web) for
|
|
31
31
|
controls the shared props don't cover, and the `ios`/`android`/`web`/
|
|
@@ -120,7 +120,7 @@ output in the app's private storage root instead of IndexedDB. Windows records
|
|
|
120
120
|
through `MediaCapture` into app-private MP4 files and is pending real-host
|
|
121
121
|
qualification. On Linux the GJS/WebKitGTK host owns media permissions and
|
|
122
122
|
writes MP4 clips under the app's data directory.
|
|
123
|
-
See [Record and reopen a camera movie](
|
|
123
|
+
See [Record and reopen a camera movie](https://octane-xplat.goddardai.org/movie-capture) for
|
|
124
124
|
explicit permission actions, audio, local output, and qualification limits.
|
|
125
125
|
|
|
126
126
|
```ts
|
|
@@ -130,6 +130,6 @@ await session.requestPermission('camera')
|
|
|
130
130
|
console.log(await session.capabilities())
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
-
Guide: [Building screens](
|
|
134
|
-
component index: [`docs/app/components.md`](
|
|
135
|
-
Exercised by [`CameraDemo`](
|
|
133
|
+
Guide: [Building screens](https://octane-xplat.goddardai.org/primitives) (leaf components);
|
|
134
|
+
component index: [`docs/app/components.md`](https://octane-xplat.goddardai.org/components).
|
|
135
|
+
Exercised by [`CameraDemo`](https://github.com/octane-xplat/octane-xplat/blob/main/packages/demos/src/CameraDemo.tsrx).
|
package/package.json
CHANGED
|
@@ -1,104 +1,114 @@
|
|
|
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.19.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
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"typegen": "tsrx-typegen --target camera",
|
|
47
|
+
"prepack": "bun run typegen && tsrx-typegen --pack-check",
|
|
48
|
+
"test:packed": "node tests/packed-consumer.mjs",
|
|
49
|
+
"pack:check": "tsrx-typegen --pack-check",
|
|
50
|
+
"test": "vitest run && node --test tests/*.test.mjs",
|
|
51
|
+
"test:macos-photo": "node tests/photo-native.macos.mjs",
|
|
52
|
+
"test:macos-photo-hardware": "node tests/photo-hardware.macos.mjs",
|
|
53
|
+
"test:web": "node tests/browser-conformance.web.mjs",
|
|
54
|
+
"test:webkitgtk": "node tests/webkitgtk-conformance.linux.mjs",
|
|
55
|
+
"typecheck": "tsrx-tsc --noEmit -p tsconfig.types.json"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@octane-xplat/jsx": "0.19.0",
|
|
59
|
+
"@octane-xplat/platform": "0.19.0",
|
|
60
|
+
"mediabunny": "1.62.1"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@nativescript-community/octane": "0.2.5",
|
|
64
|
+
"@nativescript/core": "9.1.3",
|
|
65
|
+
"@octane-xplat/macos-renderer": "0.19.0",
|
|
66
|
+
"@octanejs/vite-plugin": "0.5.0",
|
|
67
|
+
"octane": "0.16.3",
|
|
68
|
+
"tsrx-typegen": "0.5.0",
|
|
69
|
+
"typescript": "5.9.3",
|
|
70
|
+
"vite": "8.3.0",
|
|
71
|
+
"vitest": "4.1.11",
|
|
72
|
+
"@tsrx/typescript-plugin": "0.4.11",
|
|
73
|
+
"@nativescript/macos-node-api": "0.4.4-next.2026-08-09-31292056208"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
77
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
78
|
+
"octane": ">=0.6.3 <1",
|
|
79
|
+
"@nativescript/macos-node-api": "0.4.4-next.2026-08-09-31292056208"
|
|
80
|
+
},
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"@nativescript-community/octane": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"@nativescript/core": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
88
|
+
"octane": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
91
|
+
"@nativescript/macos-node-api": {
|
|
92
|
+
"optional": true
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"nativescript": {
|
|
96
|
+
"platforms": {
|
|
97
|
+
"ios": "7.0.0",
|
|
98
|
+
"android": "7.0.0"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"xplat": {
|
|
102
|
+
"macos": {
|
|
103
|
+
"swiftHeaderImports": [
|
|
104
|
+
"AppKit/AppKit.h"
|
|
105
|
+
],
|
|
106
|
+
"frameworks": [
|
|
107
|
+
"AVFoundation",
|
|
108
|
+
"CoreMedia",
|
|
109
|
+
"AppKit"
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"types": "./types/generated/index.d.ts"
|
|
114
|
+
}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
/** @jsxImportSource @
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
2
|
import { useImperativeHandle, useCallback, useEffect, useRef } from 'octane'
|
|
3
3
|
import { Application, View } from '@nativescript/core'
|
|
4
4
|
import { registerElement } from '@nativescript-community/octane'
|
|
5
|
-
import type { Attributes } from '@
|
|
5
|
+
import type { Attributes } from '@octane-xplat/jsx/intrinsics'
|
|
6
6
|
import type { CameraViewProps } from './props'
|
|
7
7
|
import { attachSessionPreview } from './session'
|
|
8
8
|
import { cameraHardwarePresent, ensureCameraPermission } from './camera-permission.mobile'
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
applyEscapeProps,
|
|
11
|
+
layoutChildProps,
|
|
12
|
+
nativeAccessibilityRole,
|
|
13
|
+
nativeAccessibilityState,
|
|
14
|
+
} from './layout-child'
|
|
15
|
+
|
|
10
16
|
import { observePreviewTap } from './preview-tap'
|
|
11
17
|
import { java } from '@octane-xplat/platform/android'
|
|
12
18
|
|
|
13
|
-
|
|
14
19
|
class CameraPreview extends View {
|
|
15
20
|
createNativeView() {
|
|
16
21
|
const nativeClass = (globalThis as any).com.octanexplat.camera.CameraPreviewView
|
|
@@ -18,20 +23,20 @@ class CameraPreview extends View {
|
|
|
18
23
|
}
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
declare module '@
|
|
22
|
-
interface
|
|
23
|
-
camerapreview: Attributes<
|
|
26
|
+
declare module '@octane-xplat/jsx/intrinsics' {
|
|
27
|
+
interface NativeElements<TElement> {
|
|
28
|
+
camerapreview: Attributes<TElement, {}>
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
registerElement('camerapreview', CameraPreview)
|
|
28
33
|
|
|
29
34
|
/** Live Android preview backed by CameraX. */
|
|
30
|
-
export function CameraView(props: CameraViewProps) @{
|
|
35
|
+
export function CameraView(props: CameraViewProps): unknown @{
|
|
31
36
|
const host = useRef<any>(null)
|
|
32
37
|
const active = props.active !== false
|
|
33
38
|
const facing = props.facing ?? 'back'
|
|
34
|
-
useImperativeHandle(props.ref, () => ({ native: host.current.android }), [])
|
|
39
|
+
useImperativeHandle(props.ref, () => ({ native: host.current.android }), [])
|
|
35
40
|
|
|
36
41
|
const bindHost = useCallback((view: any) => {
|
|
37
42
|
host.current = view
|
|
@@ -39,12 +44,17 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
39
44
|
|
|
40
45
|
useEffect(() => {
|
|
41
46
|
const nativeView = host.current?.android
|
|
42
|
-
if (!nativeView)
|
|
47
|
+
if (!nativeView) {
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
|
|
43
51
|
let disposed = false
|
|
44
52
|
let provider: any
|
|
45
53
|
let preview: any
|
|
46
54
|
nativeView.setCameraActive(active)
|
|
47
|
-
if (!active)
|
|
55
|
+
if (!active) {
|
|
56
|
+
return () => nativeView.setCameraActive(false)
|
|
57
|
+
}
|
|
48
58
|
|
|
49
59
|
const fail = (message: string) => props.onError?.({ message })
|
|
50
60
|
if (props.session) {
|
|
@@ -59,7 +69,10 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
59
69
|
onError: (issue) => fail(issue.message),
|
|
60
70
|
})
|
|
61
71
|
|
|
62
|
-
return () => {
|
|
72
|
+
return () => {
|
|
73
|
+
detach()
|
|
74
|
+
nativeView.setCameraActive(false)
|
|
75
|
+
}
|
|
63
76
|
} catch (error: any) {
|
|
64
77
|
fail(error?.message ?? 'camera session error')
|
|
65
78
|
return () => nativeView.setCameraActive(false)
|
|
@@ -72,7 +85,10 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
72
85
|
}
|
|
73
86
|
|
|
74
87
|
ensureCameraPermission().then((granted) => {
|
|
75
|
-
if (disposed)
|
|
88
|
+
if (disposed) {
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
|
|
76
92
|
if (!granted) {
|
|
77
93
|
fail('camera permission denied')
|
|
78
94
|
return
|
|
@@ -82,17 +98,24 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
82
98
|
const context = Application.android.context
|
|
83
99
|
const cameraX = (globalThis as any).androidx.camera
|
|
84
100
|
const future = cameraX.lifecycle.ProcessCameraProvider.getInstance(context)
|
|
85
|
-
const executor = (globalThis as any).androidx.core.content.ContextCompat.getMainExecutor(
|
|
101
|
+
const executor = (globalThis as any).androidx.core.content.ContextCompat.getMainExecutor(
|
|
102
|
+
context,
|
|
103
|
+
)
|
|
104
|
+
|
|
86
105
|
future.addListener(
|
|
87
106
|
new java.lang.Runnable({
|
|
88
107
|
run() {
|
|
89
|
-
if (disposed)
|
|
108
|
+
if (disposed) {
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
|
|
90
112
|
try {
|
|
91
113
|
provider = future.get()
|
|
92
114
|
const selectorClass = cameraX.core.CameraSelector
|
|
93
|
-
const lens =
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
const lens =
|
|
116
|
+
facing === 'front'
|
|
117
|
+
? selectorClass.LENS_FACING_FRONT
|
|
118
|
+
: selectorClass.LENS_FACING_BACK
|
|
96
119
|
|
|
97
120
|
const selector = new selectorClass.Builder().requireLensFacing(lens).build()
|
|
98
121
|
preview = new cameraX.core.Preview.Builder().build()
|
|
@@ -124,13 +147,33 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
124
147
|
|
|
125
148
|
useEffect(() => {
|
|
126
149
|
const view = host.current
|
|
127
|
-
if (!view)
|
|
150
|
+
if (!view) {
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
|
|
128
154
|
applyEscapeProps(view.android, props)
|
|
129
155
|
}, [props.ref, props.android])
|
|
130
156
|
|
|
131
157
|
useEffect(() => observePreviewTap(host.current, props.onTap), [props.onTap])
|
|
132
158
|
|
|
133
|
-
<masonview
|
|
134
|
-
|
|
159
|
+
<masonview
|
|
160
|
+
id={props.id}
|
|
161
|
+
className={['vx-layers', 'vx-cameraview', props.className]}
|
|
162
|
+
{...layoutChildProps(props, {
|
|
163
|
+
display: 'grid',
|
|
164
|
+
gridTemplateRows: '1fr',
|
|
165
|
+
gridTemplateColumns: '1fr',
|
|
166
|
+
backgroundColor: '#000',
|
|
167
|
+
...props.style,
|
|
168
|
+
})}
|
|
169
|
+
accessible={props.accessible}
|
|
170
|
+
accessibilityLabel={props.accessibilityLabel}
|
|
171
|
+
accessibilityRole={nativeAccessibilityRole(props.accessibilityRole) as any}
|
|
172
|
+
accessibilityHint={props.accessibilityHint}
|
|
173
|
+
accessibilityValue={props.accessibilityValue}
|
|
174
|
+
accessibilityState={nativeAccessibilityState(props.accessibilityState) as any}
|
|
175
|
+
accessibilityLiveRegion={props.accessibilityLiveRegion as any}
|
|
176
|
+
>
|
|
177
|
+
<camerapreview ref={bindHost} style={{ gridRow: '1', gridColumn: '1' }} />
|
|
135
178
|
</masonview>
|
|
136
179
|
}
|
package/src/CameraView.ios.tsrx
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
|
-
/** @jsxImportSource @
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
2
|
import { useImperativeHandle, useCallback, useEffect, useRef } from 'octane'
|
|
3
3
|
import type { CameraViewProps } from './props'
|
|
4
4
|
import { cameraHardwarePresent, ensureCameraPermission } from './camera-permission.mobile'
|
|
5
5
|
import { startCameraPreview } from './camera-session.ios'
|
|
6
6
|
import { attachSessionPreview } from './session'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
applyEscapeProps,
|
|
9
|
+
layoutChildProps,
|
|
10
|
+
nativeAccessibilityRole,
|
|
11
|
+
nativeAccessibilityState,
|
|
12
|
+
} from './layout-child'
|
|
13
|
+
|
|
8
14
|
import { observePreviewTap } from './preview-tap'
|
|
9
15
|
|
|
10
16
|
/** Live iOS preview backed by AVFoundation. With `session`, the preview
|
|
11
17
|
* attaches to the session-owned AVCaptureSession so movie recording can
|
|
12
18
|
* share it; without one the view owns its session as before. */
|
|
13
|
-
export function CameraView(props: CameraViewProps) @{
|
|
19
|
+
export function CameraView(props: CameraViewProps): unknown @{
|
|
14
20
|
const host = useRef<any>(null)
|
|
15
21
|
const active = props.active !== false
|
|
16
22
|
const facing = props.facing ?? 'back'
|
|
17
|
-
useImperativeHandle(
|
|
23
|
+
useImperativeHandle(
|
|
24
|
+
props.ref,
|
|
25
|
+
() => ({ native: host.current.ios ?? host.current.nativeViewProtected }),
|
|
26
|
+
[],
|
|
27
|
+
)
|
|
18
28
|
|
|
19
29
|
const bindHost = useCallback((view: any) => {
|
|
20
30
|
host.current = view
|
|
@@ -22,7 +32,10 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
22
32
|
|
|
23
33
|
useEffect(() => {
|
|
24
34
|
const view = host.current
|
|
25
|
-
if (!view || !active)
|
|
35
|
+
if (!view || !active) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
let disposed = false
|
|
27
40
|
let stopPreview: (() => void) | undefined
|
|
28
41
|
const fail = (message: string) => props.onError?.({ message })
|
|
@@ -36,7 +49,9 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
36
49
|
try {
|
|
37
50
|
const detach = attachSessionPreview(props.session, view, {
|
|
38
51
|
onReady: () => {
|
|
39
|
-
if (!disposed)
|
|
52
|
+
if (!disposed) {
|
|
53
|
+
props.onReady?.()
|
|
54
|
+
}
|
|
40
55
|
},
|
|
41
56
|
})
|
|
42
57
|
|
|
@@ -56,7 +71,10 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
56
71
|
}
|
|
57
72
|
|
|
58
73
|
ensureCameraPermission().then((granted) => {
|
|
59
|
-
if (disposed)
|
|
74
|
+
if (disposed) {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
60
78
|
if (!granted) {
|
|
61
79
|
fail('camera permission denied')
|
|
62
80
|
return
|
|
@@ -77,11 +95,32 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
77
95
|
|
|
78
96
|
useEffect(() => {
|
|
79
97
|
const view = host.current
|
|
80
|
-
if (!view)
|
|
98
|
+
if (!view) {
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
|
|
81
102
|
applyEscapeProps(view.ios ?? view.nativeViewProtected, props)
|
|
82
103
|
}, [props.ref, props.ios])
|
|
83
104
|
|
|
84
105
|
useEffect(() => observePreviewTap(host.current, props.onTap), [props.onTap])
|
|
85
106
|
|
|
86
|
-
<masonview
|
|
107
|
+
<masonview
|
|
108
|
+
ref={bindHost}
|
|
109
|
+
id={props.id}
|
|
110
|
+
className={['vx-layers', 'vx-cameraview', props.className]}
|
|
111
|
+
{...layoutChildProps(props, {
|
|
112
|
+
display: 'grid',
|
|
113
|
+
gridTemplateRows: '1fr',
|
|
114
|
+
gridTemplateColumns: '1fr',
|
|
115
|
+
backgroundColor: '#000',
|
|
116
|
+
...props.style,
|
|
117
|
+
})}
|
|
118
|
+
accessible={props.accessible}
|
|
119
|
+
accessibilityLabel={props.accessibilityLabel}
|
|
120
|
+
accessibilityRole={nativeAccessibilityRole(props.accessibilityRole) as any}
|
|
121
|
+
accessibilityHint={props.accessibilityHint}
|
|
122
|
+
accessibilityValue={props.accessibilityValue}
|
|
123
|
+
accessibilityState={nativeAccessibilityState(props.accessibilityState) as any}
|
|
124
|
+
accessibilityLiveRegion={props.accessibilityLiveRegion as any}
|
|
125
|
+
/>
|
|
87
126
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
/** @jsxImportSource @octane-xplat/
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
2
|
import { useImperativeHandle, useCallback, useEffect, useRef } from 'octane'
|
|
3
3
|
import type { CameraViewProps } from './props'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
cameraHardwarePresent,
|
|
6
|
+
ensureCameraPermission,
|
|
7
|
+
startCameraPreview,
|
|
8
|
+
} from './camera-session.macos'
|
|
9
|
+
|
|
5
10
|
import { attachSessionPreview } from './session'
|
|
6
11
|
import { layoutChildProps, nativeAccessibilityRole, nativeAccessibilityState } from './layout-child'
|
|
7
12
|
import { observePreviewTap } from './preview-tap'
|
|
@@ -9,7 +14,7 @@ import { observePreviewTap } from './preview-tap'
|
|
|
9
14
|
/** Live AppKit preview backed by AVFoundation. With `session`, the preview
|
|
10
15
|
* attaches to the session-owned AVCaptureSession so movie recording can
|
|
11
16
|
* share it; without one the view owns its session as before. */
|
|
12
|
-
export function CameraView(props: CameraViewProps) @{
|
|
17
|
+
export function CameraView(props: CameraViewProps): unknown @{
|
|
13
18
|
const host = useRef<any>(null)
|
|
14
19
|
const active = props.active !== false
|
|
15
20
|
const facing = props.facing ?? 'back'
|
|
@@ -21,7 +26,10 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
21
26
|
|
|
22
27
|
useEffect(() => {
|
|
23
28
|
const view = host.current
|
|
24
|
-
if (!view || !active)
|
|
29
|
+
if (!view || !active) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
let disposed = false
|
|
26
34
|
let stopPreview: (() => void) | undefined
|
|
27
35
|
const fail = (message: string) => props.onError?.({ message })
|
|
@@ -35,7 +43,9 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
35
43
|
try {
|
|
36
44
|
const detach = attachSessionPreview(props.session, view, {
|
|
37
45
|
onReady: () => {
|
|
38
|
-
if (!disposed)
|
|
46
|
+
if (!disposed) {
|
|
47
|
+
props.onReady?.()
|
|
48
|
+
}
|
|
39
49
|
},
|
|
40
50
|
})
|
|
41
51
|
|
|
@@ -55,7 +65,10 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
ensureCameraPermission().then((granted) => {
|
|
58
|
-
if (disposed)
|
|
68
|
+
if (disposed) {
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
59
72
|
if (!granted) {
|
|
60
73
|
fail('camera permission denied')
|
|
61
74
|
return
|
|
@@ -76,5 +89,23 @@ export function CameraView(props: CameraViewProps) @{
|
|
|
76
89
|
|
|
77
90
|
useEffect(() => observePreviewTap(host.current, props.onTap), [props.onTap])
|
|
78
91
|
|
|
79
|
-
<masonview
|
|
92
|
+
<masonview
|
|
93
|
+
ref={bindHost}
|
|
94
|
+
id={props.id}
|
|
95
|
+
className={['vx-layers', 'vx-cameraview', props.className]}
|
|
96
|
+
{...layoutChildProps(props, {
|
|
97
|
+
display: 'grid',
|
|
98
|
+
gridTemplateRows: '1fr',
|
|
99
|
+
gridTemplateColumns: '1fr',
|
|
100
|
+
backgroundColor: '#000000',
|
|
101
|
+
...props.style,
|
|
102
|
+
})}
|
|
103
|
+
accessible={props.accessible}
|
|
104
|
+
accessibilityLabel={props.accessibilityLabel}
|
|
105
|
+
accessibilityRole={nativeAccessibilityRole(props.accessibilityRole) as any}
|
|
106
|
+
accessibilityHint={props.accessibilityHint}
|
|
107
|
+
accessibilityValue={props.accessibilityValue}
|
|
108
|
+
accessibilityState={nativeAccessibilityState(props.accessibilityState) as any}
|
|
109
|
+
accessibilityLiveRegion={props.accessibilityLiveRegion as any}
|
|
110
|
+
/>
|
|
80
111
|
}
|