@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
package/src/types.ts CHANGED
@@ -19,64 +19,69 @@ export type CameraPermissionKind = 'camera' | 'microphone'
19
19
  * `unknown` exist so hosts that cannot distinguish user denial from
20
20
  * policy refusal do not fabricate `restricted`. */
21
21
  export type CameraPermissionStatus =
22
- | 'notDetermined'
23
- | 'granted'
24
- | 'denied'
25
- | 'restricted'
26
- | 'blocked'
27
- | 'unknown'
28
- | 'unavailable'
22
+ | 'notDetermined'
23
+ | 'granted'
24
+ | 'denied'
25
+ | 'restricted'
26
+ | 'blocked'
27
+ | 'unknown'
28
+ | 'unavailable'
29
29
 
30
30
  /** Portable error categories. `unsupported*` covers missing host features,
31
31
  * devices, or capture configurations — including adapters that are not
32
32
  * implemented yet during staged delivery. */
33
33
  export type CameraCaptureErrorKind =
34
- | 'permissionDenied'
35
- | 'permissionRestricted'
36
- | 'permissionBlocked'
37
- | 'unsupportedPlatform'
38
- | 'unsupportedConfiguration'
39
- | 'unavailable'
40
- | 'busy'
41
- | 'invalidState'
42
- | 'invalidArgument'
43
- | 'destinationUnavailable'
44
- | 'insufficientStorage'
45
- | 'noMedia'
46
- | 'captureFailed'
47
- | 'finalizationFailed'
48
- | 'storageFailed'
49
- | 'configurationMissing'
34
+ | 'permissionDenied'
35
+ | 'permissionRestricted'
36
+ | 'permissionBlocked'
37
+ | 'unsupportedPlatform'
38
+ | 'unsupportedConfiguration'
39
+ | 'unavailable'
40
+ | 'busy'
41
+ | 'invalidState'
42
+ | 'invalidArgument'
43
+ | 'destinationUnavailable'
44
+ | 'insufficientStorage'
45
+ | 'noMedia'
46
+ | 'captureFailed'
47
+ | 'finalizationFailed'
48
+ | 'storageFailed'
49
+ | 'configurationMissing'
50
50
 
51
51
  /** Structured diagnostic carried by failures and non-fatal warnings. */
52
52
  export interface CaptureIssue {
53
- kind: CameraCaptureErrorKind
54
- /** Operation being attempted, e.g. 'startRecording', 'finalize'. */
55
- operation: string
56
- message: string
57
- permission?: CameraPermissionKind
58
- /** Host-specific detail for logging; never required for control flow. */
59
- cause?: unknown
53
+ /** Error category discriminator. */
54
+ kind: CameraCaptureErrorKind
55
+ /** Operation being attempted, e.g. 'startRecording', 'finalize'. */
56
+ operation: string
57
+ /** Human-readable failure description. */
58
+ message: string
59
+ /** Camera/mic authorization state. */
60
+ permission?: CameraPermissionKind
61
+ /** Underlying platform error when one exists — diagnostic only, never required for control flow. */
62
+ cause?: unknown
60
63
  }
61
64
 
62
65
  /** Error thrown or settled by the session API. Satisfies `CaptureIssue`
63
66
  * so `error.kind` drives control flow without unwrapping. */
64
67
  export class CameraCaptureError extends Error implements CaptureIssue {
65
- kind: CameraCaptureErrorKind
66
- operation: string
67
- permission?: CameraPermissionKind
68
- cause?: unknown
68
+ kind: CameraCaptureErrorKind
69
+ operation: string
70
+ permission?: CameraPermissionKind
71
+ /** Underlying platform error when one exists — diagnostic only. */
72
+ cause?: unknown
69
73
 
70
- constructor(issue: Omit<CaptureIssue, 'cause'> & { cause?: unknown }) {
71
- super(issue.message)
72
- this.name = 'CameraCaptureError'
73
- this.kind = issue.kind
74
- this.operation = issue.operation
75
- this.permission = issue.permission
76
- this.cause = issue.cause
77
- }
74
+ constructor(issue: Omit<CaptureIssue, 'cause'> & { cause?: unknown }) {
75
+ super(issue.message)
76
+ this.name = 'CameraCaptureError'
77
+ this.kind = issue.kind
78
+ this.operation = issue.operation
79
+ this.permission = issue.permission
80
+ this.cause = issue.cause
81
+ }
78
82
  }
79
83
 
84
+ /** Lens direction vocabulary. */
80
85
  export type CameraFacing = 'front' | 'back'
81
86
 
82
87
  /** A normalized position on the live preview as the user sees it:
@@ -85,273 +90,413 @@ export type CameraFacing = 'front' | 'back'
85
90
  * mirroring. The `CameraView` `onTap` event and
86
91
  * `CameraSession.focusAtPoint` share this space. */
87
92
  export interface CameraPreviewPoint {
88
- x: number
89
- y: number
93
+ /** Focus/exposure point x, normalized 0-1. */
94
+ x: number
95
+ /** Focus/exposure point y, normalized 0-1. */
96
+ y: number
90
97
  }
91
98
 
99
+ /** Normalized pinch on the preview: `scale` is cumulative from gesture
100
+ * start (1 = no change) and `focus` is the focal point in the same
101
+ * preview space as `CameraPreviewPoint`. */
102
+ export interface CameraPinchEvent {
103
+ /** Scale factor relative to gesture start. */
104
+ scale: number
105
+ /** Gesture phase — began → moved → ended/cancelled. */
106
+ state: 'began' | 'moved' | 'ended' | 'cancelled'
107
+ /** Focal point normalized to the preview; falls back to the center when
108
+ * the platform does not report one. */
109
+ focus: CameraPreviewPoint
110
+ }
111
+
112
+ /** Capture orientation vocabulary. */
92
113
  export type CameraOrientation =
93
- | 'portrait'
94
- | 'portraitUpsideDown'
95
- | 'landscapeLeft'
96
- | 'landscapeRight'
97
- | 'unspecified'
114
+ | 'portrait'
115
+ | 'portraitUpsideDown'
116
+ | 'landscapeLeft'
117
+ | 'landscapeRight'
118
+ | 'unspecified'
98
119
 
99
120
  /** Camera selection for `CameraSessionConfig.camera`. Desktop and browser
100
121
  * hosts expose device identities instead of front/back semantics. */
101
122
  export type CameraSelection = 'default' | 'front' | 'back' | { deviceId: string }
102
123
 
124
+ /** Configuration for opening a session. */
103
125
  export interface CameraSessionConfig {
104
- /** Lens or device identity. Default `'default'`: rear when available. */
105
- camera?: CameraSelection
106
- /** Include an audio track; requires microphone permission. Default
107
- * false — silent capture is a deliberate app choice, never a
108
- * fallback from denied microphone access. */
109
- audio?: boolean
110
- /** Capture profile. `'standard'` targets 720p at 30 fps and may select
111
- * a device-supported alternative; the started attempt discloses the
112
- * actual configuration. */
113
- profile?: 'standard'
126
+ /** Lens or device identity. Default `'default'`: rear when available. */
127
+ camera?: CameraSelection
128
+ /** Include an audio track; requires microphone permission. Default
129
+ * false — silent capture is a deliberate app choice, never a
130
+ * fallback from denied microphone access. */
131
+ audio?: boolean
132
+ /** iOS only: allow haptics AND system sounds while this session owns microphone
133
+ * capture (including preview). Other platforms ignore this iOS audio-session
134
+ * policy. Defaults to leaving the existing app policy unchanged. The previous
135
+ * value is restored after the last opted-in camera owner stops audio capture.
136
+ * External audio-session owners must coordinate policy changes with the app. */
137
+ ios?: { allowHapticsAndSystemSoundsDuringRecording?: boolean }
138
+ /** Capture profile. `'standard'` targets 720p at 30 fps and may select
139
+ * a device-supported alternative; the started attempt discloses the
140
+ * actual configuration. */
141
+ profile?: 'standard'
114
142
  }
115
143
 
116
144
  /** Resolution/frame-rate combination advertised by capability discovery.
117
145
  * Entries are supported combinations, not independent lists. */
118
146
  export interface CameraProfileCapability {
119
- profile: 'standard'
120
- width: number
121
- height: number
122
- frameRate: number
147
+ /** Capture profile (resolution/framerate preset). */
148
+ profile: 'standard'
149
+ /** Frame width in pixels. */
150
+ width: number
151
+ /** Frame height in pixels. */
152
+ height: number
153
+ /** Frames per second. */
154
+ frameRate: number
155
+ }
156
+
157
+ /** Live zoom state of the active camera. Ratios are relative to the
158
+ * device's unzoomed field of view: `1` is no zoom. Bounds belong to the
159
+ * currently bound device — a camera swap can change them. */
160
+ export interface CameraZoomState {
161
+ /** Current zoom ratio. */
162
+ zoom: number
163
+ /** Minimum ratio the active device accepts (1, or below 1 when the
164
+ * device switches to a wider constituent camera). */
165
+ minZoom: number
166
+ /** Maximum ratio the active device accepts. */
167
+ maxZoom: number
123
168
  }
124
169
 
170
+ /** One usable camera device. */
125
171
  export interface CameraDeviceInfo {
126
- id: string
127
- label: string
128
- facing?: CameraFacing
172
+ /** Device-stable camera identifier. */
173
+ /** Store-assigned id. */
174
+
175
+ id: string
176
+ /** Human-readable device name. */
177
+ label: string
178
+ /** Lens direction. */
179
+ facing?: CameraFacing
129
180
  }
130
181
 
131
182
  /** What the session's host can do right now. `supported: false` means the
132
183
  * adapter or host cannot record (reason explains); `available` reflects
133
184
  * current hardware/permission state and changes over time. */
134
185
  export interface CameraSessionCapabilities {
135
- supported: boolean
136
- /** Why capture is unsupported or currently unavailable. */
137
- reason?: string
138
- available: boolean
139
- cameras: CameraDeviceInfo[]
140
- profiles: CameraProfileCapability[]
141
- /** The session can add an audio track when permission allows. */
142
- audio: boolean
143
- /** `focusAtPoint` can move autofocus metering on the active camera —
144
- * false on fixed-focus devices (common for front cameras) and on
145
- * platforms without point-of-interest metering. */
146
- focusPointOfInterest: boolean
147
- /** `focusAtPoint` can move auto-exposure metering on the active
148
- * camera. */
149
- exposurePointOfInterest: boolean
150
- /** Fixed orientations the source can lock for a take. */
151
- orientations: CameraOrientation[]
152
- /** `native` enforcement can still overshoot at media boundaries;
153
- * `bestEffort` limits are scheduled and may overshoot more. */
154
- durationLimit: 'native' | 'bestEffort'
155
- /** Where `elapsedMs` comes from while recording. */
156
- elapsedTime: 'nativeMedia' | 'estimated'
157
- output: {
158
- mimeType: string
159
- container: string
160
- /** `appPrivateFile` output survives dispose and app restart;
161
- * `originLocal` is browser storage subject to site-data clearing. */
162
- storage: 'appPrivateFile' | 'originLocal'
163
- /** Accepts an app-supplied `destinationFileUrl` on start. */
164
- destinationFileUrl: boolean
165
- }
186
+ /** A camera backend exists on this leaf. */
187
+ supported: boolean
188
+ /** Why capture is unsupported or currently unavailable. */
189
+ reason?: string
190
+ /** At least one usable camera is present. */
191
+ available: boolean
192
+ /** Detected camera devices. */
193
+ cameras: CameraDeviceInfo[]
194
+ /** Capture profiles the session can run. */
195
+ profiles: CameraProfileCapability[]
196
+ /** The session can add an audio track when permission allows. */
197
+ audio: boolean
198
+ /** Live `switchCamera` preserves the take, continuous requested audio,
199
+ * held video during acquisition, and one output file. False means
200
+ * camera selection is available only through idle `configure`. */
201
+ cameraSwitchDuringRecording: boolean
202
+ /** `focusAtPoint` can move autofocus metering on the active camera —
203
+ * false on fixed-focus devices (common for front cameras) and on
204
+ * platforms without point-of-interest metering. */
205
+ focusPointOfInterest: boolean
206
+ /** `focusAtPoint` can move auto-exposure metering on the active
207
+ * camera. */
208
+ exposurePointOfInterest: boolean
209
+ /** The active camera reports live zoom control through `zoomState`
210
+ * and `setZoom` (`zoomState().maxZoom > minZoom`). */
211
+ zoom: boolean
212
+ /** Fixed orientations the source can lock for a take. */
213
+ orientations: CameraOrientation[]
214
+ /** `native` enforcement can still overshoot at media boundaries;
215
+ * `bestEffort` limits are scheduled and may overshoot more. */
216
+ durationLimit: 'native' | 'bestEffort'
217
+ /** Where `elapsedMs` comes from while recording. */
218
+ elapsedTime: 'nativeMedia' | 'estimated'
219
+ /** Where the clip was written. */
220
+ output: {
221
+ /** Output MIME type. */
222
+ mimeType: string
223
+ /** File container format. */
224
+ container: string
225
+ /** `appPrivateFile` output survives dispose and app restart;
226
+ * `originLocal` is browser storage subject to site-data clearing. */
227
+ storage: 'appPrivateFile' | 'originLocal'
228
+ /** Accepts an app-supplied `destinationFileUrl` on start. */
229
+ destinationFileUrl: boolean
230
+ }
166
231
  }
167
232
 
233
+ /** Recorder lifecycle states. */
168
234
  export type CameraRecorderState = 'idle' | 'starting' | 'recording' | 'finalizing' | 'disposed'
169
235
 
170
236
  /** Frozen capture configuration reported once capture actually begins. */
171
237
  export interface EffectiveCaptureConfig {
172
- cameraId: string
173
- facing?: CameraFacing
174
- audio: boolean
175
- width: number
176
- height: number
177
- frameRate: number
178
- orientation: CameraOrientation
179
- mimeType: string
180
- container: string
238
+ /** The CameraDeviceInfo.id in use. */
239
+ cameraId: string
240
+ /** Lens direction. */
241
+ facing?: CameraFacing
242
+ /** Whether audio capture is enabled for video. */
243
+ audio: boolean
244
+ /** Frame width in pixels. */
245
+ width: number
246
+ /** Frame height in pixels. */
247
+ height: number
248
+ /** Frames per second. */
249
+ frameRate: number
250
+ /** Capture orientation. */
251
+ orientation: CameraOrientation
252
+ /** Output MIME type. */
253
+ mimeType: string
254
+ /** File container format. */
255
+ container: string
181
256
  }
182
257
 
258
+ /** Observable session state. */
183
259
  export interface CameraSessionSnapshot {
184
- state: CameraRecorderState
185
- /** Non-prompting last-known authorization, refreshed by `permissions()`
186
- * and `requestPermission()`. */
187
- permission: Record<CameraPermissionKind, CameraPermissionStatus>
188
- /** Camera hardware/driver availability, separate from recorder state. */
189
- cameraAvailable: boolean
190
- /** An active preview view is attached to this session. */
191
- previewAttached: boolean
192
- interrupted: boolean
193
- attempt?: {
194
- id: string
195
- state: 'starting' | 'recording' | 'finalizing'
196
- elapsedMs: number
197
- configuration?: EffectiveCaptureConfig
198
- }
260
+ /** A live switch is pending. Recorder state remains `recording`. */
261
+ switchingCamera: boolean
262
+ /** Latest camera confirmed by a started take or successful live switch.
263
+ * The attempt configuration remains the immutable starting config. */
264
+ activeCamera?: CameraDeviceInfo
265
+ /** Current lifecycle state. */
266
+ state: CameraRecorderState
267
+ /** Non-prompting last-known authorization, refreshed by `permissions()`
268
+ * and `requestPermission()`. */
269
+ permission: Record<CameraPermissionKind, CameraPermissionStatus>
270
+ /** Camera hardware/driver availability, separate from recorder state. */
271
+ cameraAvailable: boolean
272
+ /** An active preview view is attached to this session. */
273
+ previewAttached: boolean
274
+ /** Interrupted by the OS (call, route change, …). */
275
+ interrupted: boolean
276
+ /** Retry count for the current operation. */
277
+ attempt?: {
278
+ /** Device-stable camera identifier. */
279
+ id: string
280
+ /** Current lifecycle state. */
281
+ state: 'starting' | 'recording' | 'finalizing'
282
+ elapsedMs: number
283
+ configuration?: EffectiveCaptureConfig
284
+ }
199
285
  }
200
286
 
201
287
  /** What ended a capture attempt. `interrupted` covers system suspension
202
288
  * and preview teardown; `previewReleased` distinguishes an app-driven
203
289
  * deactivation from an OS interruption. */
204
290
  export type MovieEndReason =
205
- | 'stopped'
206
- | 'maximumDuration'
207
- | 'interrupted'
208
- | 'backgrounded'
209
- | 'cameraUnavailable'
210
- | 'previewReleased'
211
- | 'disposed'
212
- | 'captureError'
291
+ | 'stopped'
292
+ | 'maximumDuration'
293
+ | 'interrupted'
294
+ | 'backgrounded'
295
+ | 'cameraUnavailable'
296
+ | 'previewReleased'
297
+ | 'disposed'
298
+ | 'captureError'
213
299
 
214
300
  /** Portable completed-output reference. `resourceId` reopens the clip
215
301
  * through `openOutput`; `fileUrl` additionally guarantees file-backed
216
302
  * native output. `synthetic` marks test-seam clips. */
217
303
  export type MovieOutput =
218
- | {
219
- kind: 'nativeFile'
220
- resourceId: string
221
- fileUrl: string
222
- synthetic?: boolean
223
- }
224
- | {
225
- kind: 'browserStorage'
226
- resourceId: string
227
- retention: 'persistent' | 'bestEffort'
228
- synthetic?: boolean
229
- }
304
+ | {
305
+ /** Error category discriminator. */
306
+ kind: 'nativeFile'
307
+ /** Store handle for the clip (gallery/native ref). */
308
+ resourceId: string
309
+ /** Filesystem URL of the written clip. */
310
+ /** Filesystem URL of the written clip. */
311
+
312
+ fileUrl: string
313
+ /** True for generated/test clips, not real captures. */
314
+ synthetic?: boolean
315
+ }
316
+ | {
317
+ /** Error category discriminator. */
318
+ kind: 'browserStorage'
319
+ /** Store handle for the clip (gallery/native ref). */
320
+ resourceId: string
321
+ retention: 'persistent' | 'bestEffort'
322
+ /** True for generated/test clips, not real captures. */
323
+ synthetic?: boolean
324
+ }
230
325
 
326
+ /** One finished recording. */
231
327
  export interface MovieClip {
232
- output: MovieOutput
233
- mimeType: string
234
- /** Authoritative duration read from the finalized movie. */
235
- durationMs: number
236
- /** Presentation dimensions after the orientation transform. */
237
- width: number
238
- height: number
239
- orientation: CameraOrientation
240
- /** Whether the finalized movie actually contains an audio track.
241
- * Missing requested audio is a failure, not silent capture. */
242
- hasAudio: boolean
328
+ /** Where the clip was written. */
329
+ output: MovieOutput
330
+ /** Output MIME type. */
331
+ mimeType: string
332
+ /** Authoritative duration read from the finalized movie. */
333
+ durationMs: number
334
+ /** Presentation dimensions after the orientation transform. */
335
+ width: number
336
+ /** Frame height in pixels. */
337
+ height: number
338
+ /** Capture orientation. */
339
+ orientation: CameraOrientation
340
+ /** Whether the finalized movie actually contains an audio track.
341
+ * Missing requested audio is a failure, not silent capture. */
342
+ hasAudio: boolean
243
343
  }
244
344
 
245
345
  /** One immutable terminal result per admitted attempt. `partial` marks a
246
346
  * usable clip ended early by an external condition — still a success;
247
347
  * app review decides whether to keep it. */
248
348
  export type MovieOutcome =
249
- | {
250
- kind: 'clip'
251
- clip: MovieClip
252
- endReason: MovieEndReason
253
- partial: boolean
254
- warning?: CaptureIssue
255
- }
256
- | {
257
- kind: 'failed'
258
- endReason: MovieEndReason
259
- stage: 'preparation' | 'capture' | 'finalization' | 'storage'
260
- error: CaptureIssue
261
- }
349
+ | {
350
+ /** Error category discriminator. */
351
+ kind: 'clip'
352
+ clip: MovieClip
353
+ /** Why recording stopped. */
354
+ endReason: MovieEndReason
355
+ partial: boolean
356
+ warning?: CaptureIssue
357
+ }
358
+ | {
359
+ /** Error category discriminator. */
360
+ kind: 'failed'
361
+ /** Why recording stopped. */
362
+ endReason: MovieEndReason
363
+ stage: 'preparation' | 'capture' | 'finalization' | 'storage'
364
+ error: CaptureIssue
365
+ }
262
366
 
263
367
  /** Ordered lifecycle observation, correlated to an attempt when relevant. */
264
368
  export type CameraSessionEvent =
265
- | { type: 'stateChanged'; snapshot: CameraSessionSnapshot }
266
- | { type: 'started'; attemptId: string; configuration: EffectiveCaptureConfig }
267
- | { type: 'finished'; attemptId: string; outcome: MovieOutcome }
268
- | {
269
- type: 'interruption'
270
- phase: 'began' | 'ended'
271
- reason?: CameraInterruptionReason
272
- }
273
- | { type: 'availability'; available: boolean }
369
+ | { type: 'stateChanged'; snapshot: CameraSessionSnapshot }
370
+ | { type: 'started'; attemptId: string; configuration: EffectiveCaptureConfig }
371
+ | { type: 'finished'; attemptId: string; outcome: MovieOutcome }
372
+ | {
373
+ /** Output kind discriminator. */
374
+ type: 'interruption'
375
+ phase: 'began' | 'ended'
376
+ reason?: CameraInterruptionReason
377
+ }
378
+ | { type: 'availability'; available: boolean }
274
379
 
380
+ /** Why the OS interrupted capture. */
275
381
  export type CameraInterruptionReason =
276
- | 'background'
277
- | 'audioInUse'
278
- | 'cameraInUse'
279
- | 'multitasking'
280
- | 'systemPressure'
281
- | 'unknown'
382
+ | 'background'
383
+ | 'audioInUse'
384
+ | 'cameraInUse'
385
+ | 'multitasking'
386
+ | 'systemPressure'
387
+ | 'unknown'
282
388
 
389
+ /** Options for session.startRecording(). */
283
390
  export interface StartRecordingOptions {
284
- /** Positive finite milliseconds. Enforcement precision comes from
285
- * `capabilities().durationLimit`; the final duration is read from
286
- * the movie and may overshoot. */
287
- maximumDurationMs?: number
288
- /** Fixed orientation for the take. Must appear in
289
- * `capabilities().orientations`; omit for the source default. */
290
- orientation?: CameraOrientation
291
- /** App-supplied writable local `file://` URL (native hosts only,
292
- * where `capabilities().output.destinationFileUrl` is true).
293
- * Existing files are never overwritten. */
294
- destinationFileUrl?: string
391
+ /** Positive finite milliseconds. Enforcement precision comes from
392
+ * `capabilities().durationLimit`; the final duration is read from
393
+ * the movie and may overshoot. */
394
+ maximumDurationMs?: number
395
+ /** Fixed orientation for the take. Must appear in
396
+ * `capabilities().orientations`; omit for the source default. */
397
+ orientation?: CameraOrientation
398
+ /** App-supplied writable local `file://` URL (native hosts only,
399
+ * where `capabilities().output.destinationFileUrl` is true).
400
+ * Existing files are never overwritten. */
401
+ destinationFileUrl?: string
295
402
  }
296
403
 
297
404
  /** One admitted capture attempt. `completion` is available immediately and
298
405
  * settles exactly once with the terminal outcome; repeated `stop()`
299
406
  * joins the same finalization. */
300
407
  export interface MovieTake {
301
- readonly id: string
302
- readonly state: 'starting' | 'recording' | 'finalizing' | 'settled'
303
- /** Elapsed capture time in milliseconds; excludes preparation and
304
- * finalization. Source identified by `capabilities().elapsedTime`. */
305
- readonly elapsedMs: number
306
- readonly completion: Promise<MovieOutcome>
307
- /** Requests stop and joins finalization. Returns `completion`. */
308
- stop(): Promise<MovieOutcome>
408
+ /** Attempt identifier — unique per `startRecording` call. */
409
+ readonly id: string
410
+ /** Lifecycle phase; terminal value is `settled` (check `completion` for the outcome). */
411
+ readonly state: 'starting' | 'recording' | 'finalizing' | 'settled'
412
+ /** Elapsed capture time in milliseconds; excludes preparation and
413
+ * finalization. Source identified by `capabilities().elapsedTime`. */
414
+ readonly elapsedMs: number
415
+ /** Terminal outcome — resolves exactly once; `stop()` returns this same promise. */
416
+ readonly completion: Promise<MovieOutcome>
417
+ /** Requests stop and joins finalization. Returns `completion`. */
418
+ stop(): Promise<MovieOutcome>
309
419
  }
310
420
 
311
421
  /** Reopened access to a stored clip. `release()` frees temporary access;
312
422
  * it never deletes the clip. */
313
423
  export interface MovieOutputHandle {
314
- /** Playable/readable location for the clip. */
315
- readonly url: string
316
- readonly fileUrl?: string
317
- release(): void
424
+ /** Playable/readable location for the clip. */
425
+ readonly url: string
426
+ /** On-disk path when the clip is file-backed; absent for memory/remote storage. */
427
+ readonly fileUrl?: string
428
+ /** Free temporary access to the clip — never deletes it. */
429
+ release(): void
318
430
  }
319
431
 
432
+ /** An owned camera session — dispose when done. */
320
433
  export interface CameraSession {
321
- /** Non-prompting permission inspection; may return `unknown` when the
322
- * host cannot observe authorization. */
323
- permissions(): Promise<Record<CameraPermissionKind, CameraPermissionStatus>>
324
- /** Runs the system authorization flow for one kind. Calls are
325
- * serialized; a status other than `notDetermined` returns without
326
- * prompting. */
327
- requestPermission(kind: CameraPermissionKind): Promise<CameraPermissionStatus>
328
- capabilities(): Promise<CameraSessionCapabilities>
329
- snapshot(): CameraSessionSnapshot
330
- /** Ordered lifecycle events. A caller never loses a result by
331
- * subscribing late — `completion` is authoritative. Listener
332
- * exceptions do not change capture. */
333
- subscribe(listener: (event: CameraSessionEvent) => void): () => void
334
- /** Tap-to-focus: meters one autofocus/auto-exposure pass at a
335
- * normalized preview-space point (see `CameraPreviewPoint`), pairing
336
- * with the `CameraView` `onTap` event. No-ops while no preview is
337
- * attached, after `dispose`, and on hosts without point-of-interest
338
- * metering — `capabilities()` reports `focusPointOfInterest` and
339
- * `exposurePointOfInterest` separately. Out-of-range coordinates
340
- * clamp to the preview edge; non-finite coordinates throw
341
- * `invalidArgument`. Metering is per-device state: a camera swap
342
- * through `configure` returns focus/exposure to the new device's
343
- * default. */
344
- focusAtPoint(point: CameraPreviewPoint): void
345
- /** Replaces configuration while idle. Validates against current
346
- * capabilities and rejects with `invalidState` during an attempt. */
347
- configure(config: Partial<CameraSessionConfig>): Promise<void>
348
- /** Admits one capture attempt. Throws `CameraCaptureError` before
349
- * admission for invalid arguments, busy, invalid state, or
350
- * unavailable camera — no attempt is created. */
351
- startRecording(options?: StartRecordingOptions): MovieTake
352
- /** Reopens a stored output for playback or reading. */
353
- openOutput(output: MovieOutput): Promise<MovieOutputHandle>
354
- /** Requests stop on any active attempt, awaits finalization, then
355
- * releases camera ownership. */
356
- dispose(): Promise<void>
434
+ /** Non-prompting permission inspection; may return `unknown` when the
435
+ * host cannot observe authorization. */
436
+ permissions(): Promise<Record<CameraPermissionKind, CameraPermissionStatus>>
437
+ /** Runs the system authorization flow for one kind. Calls are
438
+ * serialized; a status other than `notDetermined` returns without
439
+ * prompting. */
440
+ requestPermission(kind: CameraPermissionKind): Promise<CameraPermissionStatus>
441
+ /** Hardware/OS limits for this session — polled live, so values can change as devices come and go. */
442
+ capabilities(): Promise<CameraSessionCapabilities>
443
+ /** Point-in-time session state — subscribe for changes. */
444
+ snapshot(): CameraSessionSnapshot
445
+ /** Ordered lifecycle events. A caller never loses a result by
446
+ * subscribing late — `completion` is authoritative. Listener
447
+ * exceptions do not change capture. */
448
+ subscribe(listener: (event: CameraSessionEvent) => void): () => void
449
+ /** Tap-to-focus: meters one autofocus/auto-exposure pass at a
450
+ * normalized preview-space point (see `CameraPreviewPoint`), pairing
451
+ * with the `CameraView` `onTap` event. No-ops while no preview is
452
+ * attached, after `dispose`, and on hosts without point-of-interest
453
+ * metering — `capabilities()` reports `focusPointOfInterest` and
454
+ * `exposurePointOfInterest` separately. Out-of-range coordinates
455
+ * clamp to the preview edge; non-finite coordinates throw
456
+ * `invalidArgument`. Metering is per-device state: a camera swap
457
+ * through `configure` returns focus/exposure to the new device's
458
+ * default. */
459
+ focusAtPoint(point: CameraPreviewPoint): void
460
+ /** Live zoom state of the active camera (see `CameraZoomState`).
461
+ * Returns `undefined` while no camera is bound, after `dispose`, and
462
+ * on hosts or devices without zoom control — check
463
+ * `capabilities().zoom` before showing zoom UI. Values change with
464
+ * the bound device: re-read after `configure` or `switchCamera`. */
465
+ zoomState(): CameraZoomState | undefined
466
+ /** Writes a zoom ratio on the active camera without reconfiguring the
467
+ * session; works while recording. Values clamp to the active
468
+ * device's live `zoomState()` bounds on every write. No-ops while no
469
+ * camera is bound, after `dispose`, and on hosts without zoom
470
+ * control. Non-finite values throw `invalidArgument`. */
471
+ setZoom(ratio: number): void
472
+ /** Replaces configuration while idle. Validates against current
473
+ * capabilities and rejects with `invalidState` during an attempt,
474
+ * including one admitted while capability discovery was pending.
475
+ * Live camera changes use `switchCamera` when advertised; rejection
476
+ * leaves the take running and does not request stop. */
477
+ configure(config: Partial<CameraSessionConfig>): Promise<void>
478
+ /** Change only the camera during `recording`. Audio and elapsed time
479
+ * continue while video holds its last frame. Resolves when the replacement
480
+ * camera is producing frames on the existing recording path; this is source
481
+ * readiness, not an encoded-frame acknowledgement. Completion still belongs
482
+ * to the original take. Rejects `busy` for overlapping switches,
483
+ * `invalidState` outside recording, and `unsupportedConfiguration`
484
+ * when the host cannot preserve this contract. Use idle `configure`
485
+ * before starting a take. Cancellation never restarts recording.
486
+ * @example
487
+ * import type { CameraSession } from '@octane-xplat/camera'
488
+ * async function faceFront(session: CameraSession): Promise<void> {
489
+ * await session.switchCamera('front')
490
+ * }
491
+ */
492
+ switchCamera(camera: CameraSelection): Promise<void>
493
+ /** Admits one capture attempt. Throws `CameraCaptureError` before
494
+ * admission for invalid arguments, busy, invalid state, or
495
+ * unavailable camera — no attempt is created. */
496
+ startRecording(options?: StartRecordingOptions): MovieTake
497
+ /** Reopens a stored output for playback or reading. */
498
+ openOutput(output: MovieOutput): Promise<MovieOutputHandle>
499
+ /** Requests stop on any active attempt, awaits finalization, then
500
+ * releases camera ownership. */
501
+ dispose(): Promise<void>
357
502
  }