@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
|
@@ -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,72 +14,105 @@ 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) @{
|
|
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
|
-
|
|
17
|
+
export function CameraView(props: CameraViewProps): unknown @{
|
|
18
|
+
const host = useRef<any>(null)
|
|
19
|
+
const active = props.active !== false
|
|
20
|
+
const facing = props.facing ?? 'back'
|
|
21
|
+
|
|
22
|
+
useImperativeHandle(props.ref, () => ({ native: host.current }), [])
|
|
23
|
+
|
|
24
|
+
const bindHost = useCallback((view: any) => {
|
|
25
|
+
host.current = view
|
|
26
|
+
}, [])
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const view = host.current
|
|
30
|
+
|
|
31
|
+
if (!view || !active) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let disposed = false
|
|
36
|
+
let stopPreview: (() => void) | undefined
|
|
37
|
+
const fail = (message: string) => props.onError?.({ message })
|
|
38
|
+
|
|
39
|
+
if (props.session) {
|
|
40
|
+
if (props.facing !== undefined) {
|
|
41
|
+
fail('camera session conflicts with facing')
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const detach = attachSessionPreview(props.session, view, {
|
|
47
|
+
onReady: () => {
|
|
48
|
+
if (!disposed) {
|
|
49
|
+
props.onReady?.()
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
onDisplayReady: () => {
|
|
53
|
+
if (!disposed) {
|
|
54
|
+
props.onDisplayReady?.()
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
disposed = true
|
|
61
|
+
detach()
|
|
62
|
+
}
|
|
63
|
+
} catch (error: any) {
|
|
64
|
+
fail(error?.message ?? 'camera session error')
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!cameraHardwarePresent()) {
|
|
70
|
+
fail('camera unsupported')
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
ensureCameraPermission().then((granted) => {
|
|
75
|
+
if (disposed) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!granted) {
|
|
80
|
+
fail('camera permission denied')
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
stopPreview = startCameraPreview(view, facing, props.onReady)
|
|
86
|
+
} catch (error: any) {
|
|
87
|
+
fail(error?.message ?? 'camera error')
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
return () => {
|
|
92
|
+
disposed = true
|
|
93
|
+
stopPreview?.()
|
|
94
|
+
}
|
|
95
|
+
}, [active, facing, props.session])
|
|
96
|
+
|
|
97
|
+
useEffect(() => observePreviewTap(host.current, props.onTap), [props.onTap])
|
|
98
|
+
|
|
99
|
+
<masonview
|
|
100
|
+
ref={bindHost}
|
|
101
|
+
id={props.id}
|
|
102
|
+
className={['vx-layers', 'vx-cameraview', props.className]}
|
|
103
|
+
{...layoutChildProps(props, {
|
|
104
|
+
display: 'grid',
|
|
105
|
+
gridTemplateRows: '1fr',
|
|
106
|
+
gridTemplateColumns: '1fr',
|
|
107
|
+
backgroundColor: '#000000',
|
|
108
|
+
...props.style,
|
|
109
|
+
})}
|
|
110
|
+
accessible={props.accessible}
|
|
111
|
+
accessibilityLabel={props.accessibilityLabel}
|
|
112
|
+
accessibilityRole={nativeAccessibilityRole(props.accessibilityRole) as any}
|
|
113
|
+
accessibilityHint={props.accessibilityHint}
|
|
114
|
+
accessibilityValue={props.accessibilityValue}
|
|
115
|
+
accessibilityState={nativeAccessibilityState(props.accessibilityState) as any}
|
|
116
|
+
accessibilityLiveRegion={props.accessibilityLiveRegion as any}
|
|
117
|
+
/>
|
|
80
118
|
}
|
package/src/CameraView.web.tsrx
CHANGED
|
@@ -1,132 +1,167 @@
|
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx/dom */
|
|
2
|
+
import type { JSX } from 'octane/jsx-runtime'
|
|
1
3
|
import { useImperativeHandle, useEffect, useRef } from 'octane'
|
|
2
4
|
import type { CameraViewProps } from './props'
|
|
3
5
|
import { attachSessionPreview } from './session'
|
|
4
6
|
import { applyEscapeProps, layoutChildProps } from './layout-child.web'
|
|
5
7
|
|
|
6
8
|
/** Live web preview backed by getUserMedia. */
|
|
7
|
-
export function CameraView(props: CameraViewProps) @{
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
9
|
+
export function CameraView(props: CameraViewProps): JSX.Element @{
|
|
10
|
+
const hostRef = useRef<any>(null)
|
|
11
|
+
const video = useRef<HTMLVideoElement | null>(null)
|
|
12
|
+
const facing = props.facing ?? 'back'
|
|
13
|
+
const active = props.active !== false
|
|
14
|
+
const readyFired = useRef(false)
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const element = video.current
|
|
18
|
+
|
|
19
|
+
if (!element || !active) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (props.session) {
|
|
24
|
+
if (props.facing !== undefined) {
|
|
25
|
+
props.onError?.({ message: 'camera session conflicts with facing' })
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
return attachSessionPreview(props.session, element, {
|
|
31
|
+
onReady: props.onReady,
|
|
32
|
+
onDisplayReady: props.onDisplayReady,
|
|
33
|
+
onError: (issue) => props.onError?.({ message: issue.message }),
|
|
34
|
+
})
|
|
35
|
+
} catch (error: any) {
|
|
36
|
+
props.onError?.({ message: error?.message ?? 'camera session error' })
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const mediaDevices = navigator.mediaDevices
|
|
42
|
+
|
|
43
|
+
if (!mediaDevices?.getUserMedia) {
|
|
44
|
+
props.onError?.({ message: 'camera unsupported' })
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let stream: MediaStream | null = null
|
|
49
|
+
let disposed = false
|
|
50
|
+
|
|
51
|
+
readyFired.current = false
|
|
52
|
+
mediaDevices
|
|
53
|
+
.getUserMedia({
|
|
54
|
+
video: { facingMode: facing === 'front' ? 'user' : 'environment' },
|
|
55
|
+
audio: false,
|
|
56
|
+
})
|
|
57
|
+
.then((nextStream) => {
|
|
58
|
+
if (disposed) {
|
|
59
|
+
for (const track of nextStream.getTracks()) {
|
|
60
|
+
track.stop()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
stream = nextStream
|
|
67
|
+
element.srcObject = nextStream
|
|
68
|
+
element.play()?.catch(() => {})
|
|
69
|
+
})
|
|
70
|
+
.catch((error: any) => {
|
|
71
|
+
props.onError?.({
|
|
72
|
+
message:
|
|
73
|
+
error?.name === 'NotAllowedError'
|
|
74
|
+
? 'camera permission denied'
|
|
75
|
+
: String(error?.name ?? error ?? 'camera error'),
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
return () => {
|
|
80
|
+
disposed = true
|
|
81
|
+
element.srcObject = null
|
|
82
|
+
if (stream) {
|
|
83
|
+
for (const track of stream.getTracks()) {
|
|
84
|
+
track.stop()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, [active, facing, props.session])
|
|
89
|
+
|
|
90
|
+
useImperativeHandle(props.ref, () => ({ native: hostRef.current }), undefined)
|
|
91
|
+
|
|
92
|
+
<div
|
|
93
|
+
id={props.id}
|
|
94
|
+
className={['vx-layers', 'vx-cameraview', props.className]}
|
|
95
|
+
{...layoutChildProps(props, {
|
|
96
|
+
position: 'relative',
|
|
97
|
+
overflow: 'hidden',
|
|
98
|
+
backgroundColor: '#000',
|
|
99
|
+
...props.style,
|
|
100
|
+
})}
|
|
101
|
+
role={props.accessibilityRole}
|
|
102
|
+
aria-label={props.accessibilityLabel}
|
|
103
|
+
aria-hidden={props.accessible === false ? true : undefined}
|
|
104
|
+
aria-description={props.accessibilityHint}
|
|
105
|
+
aria-valuetext={props.accessibilityValue}
|
|
106
|
+
aria-disabled={props.accessibilityState?.disabled}
|
|
107
|
+
aria-selected={props.accessibilityState?.selected}
|
|
108
|
+
aria-checked={props.accessibilityState?.checked}
|
|
109
|
+
aria-live={props.accessibilityLiveRegion === 'none' ? 'off' : props.accessibilityLiveRegion}
|
|
110
|
+
>
|
|
111
|
+
@if (active) {
|
|
112
|
+
<video
|
|
113
|
+
ref={(element: HTMLVideoElement | null) => {
|
|
114
|
+
hostRef.current = element
|
|
115
|
+
video.current = element
|
|
116
|
+
if (!element) {
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
applyEscapeProps(element, props)
|
|
121
|
+
}}
|
|
122
|
+
muted={true}
|
|
123
|
+
autoplay={true}
|
|
124
|
+
playsInline={true}
|
|
125
|
+
onClick={(event: MouseEvent) => {
|
|
126
|
+
const onTap = props.onTap
|
|
127
|
+
const target = event.currentTarget as HTMLElement | null
|
|
128
|
+
|
|
129
|
+
if (!onTap || !target) {
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const rect = target.getBoundingClientRect()
|
|
134
|
+
|
|
135
|
+
if (!(rect.width > 0) || !(rect.height > 0)) {
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
onTap({
|
|
140
|
+
x: Math.min(1, Math.max(0, (event.clientX - rect.left) / rect.width)),
|
|
141
|
+
y: Math.min(1, Math.max(0, (event.clientY - rect.top) / rect.height)),
|
|
142
|
+
})
|
|
143
|
+
}}
|
|
144
|
+
style={{
|
|
145
|
+
display: 'block',
|
|
146
|
+
width: '100%',
|
|
147
|
+
height: '100%',
|
|
148
|
+
objectFit: 'cover',
|
|
149
|
+
transform: facing === 'front' ? 'scaleX(-1)' : undefined,
|
|
150
|
+
}}
|
|
151
|
+
onPlaying={() => {
|
|
152
|
+
if (props.session) {
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
props.onDisplayReady?.()
|
|
157
|
+
if (readyFired.current) {
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
readyFired.current = true
|
|
162
|
+
props.onReady?.()
|
|
163
|
+
}}
|
|
164
|
+
/>
|
|
165
|
+
}
|
|
166
|
+
</div>
|
|
132
167
|
}
|