@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
|
@@ -7,120 +7,128 @@
|
|
|
7
7
|
const windows = () => globalThis as any
|
|
8
8
|
|
|
9
9
|
const toPromise = (op: any): Promise<any> => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
const { NSWinRT } = windows()
|
|
11
|
+
|
|
12
|
+
if (NSWinRT?.toPromise && op != null) {
|
|
13
|
+
return NSWinRT.toPromise(op)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (op?.done) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
try {
|
|
19
|
+
op.done(resolve, reject)
|
|
20
|
+
} catch (cause) {
|
|
21
|
+
reject(cause)
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return Promise.resolve(op)
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
const vectorToArray = (items: any): any[] => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
for (let index = 0; index < size; index += 1) {
|
|
32
|
-
result.push(items.GetAt(index))
|
|
33
|
-
}
|
|
30
|
+
const result: any[] = []
|
|
31
|
+
const size = Number(items?.Size ?? items?.Count ?? 0)
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
for (let index = 0; index < size; index += 1) {
|
|
34
|
+
result.push(items.GetAt(index))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
/** Attach a MediaCapture preview to the view's `CaptureElement`.
|
|
39
41
|
* `facing` maps to enclosure panels; desktop cameras without a panel fall
|
|
40
42
|
* back to the OS default — front/back is a preference, never a fabrication. */
|
|
41
43
|
export async function startCameraPreview(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
view: any,
|
|
45
|
+
facing: 'front' | 'back',
|
|
46
|
+
onReady?: () => void,
|
|
45
47
|
): Promise<() => Promise<void>> {
|
|
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
|
-
|
|
48
|
+
const { Windows } = windows()
|
|
49
|
+
const enumeration = Windows?.Devices?.Enumeration
|
|
50
|
+
const captureApi = Windows?.Media?.Capture
|
|
51
|
+
|
|
52
|
+
if (!enumeration || !captureApi) {
|
|
53
|
+
throw new Error('camera preview unsupported')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const found = await toPromise(
|
|
57
|
+
enumeration.DeviceInformation.FindAllAsync(enumeration.DeviceClass.VideoCapture),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const devices = vectorToArray(found)
|
|
61
|
+
|
|
62
|
+
if (!devices.length) {
|
|
63
|
+
throw new Error('camera unavailable')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const wantedPanel = facing === 'front' ? 1 : 2
|
|
67
|
+
const device =
|
|
68
|
+
devices.find((entry: any) => Number(entry?.EnclosureLocation?.Panel) === wantedPanel) ??
|
|
69
|
+
devices[0]
|
|
70
|
+
|
|
71
|
+
const settings = new captureApi.MediaCaptureInitializationSettings()
|
|
72
|
+
|
|
73
|
+
settings.VideoDeviceId = String(device?.Id ?? device?.id ?? '')
|
|
74
|
+
settings.StreamingCaptureMode = 0 // Video
|
|
75
|
+
|
|
76
|
+
const capture = new captureApi.MediaCapture()
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
await toPromise(capture.InitializeAsync(settings))
|
|
80
|
+
} catch (cause) {
|
|
81
|
+
try {
|
|
82
|
+
capture.Close()
|
|
83
|
+
} catch {
|
|
84
|
+
try {
|
|
85
|
+
capture.Dispose()
|
|
86
|
+
} catch {
|
|
87
|
+
// GC reclaims the device handle.
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
throw cause instanceof Error ? cause : new Error('camera unavailable')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const element = view?.nativeViewProtected ?? view
|
|
95
|
+
|
|
96
|
+
element.Source = capture
|
|
97
|
+
try {
|
|
98
|
+
if (
|
|
99
|
+
Number(device?.EnclosureLocation?.Panel) === 1 &&
|
|
100
|
+
typeof capture.SetPreviewMirroring === 'function'
|
|
101
|
+
) {
|
|
102
|
+
capture.SetPreviewMirroring(true)
|
|
103
|
+
}
|
|
104
|
+
} catch {
|
|
105
|
+
// Mirrored preview is cosmetic.
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
await toPromise(capture.StartPreviewAsync())
|
|
109
|
+
onReady?.()
|
|
110
|
+
|
|
111
|
+
return async () => {
|
|
112
|
+
try {
|
|
113
|
+
element.Source = null
|
|
114
|
+
} catch {
|
|
115
|
+
// The element may already be gone.
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
await toPromise(capture.StopPreviewAsync())
|
|
120
|
+
} catch {
|
|
121
|
+
// The pipeline may already be down.
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
capture.Close()
|
|
126
|
+
} catch {
|
|
127
|
+
try {
|
|
128
|
+
capture.Dispose()
|
|
129
|
+
} catch {
|
|
130
|
+
// GC reclaims the device handle.
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
126
134
|
}
|