@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.
Files changed (67) hide show
  1. package/README.md +2 -132
  2. package/package.json +108 -103
  3. package/platforms/android/java/com/octanexplat/camera/CameraPreviewView.java +24 -0
  4. package/platforms/android/java/com/octanexplat/camera/CameraSessionBridge.java +153 -21
  5. package/platforms/ios/src/XplatSwitchingMovieWriter.swift +557 -0
  6. package/src/CameraView.android.tsrx +194 -118
  7. package/src/CameraView.ios.tsrx +129 -76
  8. package/src/CameraView.macos.tsrx +108 -70
  9. package/src/CameraView.tsrx +2 -0
  10. package/src/CameraView.web.tsrx +160 -125
  11. package/src/CameraView.windows.tsrx +141 -92
  12. package/src/camera-host.macos.ts +1059 -0
  13. package/src/camera-permission.mobile.ts +85 -81
  14. package/src/camera-permission.windows.ts +56 -53
  15. package/src/camera-session.ios.ts +89 -61
  16. package/src/camera-session.macos.ts +51 -49
  17. package/src/camera-session.windows.ts +113 -105
  18. package/src/host-movie.web.ts +266 -222
  19. package/src/index.ts +28 -26
  20. package/src/index.web.ts +27 -25
  21. package/src/layout-child.ts +88 -79
  22. package/src/layout-child.web.ts +57 -51
  23. package/src/layout-child.windows.ts +82 -71
  24. package/src/movie-metadata.web.ts +87 -74
  25. package/src/movie-storage.web.ts +142 -135
  26. package/src/movie-writer.ios.ts +170 -0
  27. package/src/photo-lifecycle.macos.ts +60 -0
  28. package/src/photo-sheet.macos.ts +505 -0
  29. package/src/preview-display.ios.ts +69 -0
  30. package/src/preview-pinch.ts +41 -0
  31. package/src/preview-tap.ts +22 -21
  32. package/src/props.ts +118 -68
  33. package/src/recording-haptics.ios.ts +39 -0
  34. package/src/recording-source.web.ts +159 -0
  35. package/src/session-backend.android.ts +552 -410
  36. package/src/session-backend.ios.ts +1500 -1148
  37. package/src/session-backend.linux.ts +886 -860
  38. package/src/session-backend.macos.ts +697 -679
  39. package/src/session-backend.ts +51 -49
  40. package/src/session-backend.web.ts +1181 -867
  41. package/src/session-backend.windows.ts +1556 -1467
  42. package/src/session-core.ts +925 -711
  43. package/src/session.ts +12 -12
  44. package/src/style-merge.ts +43 -43
  45. package/src/synthetic-session.ts +392 -333
  46. package/src/types.ts +384 -239
  47. package/types/generated/.tsrx-typegen-manifest.json +18 -0
  48. package/types/generated/CameraView.d.ts +2 -0
  49. package/types/generated/CameraView.web.d.ts +4 -0
  50. package/types/generated/camera-host.macos.d.ts +33 -0
  51. package/types/generated/index.d.ts +34 -0
  52. package/types/generated/layout-child.web.d.ts +7 -0
  53. package/types/generated/photo-lifecycle.macos.d.ts +12 -0
  54. package/types/generated/photo-sheet.macos.d.ts +36 -0
  55. package/types/generated/props.d.ts +111 -0
  56. package/types/generated/session-backend.d.ts +6 -0
  57. package/types/{session-core.d.ts → generated/session-core.d.ts} +30 -1
  58. package/types/generated/session.d.ts +16 -0
  59. package/types/{synthetic-session.d.ts → generated/synthetic-session.d.ts} +15 -1
  60. package/types/{types.d.ts → generated/types.d.ts} +145 -2
  61. package/LICENSE +0 -21
  62. package/platforms/macos/src/CameraOwnership.swift +0 -22
  63. package/platforms/macos/src/PhotoCaptureLifecycle.swift +0 -34
  64. package/platforms/macos/src/XplatCameraHost.swift +0 -639
  65. package/platforms/macos/src/XplatPhotoCaptureSheet.swift +0 -192
  66. package/types/index.d.ts +0 -48
  67. 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
- const { NSWinRT } = windows()
11
- if (NSWinRT?.toPromise && op != null) {
12
- return NSWinRT.toPromise(op)
13
- }
14
-
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)
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
- const result: any[] = []
30
- const size = Number(items?.Size ?? items?.Count ?? 0)
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
- return result
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
- view: any,
43
- facing: 'front' | 'back',
44
- onReady?: () => void,
44
+ view: any,
45
+ facing: 'front' | 'back',
46
+ onReady?: () => void,
45
47
  ): Promise<() => Promise<void>> {
46
- const { Windows } = windows()
47
- const enumeration = Windows?.Devices?.Enumeration
48
- const captureApi = Windows?.Media?.Capture
49
- if (!enumeration || !captureApi) {
50
- throw new Error('camera preview unsupported')
51
- }
52
-
53
- const found = await toPromise(
54
- enumeration.DeviceInformation.FindAllAsync(enumeration.DeviceClass.VideoCapture),
55
- )
56
-
57
- const devices = vectorToArray(found)
58
- if (!devices.length) {
59
- throw new Error('camera unavailable')
60
- }
61
-
62
- const wantedPanel = facing === 'front' ? 1 : 2
63
- const device =
64
- devices.find((entry: any) => Number(entry?.EnclosureLocation?.Panel) === wantedPanel) ??
65
- devices[0]
66
-
67
- const settings = new captureApi.MediaCaptureInitializationSettings()
68
- settings.VideoDeviceId = String(device?.Id ?? device?.id ?? '')
69
- settings.StreamingCaptureMode = 0 // Video
70
- const capture = new captureApi.MediaCapture()
71
- try {
72
- await toPromise(capture.InitializeAsync(settings))
73
- } catch (cause) {
74
- try {
75
- capture.Close()
76
- } catch {
77
- try {
78
- capture.Dispose()
79
- } catch {
80
- // GC reclaims the device handle.
81
- }
82
- }
83
-
84
- throw cause instanceof Error ? cause : new Error('camera unavailable')
85
- }
86
-
87
- const element = view?.nativeViewProtected ?? view
88
- element.Source = capture
89
- try {
90
- if (
91
- Number(device?.EnclosureLocation?.Panel) === 1 &&
92
- typeof capture.SetPreviewMirroring === 'function'
93
- ) {
94
- capture.SetPreviewMirroring(true)
95
- }
96
- } catch {
97
- // Mirrored preview is cosmetic.
98
- }
99
-
100
- await toPromise(capture.StartPreviewAsync())
101
- onReady?.()
102
-
103
- return async () => {
104
- try {
105
- element.Source = null
106
- } catch {
107
- // The element may already be gone.
108
- }
109
-
110
- try {
111
- await toPromise(capture.StopPreviewAsync())
112
- } catch {
113
- // The pipeline may already be down.
114
- }
115
-
116
- try {
117
- capture.Close()
118
- } catch {
119
- try {
120
- capture.Dispose()
121
- } catch {
122
- // GC reclaims the device handle.
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
  }