@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
|
@@ -4,88 +4,92 @@ import { android } from '@octane-xplat/platform/android'
|
|
|
4
4
|
let requestCode = 7719
|
|
5
5
|
|
|
6
6
|
export function cameraHardwarePresent(): boolean {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
if (isIOS) {
|
|
8
|
+
return typeof (globalThis as any).AVCaptureDevice !== 'undefined'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (!isAndroid) {
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const context = Application.android?.context ?? Application.android?.startActivity
|
|
17
|
+
|
|
18
|
+
return context?.getPackageManager()?.hasSystemFeature('android.hardware.camera.any') !== false
|
|
19
|
+
} catch {
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export async function ensureCameraPermission(): Promise<boolean> {
|
|
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
|
-
|
|
25
|
+
try {
|
|
26
|
+
if (isIOS) {
|
|
27
|
+
const av = (globalThis as any).AVCaptureDevice
|
|
28
|
+
const mediaType = (globalThis as any).AVMediaTypeVideo ?? 'vide'
|
|
29
|
+
const status = av?.authorizationStatusForMediaType?.(mediaType)
|
|
30
|
+
|
|
31
|
+
if (status === 3) {
|
|
32
|
+
return true
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (status === 1 || status === 2) {
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return await new Promise<boolean>((resolve) =>
|
|
40
|
+
av.requestAccessForMediaTypeCompletionHandler(mediaType, resolve),
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (isAndroid) {
|
|
45
|
+
const permission = 'android.permission.CAMERA'
|
|
46
|
+
const activity = Application.android.foregroundActivity ?? Application.android.startActivity
|
|
47
|
+
|
|
48
|
+
if (
|
|
49
|
+
activity?.checkSelfPermission?.(permission) ===
|
|
50
|
+
android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
51
|
+
) {
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!activity) {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return await new Promise<boolean>((resolve) => {
|
|
60
|
+
const currentRequest = requestCode++
|
|
61
|
+
const finish = (granted: boolean) => {
|
|
62
|
+
clearTimeout(timer)
|
|
63
|
+
Application.android.off(Application.android.activityRequestPermissionsEvent, onResult)
|
|
64
|
+
|
|
65
|
+
resolve(granted)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const onResult = (args: any) => {
|
|
69
|
+
if (args.requestCode !== currentRequest) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
finish(args.grantResults?.[0] === android.content.pm.PackageManager.PERMISSION_GRANTED)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Same bound the session adapter uses — an activity destroyed or
|
|
77
|
+
// rotated before the result must not hang the caller or leak the
|
|
78
|
+
// listener.
|
|
79
|
+
const timer = setTimeout(() => finish(false), 120_000)
|
|
80
|
+
|
|
81
|
+
Application.android.on(Application.android.activityRequestPermissionsEvent, onResult)
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
activity.requestPermissions([permission], currentRequest)
|
|
85
|
+
} catch {
|
|
86
|
+
finish(false)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
return false
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return false
|
|
91
95
|
}
|
|
@@ -6,71 +6,74 @@
|
|
|
6
6
|
const windows = () => globalThis as any
|
|
7
7
|
|
|
8
8
|
const toPromise = (op: any): Promise<any> => {
|
|
9
|
-
|
|
10
|
-
if (NSWinRT?.toPromise && op != null) {
|
|
11
|
-
return NSWinRT.toPromise(op)
|
|
12
|
-
}
|
|
9
|
+
const { NSWinRT } = windows()
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
op.done(resolve, reject)
|
|
18
|
-
} catch (cause) {
|
|
19
|
-
reject(cause)
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
}
|
|
11
|
+
if (NSWinRT?.toPromise && op != null) {
|
|
12
|
+
return NSWinRT.toPromise(op)
|
|
13
|
+
}
|
|
23
14
|
|
|
24
|
-
|
|
15
|
+
if (op?.done) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
try {
|
|
18
|
+
op.done(resolve, reject)
|
|
19
|
+
} catch (cause) {
|
|
20
|
+
reject(cause)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return Promise.resolve(op)
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export function cameraHardwarePresent(): boolean {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
const { Windows, Microsoft } = windows()
|
|
30
|
+
|
|
31
|
+
return !!(
|
|
32
|
+
Windows?.Media?.Capture?.MediaCapture &&
|
|
33
|
+
Windows?.Devices?.Enumeration?.DeviceInformation &&
|
|
34
|
+
Microsoft?.UI?.Xaml?.Controls?.CaptureElement
|
|
35
|
+
)
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export async function ensureCameraPermission(): Promise<boolean> {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
try {
|
|
40
|
+
const { Windows } = windows()
|
|
41
|
+
const capability =
|
|
42
|
+
Windows?.Security?.Authorization?.AppCapabilityAccess?.AppCapability?.Create?.('webcam')
|
|
43
|
+
|
|
44
|
+
if (capability) {
|
|
45
|
+
const status = capability.CheckAccess()
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return true
|
|
48
|
-
}
|
|
47
|
+
// AppCapabilityAccessStatus: DeniedBySystem=0, NotDeclaredByApp=1,
|
|
48
|
+
// DeniedByUser=2, UserPromptRequired=3, Allowed=4.
|
|
49
|
+
if (status === 4) {
|
|
50
|
+
return true
|
|
51
|
+
}
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
if (status === 3) {
|
|
54
|
+
return (await toPromise(capability.RequestAccessAsync())) === 4
|
|
55
|
+
}
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const enumeration = Windows?.Devices?.Enumeration
|
|
61
|
+
const deviceClass = enumeration?.DeviceClass?.VideoCapture
|
|
62
|
+
const info =
|
|
63
|
+
deviceClass === undefined
|
|
64
|
+
? undefined
|
|
65
|
+
: enumeration?.DeviceAccessInformation?.CreateFromDeviceClass(deviceClass)
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
if (info) {
|
|
68
|
+
// DeviceAccessStatus: Unspecified=0, Allowed=1, DeniedByUser=2,
|
|
69
|
+
// DeniedBySystem=3. The enumeration API cannot prompt — an
|
|
70
|
+
// Unspecified outcome is resolved by the preview's own
|
|
71
|
+
// InitializeAsync, which runs the OS consent flow.
|
|
72
|
+
return info.CurrentStatus !== 2 && info.CurrentStatus !== 3
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
return false
|
|
76
|
+
}
|
|
74
77
|
|
|
75
|
-
|
|
78
|
+
return false
|
|
76
79
|
}
|
|
@@ -1,65 +1,93 @@
|
|
|
1
|
+
import { observePreviewDisplay, previewLayerDisplaying } from './preview-display.ios'
|
|
2
|
+
|
|
1
3
|
/** Attach an AVFoundation preview layer to a NativeScript UIView host. */
|
|
2
4
|
export function startCameraPreview(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
view: any,
|
|
6
|
+
facing: 'front' | 'back',
|
|
7
|
+
onReady?: () => void,
|
|
8
|
+
onDisplayReady?: () => void,
|
|
6
9
|
): () => void {
|
|
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
|
-
|
|
10
|
+
const av = globalThis as any
|
|
11
|
+
const mediaType = av.AVMediaTypeVideo ?? 'vide'
|
|
12
|
+
const desiredPosition =
|
|
13
|
+
facing === 'front'
|
|
14
|
+
? (av.AVCaptureDevicePositionFront ?? 2)
|
|
15
|
+
: (av.AVCaptureDevicePositionBack ?? 1)
|
|
16
|
+
|
|
17
|
+
const devices = av.AVCaptureDevice.devicesWithMediaType(mediaType)
|
|
18
|
+
let device: any = null
|
|
19
|
+
|
|
20
|
+
for (let index = 0; index < devices.count; index++) {
|
|
21
|
+
const candidate = devices.objectAtIndex(index)
|
|
22
|
+
|
|
23
|
+
if (candidate.position === desiredPosition) {
|
|
24
|
+
device = candidate
|
|
25
|
+
break
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!device) {
|
|
30
|
+
throw new Error('camera unavailable')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const session = av.AVCaptureSession.new()
|
|
34
|
+
const input = av.AVCaptureDeviceInput.deviceInputWithDeviceError(device)
|
|
35
|
+
|
|
36
|
+
if (!input || !session.canAddInput(input)) {
|
|
37
|
+
throw new Error('camera input unavailable')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
session.addInput(input)
|
|
41
|
+
|
|
42
|
+
const layer = av.AVCaptureVideoPreviewLayer.layerWithSession(session)
|
|
43
|
+
|
|
44
|
+
layer.videoGravity = 'resizeAspectFill'
|
|
45
|
+
|
|
46
|
+
const connection = layer.connection
|
|
47
|
+
|
|
48
|
+
if (connection) {
|
|
49
|
+
connection.automaticallyAdjustsVideoMirroring = false
|
|
50
|
+
if (connection.isVideoMirroringSupported) {
|
|
51
|
+
connection.isVideoMirrored = facing === 'front'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const nativeView = view.ios ?? view.nativeViewProtected
|
|
56
|
+
|
|
57
|
+
if (!nativeView?.layer) {
|
|
58
|
+
throw new Error('camera preview host unavailable')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
nativeView.layer.addSublayer(layer)
|
|
62
|
+
|
|
63
|
+
const updateFrame = () => {
|
|
64
|
+
layer.frame = nativeView.bounds
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
view.on?.('layoutChanged', updateFrame)
|
|
68
|
+
updateFrame()
|
|
69
|
+
|
|
70
|
+
let displayReady = false
|
|
71
|
+
const detachDisplay = observePreviewDisplay(layer, () => {
|
|
72
|
+
const showing = previewLayerDisplaying(layer)
|
|
73
|
+
|
|
74
|
+
if (showing === displayReady) {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
displayReady = showing
|
|
79
|
+
if (showing) {
|
|
80
|
+
onDisplayReady?.()
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
session.startRunning()
|
|
85
|
+
onReady?.()
|
|
86
|
+
|
|
87
|
+
return () => {
|
|
88
|
+
view.off?.('layoutChanged', updateFrame)
|
|
89
|
+
detachDisplay?.()
|
|
90
|
+
session.stopRunning()
|
|
91
|
+
layer.removeFromSuperlayer()
|
|
92
|
+
}
|
|
65
93
|
}
|
|
@@ -1,75 +1,77 @@
|
|
|
1
1
|
import '@nativescript/macos-node-api'
|
|
2
|
+
import { createCameraHost } from './camera-host.macos.ts'
|
|
2
3
|
|
|
3
4
|
interface CameraHost {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare const XplatCameraHost: {
|
|
16
|
-
alloc(): { init(): CameraHost }
|
|
5
|
+
attachPreview(view: object): string | null
|
|
6
|
+
detachPreview(): void
|
|
7
|
+
installObserver(emit: (message: string) => void): void
|
|
8
|
+
permissionStatus(kind: string): string
|
|
9
|
+
requestPermissionReply(kind: string, reply: (status: string) => void): void
|
|
10
|
+
devices(): string
|
|
11
|
+
audioDeviceAvailable(): boolean
|
|
12
|
+
configure(options: { cameraId?: string; audio?: boolean; rotationAngle?: number }): string | null
|
|
13
|
+
dispose(): void
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
let helper: CameraHost | undefined
|
|
20
|
-
const helperHost = () => (helper ??=
|
|
17
|
+
const helperHost = () => (helper ??= createCameraHost())
|
|
21
18
|
|
|
22
19
|
export function cameraHardwarePresent(): boolean {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(helperHost().devices()).length > 0
|
|
22
|
+
} catch {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
/** Preview-only permission entry point: prompts once from mount, mirrors the
|
|
31
28
|
* iOS legacy path. Session code should use `session.requestPermission` —
|
|
32
29
|
* explicit actions only. */
|
|
33
30
|
export function ensureCameraPermission(): Promise<boolean> {
|
|
34
|
-
|
|
35
|
-
if (status === 'granted') {
|
|
36
|
-
return Promise.resolve(true)
|
|
37
|
-
}
|
|
31
|
+
const status = helperHost().permissionStatus('camera')
|
|
38
32
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
if (status === 'granted') {
|
|
34
|
+
return Promise.resolve(true)
|
|
35
|
+
}
|
|
42
36
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
if (status === 'undeclared') {
|
|
38
|
+
return Promise.resolve(false)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new Promise((resolve) =>
|
|
42
|
+
helperHost().requestPermissionReply('camera', (next) => resolve(next === 'granted')),
|
|
43
|
+
)
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
/** Legacy preview-only path: a dedicated XplatCameraHost owns the preview
|
|
49
47
|
* session — shared with nothing, disposed with the view. The session-backed
|
|
50
48
|
* path goes through `attachSessionPreview` instead. */
|
|
51
49
|
export function startCameraPreview(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
view: object,
|
|
51
|
+
_facing: 'front' | 'back',
|
|
52
|
+
onReady?: () => void,
|
|
55
53
|
): () => void {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
const host = createCameraHost()
|
|
55
|
+
|
|
56
|
+
host.installObserver(() => {})
|
|
57
|
+
|
|
58
|
+
const configured = host.configure({ audio: false })
|
|
59
|
+
|
|
60
|
+
if (configured) {
|
|
61
|
+
host.dispose()
|
|
62
|
+
throw new Error(`camera unavailable: ${configured}`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const failure = host.attachPreview(view)
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
67
|
+
if (failure) {
|
|
68
|
+
host.dispose()
|
|
69
|
+
throw new Error(`camera unavailable: ${failure}`)
|
|
70
|
+
}
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
onReady?.()
|
|
73
|
+
return () => {
|
|
74
|
+
host.detachPreview()
|
|
75
|
+
host.dispose()
|
|
76
|
+
}
|
|
75
77
|
}
|