@octane-xplat/camera 0.19.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 (84) hide show
  1. package/README.md +2 -132
  2. package/package.json +20 -25
  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 +187 -154
  7. package/src/CameraView.ios.tsrx +124 -110
  8. package/src/CameraView.macos.tsrx +103 -96
  9. package/src/CameraView.tsrx +2 -0
  10. package/src/CameraView.web.tsrx +157 -146
  11. package/src/CameraView.windows.tsrx +134 -125
  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 +257 -231
  19. package/src/index.ts +28 -26
  20. package/src/index.web.ts +27 -25
  21. package/src/layout-child.ts +86 -79
  22. package/src/layout-child.web.ts +54 -53
  23. package/src/layout-child.windows.ts +80 -74
  24. package/src/movie-metadata.web.ts +84 -81
  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 +115 -93
  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 +1540 -1467
  42. package/src/session-core.ts +925 -714
  43. package/src/session.ts +12 -12
  44. package/src/style-merge.ts +40 -37
  45. package/src/synthetic-session.ts +391 -339
  46. package/src/types.ts +372 -298
  47. package/types/generated/.tsrx-typegen-manifest.json +4 -24
  48. package/types/generated/CameraView.d.ts +2 -0
  49. package/types/generated/camera-host.macos.d.ts +33 -0
  50. package/types/generated/index.d.ts +27 -26
  51. package/types/generated/photo-lifecycle.macos.d.ts +12 -0
  52. package/types/generated/photo-sheet.macos.d.ts +36 -0
  53. package/types/generated/props.d.ts +24 -2
  54. package/types/generated/session-core.d.ts +30 -1
  55. package/types/generated/synthetic-session.d.ts +7 -0
  56. package/types/generated/types.d.ts +75 -1
  57. package/platforms/macos/src/CameraOwnership.swift +0 -22
  58. package/platforms/macos/src/PhotoCaptureLifecycle.swift +0 -34
  59. package/platforms/macos/src/XplatCameraHost.swift +0 -639
  60. package/platforms/macos/src/XplatPhotoCaptureSheet.swift +0 -192
  61. package/types/generated/CameraView.android.d.ts +0 -9
  62. package/types/generated/CameraView.ios.d.ts +0 -5
  63. package/types/generated/CameraView.macos.d.ts +0 -5
  64. package/types/generated/CameraView.mobile.d.ts +0 -5
  65. package/types/generated/CameraView.windows.d.ts +0 -11
  66. package/types/generated/camera-permission.mobile.d.ts +0 -2
  67. package/types/generated/camera-permission.windows.d.ts +0 -6
  68. package/types/generated/camera-session.ios.d.ts +0 -2
  69. package/types/generated/camera-session.macos.d.ts +0 -10
  70. package/types/generated/camera-session.windows.d.ts +0 -9
  71. package/types/generated/host-movie.web.d.ts +0 -100
  72. package/types/generated/index.web.d.ts +0 -7
  73. package/types/generated/layout-child.d.ts +0 -11
  74. package/types/generated/layout-child.windows.d.ts +0 -13
  75. package/types/generated/movie-metadata.web.d.ts +0 -9
  76. package/types/generated/movie-storage.web.d.ts +0 -5
  77. package/types/generated/preview-tap.d.ts +0 -7
  78. package/types/generated/session-backend.android.d.ts +0 -3
  79. package/types/generated/session-backend.ios.d.ts +0 -5
  80. package/types/generated/session-backend.linux.d.ts +0 -3
  81. package/types/generated/session-backend.macos.d.ts +0 -8
  82. package/types/generated/session-backend.web.d.ts +0 -3
  83. package/types/generated/session-backend.windows.d.ts +0 -37
  84. package/types/generated/style-merge.d.ts +0 -8
@@ -9,48 +9,48 @@ import type { MovieOutput, MovieOutputHandle } from './types'
9
9
  // resolves absent and the adapter keeps its browser storage behavior.
10
10
 
11
11
  export interface CameraHostServices {
12
- camera: {
13
- permissionStatus(options: { kind: string }): Promise<{ status: string }>
14
- requestPermission(options: { kind: string }): Promise<{ status: string }>
15
- movieDirectory(): Promise<{ fileUrl: string | null }>
16
- reserveMoviePath(options: {
17
- fileUrl?: string
18
- container?: string
19
- }): Promise<{ reservation: { fileUrl: string } | null }>
20
- writeMovieFile(options: {
21
- fileUrl: string
22
- base64: string
23
- }): Promise<{ file: { name: string; uri: string } | null }>
24
- movieFileInfo(options: {
25
- fileUrl: string
26
- }): Promise<{ info: { exists: boolean; fileUrl?: string; size?: number } | null }>
27
- readMovieFile(options: { fileUrl: string }): Promise<{ base64: string | null }>
28
- deleteMovieFile(options: { fileUrl: string }): Promise<{ removed: boolean }>
29
- /** Optional chunked variants — a multi-hundred-MB movie must not
30
- * round-trip through the bridge as one base64 payload. Absent on
31
- * hosts built before the chunked contract; detected per client. */
32
- writeMovieFileChunk?(options: {
33
- fileUrl: string
34
- base64: string
35
- final?: boolean
36
- }): Promise<{ file: { name: string; uri: string } | { ok: boolean } | null }>
37
- readMovieFileChunk?(options: {
38
- fileUrl: string
39
- offset: number
40
- length: number
41
- }): Promise<{ base64: string | null }>
42
- }
12
+ camera: {
13
+ permissionStatus(options: { kind: string }): Promise<{ status: string }>
14
+ requestPermission(options: { kind: string }): Promise<{ status: string }>
15
+ movieDirectory(): Promise<{ fileUrl: string | null }>
16
+ reserveMoviePath(options: {
17
+ fileUrl?: string
18
+ container?: string
19
+ }): Promise<{ reservation: { fileUrl: string } | null }>
20
+ writeMovieFile(options: {
21
+ fileUrl: string
22
+ base64: string
23
+ }): Promise<{ file: { name: string; uri: string } | null }>
24
+ movieFileInfo(options: {
25
+ fileUrl: string
26
+ }): Promise<{ info: { exists: boolean; fileUrl?: string; size?: number } | null }>
27
+ readMovieFile(options: { fileUrl: string }): Promise<{ base64: string | null }>
28
+ deleteMovieFile(options: { fileUrl: string }): Promise<{ removed: boolean }>
29
+ /** Optional chunked variants — a multi-hundred-MB movie must not
30
+ * round-trip through the bridge as one base64 payload. Absent on
31
+ * hosts built before the chunked contract; detected per client. */
32
+ writeMovieFileChunk?(options: {
33
+ fileUrl: string
34
+ base64: string
35
+ final?: boolean
36
+ }): Promise<{ file: { name: string; uri: string } | { ok: boolean } | null }>
37
+ readMovieFileChunk?(options: {
38
+ fileUrl: string
39
+ offset: number
40
+ length: number
41
+ }): Promise<{ base64: string | null }>
42
+ }
43
43
  }
44
44
 
45
45
  const requiredMethods = [
46
- 'permissionStatus',
47
- 'requestPermission',
48
- 'movieDirectory',
49
- 'reserveMoviePath',
50
- 'writeMovieFile',
51
- 'movieFileInfo',
52
- 'readMovieFile',
53
- 'deleteMovieFile',
46
+ 'permissionStatus',
47
+ 'requestPermission',
48
+ 'movieDirectory',
49
+ 'reserveMoviePath',
50
+ 'writeMovieFile',
51
+ 'movieFileInfo',
52
+ 'readMovieFile',
53
+ 'deleteMovieFile',
54
54
  ]
55
55
 
56
56
  export type CameraHost = HostClient<CameraHostServices>
@@ -58,27 +58,32 @@ export type CameraHost = HostClient<CameraHostServices>
58
58
  let hostProbe: Promise<CameraHost | null> | undefined
59
59
 
60
60
  const probeHost = async (): Promise<CameraHost | null> => {
61
- try {
62
- const transport = createWebKitTransport()
63
- if (!transport) {
64
- return null
65
- }
66
-
67
- const client = createHostClient<CameraHostServices>(transport)
68
- const capabilities = (await client.capabilities().catch(() => null)) as {
69
- camera?: string[]
70
- } | null
71
-
72
- const methods = capabilities?.camera
73
- if (Array.isArray(methods) && requiredMethods.every((name) => methods.includes(name))) {
74
- return client
75
- }
76
-
77
- client.dispose()
78
- return null
79
- } catch {
80
- return null
81
- }
61
+ try {
62
+ const transport = createWebKitTransport()
63
+
64
+ if (!transport) {
65
+ return null
66
+ }
67
+
68
+ const client = createHostClient<CameraHostServices>(transport)
69
+ const capabilities: unknown = await client.capabilities().catch(() => null)
70
+ const methods =
71
+ typeof capabilities === 'object' &&
72
+ capabilities !== null &&
73
+ 'camera' in capabilities &&
74
+ Array.isArray(capabilities.camera)
75
+ ? capabilities.camera
76
+ : undefined
77
+
78
+ if (Array.isArray(methods) && requiredMethods.every((name) => methods.includes(name))) {
79
+ return client
80
+ }
81
+
82
+ client.dispose()
83
+ return null
84
+ } catch {
85
+ return null
86
+ }
82
87
  }
83
88
 
84
89
  /** The camera-capable desktop host client, or null outside a qualified host.
@@ -86,78 +91,82 @@ const probeHost = async (): Promise<CameraHost | null> => {
86
91
  * transport or capabilities failure, so the next call probes again rather
87
92
  * than sticking 'absent' for the page lifetime. */
88
93
  export async function cameraHost(): Promise<CameraHost | null> {
89
- hostProbe ??= probeHost()
90
- const host = await hostProbe
91
- if (!host) {
92
- hostProbe = probeHost()
93
- return hostProbe
94
- }
95
-
96
- return host
94
+ hostProbe ??= probeHost()
95
+
96
+ const host = await hostProbe
97
+
98
+ if (!host) {
99
+ hostProbe = probeHost()
100
+ return hostProbe
101
+ }
102
+
103
+ return host
97
104
  }
98
105
 
99
106
  const error = (kind: 'destinationUnavailable' | 'storageFailed' | 'unavailable', message: string) =>
100
- new CameraCaptureError({ kind, operation: 'storage', message })
107
+ new CameraCaptureError({ kind, operation: 'storage', message })
101
108
 
102
109
  const dataToBase64 = (data: Uint8Array): string => {
103
- let binary = ''
104
- const chunk = 0x8000
105
- for (let offset = 0; offset < data.length; offset += chunk) {
106
- binary += String.fromCharCode(...data.subarray(offset, offset + chunk))
107
- }
110
+ let binary = ''
111
+ const chunk = 0x8000
108
112
 
109
- return btoa(binary)
113
+ for (let offset = 0; offset < data.length; offset += chunk) {
114
+ binary += String.fromCharCode(...data.subarray(offset, offset + chunk))
115
+ }
116
+
117
+ return btoa(binary)
110
118
  }
111
119
 
112
120
  const blobToBase64 = async (bytes: Blob): Promise<string> =>
113
- dataToBase64(new Uint8Array(await bytes.arrayBuffer()))
121
+ dataToBase64(new Uint8Array(await bytes.arrayBuffer()))
114
122
 
115
123
  const base64ToBlob = (base64: string, type: string): Blob => {
116
- const binary = atob(base64)
117
- const data = new Uint8Array(binary.length)
118
- for (let index = 0; index < binary.length; index++) {
119
- data[index] = binary.charCodeAt(index)
120
- }
124
+ const binary = atob(base64)
125
+ const data = new Uint8Array(binary.length)
126
+
127
+ for (let index = 0; index < binary.length; index++) {
128
+ data[index] = binary.charCodeAt(index)
129
+ }
121
130
 
122
- return new Blob([data], { type })
131
+ return new Blob([data], { type })
123
132
  }
124
133
 
125
134
  const mimeForFileUrl = (fileUrl: string): string =>
126
- fileUrl.endsWith('.webm')
127
- ? 'video/webm'
128
- : fileUrl.endsWith('.mov')
129
- ? 'video/quicktime'
130
- : 'video/mp4'
135
+ fileUrl.endsWith('.webm')
136
+ ? 'video/webm'
137
+ : fileUrl.endsWith('.mov')
138
+ ? 'video/quicktime'
139
+ : 'video/mp4'
131
140
 
132
141
  /** Reserve a host-side movie file. `destinationFileUrl` is validated
133
142
  * host-side: it must be a new file inside the app-private storage root. */
134
143
  export const reserveHostMovie: (
135
- host: CameraHost,
136
- options: {
137
- destinationFileUrl?: string
138
- container?: string
139
- },
144
+ host: CameraHost,
145
+ options: {
146
+ destinationFileUrl?: string
147
+ container?: string
148
+ },
140
149
  ) => Promise<{
141
- fileUrl: string
150
+ fileUrl: string
142
151
  }> = async (
143
- host: CameraHost,
144
- options: { destinationFileUrl?: string; container?: string },
152
+ host: CameraHost,
153
+ options: { destinationFileUrl?: string; container?: string },
145
154
  ): Promise<{ fileUrl: string }> => {
146
- const { reservation } = await host.call('camera', 'reserveMoviePath', {
147
- fileUrl: options.destinationFileUrl,
148
- container: options.container,
149
- })
150
-
151
- if (!reservation?.fileUrl) {
152
- throw error(
153
- 'destinationUnavailable',
154
- options.destinationFileUrl
155
- ? 'destinationFileUrl must be a new file inside the app-private recordings directory'
156
- : 'The host could not allocate a movie recording file',
157
- )
158
- }
159
-
160
- return reservation
155
+ const { reservation } = await host.call('camera', 'reserveMoviePath', {
156
+ fileUrl: options.destinationFileUrl,
157
+ container: options.container,
158
+ })
159
+
160
+ if (!reservation?.fileUrl) {
161
+ throw error(
162
+ 'destinationUnavailable',
163
+ options.destinationFileUrl
164
+ ? 'destinationFileUrl must be a new file inside the app-private recordings directory'
165
+ : 'The host could not allocate a movie recording file',
166
+ )
167
+ }
168
+
169
+ return reservation
161
170
  }
162
171
 
163
172
  /** Bytes bridged per call when the host exposes the chunked movie contract —
@@ -169,145 +178,162 @@ const chunkedSupport = new WeakMap<CameraHost, Promise<boolean>>()
169
178
  /** A host built before the chunked contract lacks the methods entirely —
170
179
  * the capabilities probe answers that without a probe call. */
171
180
  const supportsChunkedMovies = (host: CameraHost): Promise<boolean> => {
172
- let probe = chunkedSupport.get(host)
173
- if (!probe) {
174
- probe = host
175
- .capabilities()
176
- .then((capabilities) => {
177
- const methods = (capabilities as { camera?: string[] }).camera ?? []
178
- return methods.includes('writeMovieFileChunk') && methods.includes('readMovieFileChunk')
179
- })
180
- .catch(() => false)
181
-
182
- chunkedSupport.set(host, probe)
183
- }
184
-
185
- return probe
181
+ let probe = chunkedSupport.get(host)
182
+
183
+ if (!probe) {
184
+ probe = host
185
+ .capabilities()
186
+ .then((capabilities: unknown) => {
187
+ const methods =
188
+ typeof capabilities === 'object' &&
189
+ capabilities !== null &&
190
+ 'camera' in capabilities &&
191
+ Array.isArray(capabilities.camera)
192
+ ? capabilities.camera
193
+ : []
194
+
195
+ return methods.includes('writeMovieFileChunk') && methods.includes('readMovieFileChunk')
196
+ })
197
+ .catch(() => false)
198
+
199
+ chunkedSupport.set(host, probe)
200
+ }
201
+
202
+ return probe
186
203
  }
187
204
 
188
205
  /** Commit finalized movie bytes to host-side app-private storage. Hosts
189
206
  * with the chunked contract stream 4MB slices — a multi-hundred-MB
190
207
  * recording no longer materializes ~3-4x its size across the bridge. */
191
208
  export const commitHostMovie: (
192
- host: CameraHost,
193
- fileUrl: string,
194
- bytes: Blob,
209
+ host: CameraHost,
210
+ fileUrl: string,
211
+ bytes: Blob,
195
212
  ) => Promise<MovieOutput> = async (
196
- host: CameraHost,
197
- fileUrl: string,
198
- bytes: Blob,
213
+ host: CameraHost,
214
+ fileUrl: string,
215
+ bytes: Blob,
199
216
  ): Promise<MovieOutput> => {
200
- if (await supportsChunkedMovies(host)) {
201
- for (let offset = 0; ; offset += MOVIE_CHUNK_BYTES) {
202
- const slice = bytes.slice(offset, offset + MOVIE_CHUNK_BYTES)
203
- const final = offset + MOVIE_CHUNK_BYTES >= bytes.size
204
- const { file } = await host.call('camera', 'writeMovieFileChunk', {
205
- fileUrl,
206
- base64: dataToBase64(new Uint8Array(await slice.arrayBuffer())),
207
- final,
208
- })
209
-
210
- if (final) {
211
- const committed = file && 'uri' in file ? file : null
212
- if (!committed?.uri) {
213
- throw error('storageFailed', 'The host could not write the recorded movie')
214
- }
215
-
216
- return { kind: 'nativeFile', resourceId: committed.uri, fileUrl: committed.uri }
217
- }
218
-
219
- if (!file || !('ok' in file) || file.ok !== true) {
220
- throw error('storageFailed', 'The host could not write a recorded movie chunk')
221
- }
222
- }
223
- }
224
-
225
- const base64 = await blobToBase64(bytes)
226
- const { file } = await host.call('camera', 'writeMovieFile', { fileUrl, base64 })
227
- if (!file?.uri) {
228
- throw error('storageFailed', 'The host could not write the recorded movie')
229
- }
230
-
231
- return { kind: 'nativeFile', resourceId: file.uri, fileUrl: file.uri }
217
+ if (await supportsChunkedMovies(host)) {
218
+ for (let offset = 0; ; offset += MOVIE_CHUNK_BYTES) {
219
+ const slice = bytes.slice(offset, offset + MOVIE_CHUNK_BYTES)
220
+ const final = offset + MOVIE_CHUNK_BYTES >= bytes.size
221
+ const { file } = await host.call('camera', 'writeMovieFileChunk', {
222
+ fileUrl,
223
+ base64: dataToBase64(new Uint8Array(await slice.arrayBuffer())),
224
+ final,
225
+ })
226
+
227
+ if (final) {
228
+ const committed = file && 'uri' in file ? file : null
229
+
230
+ if (!committed?.uri) {
231
+ throw error('storageFailed', 'The host could not write the recorded movie')
232
+ }
233
+
234
+ return { kind: 'nativeFile', resourceId: committed.uri, fileUrl: committed.uri }
235
+ }
236
+
237
+ if (!file || !('ok' in file) || file.ok !== true) {
238
+ throw error('storageFailed', 'The host could not write a recorded movie chunk')
239
+ }
240
+ }
241
+ }
242
+
243
+ const base64 = await blobToBase64(bytes)
244
+ const { file } = await host.call('camera', 'writeMovieFile', { fileUrl, base64 })
245
+
246
+ if (!file?.uri) {
247
+ throw error('storageFailed', 'The host could not write the recorded movie')
248
+ }
249
+
250
+ return { kind: 'nativeFile', resourceId: file.uri, fileUrl: file.uri }
232
251
  }
233
252
 
234
253
  /** Drop an uncommitted host reservation after a failed attempt. */
235
254
  export const removeHostReservation: (host: CameraHost, fileUrl: string) => Promise<void> = async (
236
- host: CameraHost,
237
- fileUrl: string,
255
+ host: CameraHost,
256
+ fileUrl: string,
238
257
  ): Promise<void> => {
239
- await host.call('camera', 'deleteMovieFile', { fileUrl }).catch(() => {})
258
+ await host.call('camera', 'deleteMovieFile', { fileUrl }).catch(() => {})
240
259
  }
241
260
 
242
261
  /** Reopen a host-stored movie as a temporary playback URL. The durable
243
262
  * reference remains `fileUrl`; the returned url lives until `release()`. */
244
263
  export const openHostMovie: (
245
- host: CameraHost,
246
- output: MovieOutput,
264
+ host: CameraHost,
265
+ output: MovieOutput,
247
266
  ) => Promise<MovieOutputHandle> = async (
248
- host: CameraHost,
249
- output: MovieOutput,
267
+ host: CameraHost,
268
+ output: MovieOutput,
250
269
  ): Promise<MovieOutputHandle> => {
251
- if (output.kind !== 'nativeFile' || !output.fileUrl) {
252
- throw new CameraCaptureError({
253
- kind: 'invalidArgument',
254
- operation: 'openOutput',
255
- message: 'Only file-backed output can be opened through the desktop host',
256
- })
257
- }
258
-
259
- const { info } = await host.call('camera', 'movieFileInfo', { fileUrl: output.fileUrl })
260
- if (!info?.exists) {
261
- throw error('unavailable', `Movie file is missing at ${output.fileUrl}`)
262
- }
263
-
264
- const size = Number(info.size ?? -1)
265
- if (size > 0 && (await supportsChunkedMovies(host))) {
266
- const data = new Uint8Array(size)
267
- for (let offset = 0; offset < size; offset += MOVIE_CHUNK_BYTES) {
268
- const { base64: chunk } = await host.call('camera', 'readMovieFileChunk', {
269
- fileUrl: output.fileUrl,
270
- offset,
271
- length: Math.min(MOVIE_CHUNK_BYTES, size - offset),
272
- })
273
-
274
- if (chunk == null) {
275
- throw error('unavailable', `Movie file could not be read at ${output.fileUrl}`)
276
- }
277
-
278
- let decoded: string
279
- try {
280
- decoded = atob(chunk)
281
- } catch {
282
- throw error('unavailable', 'The host returned invalid movie bytes')
283
- }
284
-
285
- if (decoded.length !== Math.min(MOVIE_CHUNK_BYTES, size - offset)) {
286
- throw error('unavailable', 'The stored movie changed or could not be read completely')
287
- }
288
-
289
- for (let index = 0; index < decoded.length; index += 1) {
290
- data[offset + index] = decoded.charCodeAt(index)
291
- }
292
- }
293
-
294
- const url = URL.createObjectURL(new Blob([data], { type: mimeForFileUrl(output.fileUrl) }))
295
- return {
296
- url,
297
- fileUrl: output.fileUrl,
298
- release: () => URL.revokeObjectURL(url),
299
- }
300
- }
301
-
302
- const { base64 } = await host.call('camera', 'readMovieFile', { fileUrl: output.fileUrl })
303
- if (!base64) {
304
- throw error('unavailable', `Movie file could not be read at ${output.fileUrl}`)
305
- }
306
-
307
- const url = URL.createObjectURL(base64ToBlob(base64, mimeForFileUrl(output.fileUrl)))
308
- return {
309
- url,
310
- fileUrl: output.fileUrl,
311
- release: () => URL.revokeObjectURL(url),
312
- }
270
+ if (output.kind !== 'nativeFile' || !output.fileUrl) {
271
+ throw new CameraCaptureError({
272
+ kind: 'invalidArgument',
273
+ operation: 'openOutput',
274
+ message: 'Only file-backed output can be opened through the desktop host',
275
+ })
276
+ }
277
+
278
+ const { info } = await host.call('camera', 'movieFileInfo', { fileUrl: output.fileUrl })
279
+
280
+ if (!info?.exists) {
281
+ throw error('unavailable', `Movie file is missing at ${output.fileUrl}`)
282
+ }
283
+
284
+ const size = Number(info.size ?? -1)
285
+
286
+ if (size > 0 && (await supportsChunkedMovies(host))) {
287
+ const data = new Uint8Array(size)
288
+
289
+ for (let offset = 0; offset < size; offset += MOVIE_CHUNK_BYTES) {
290
+ const { base64: chunk } = await host.call('camera', 'readMovieFileChunk', {
291
+ fileUrl: output.fileUrl,
292
+ offset,
293
+ length: Math.min(MOVIE_CHUNK_BYTES, size - offset),
294
+ })
295
+
296
+ if (chunk == null) {
297
+ throw error('unavailable', `Movie file could not be read at ${output.fileUrl}`)
298
+ }
299
+
300
+ let decoded: string
301
+
302
+ try {
303
+ decoded = atob(chunk)
304
+ } catch {
305
+ throw error('unavailable', 'The host returned invalid movie bytes')
306
+ }
307
+
308
+ if (decoded.length !== Math.min(MOVIE_CHUNK_BYTES, size - offset)) {
309
+ throw error('unavailable', 'The stored movie changed or could not be read completely')
310
+ }
311
+
312
+ for (let index = 0; index < decoded.length; index += 1) {
313
+ data[offset + index] = decoded.charCodeAt(index)
314
+ }
315
+ }
316
+
317
+ const url = URL.createObjectURL(new Blob([data], { type: mimeForFileUrl(output.fileUrl) }))
318
+
319
+ return {
320
+ url,
321
+ fileUrl: output.fileUrl,
322
+ release: () => URL.revokeObjectURL(url),
323
+ }
324
+ }
325
+
326
+ const { base64 } = await host.call('camera', 'readMovieFile', { fileUrl: output.fileUrl })
327
+
328
+ if (!base64) {
329
+ throw error('unavailable', `Movie file could not be read at ${output.fileUrl}`)
330
+ }
331
+
332
+ const url = URL.createObjectURL(base64ToBlob(base64, mimeForFileUrl(output.fileUrl)))
333
+
334
+ return {
335
+ url,
336
+ fileUrl: output.fileUrl,
337
+ release: () => URL.revokeObjectURL(url),
338
+ }
313
339
  }
package/src/index.ts CHANGED
@@ -1,35 +1,37 @@
1
1
  // Keep this relative import extensionless so the NativeScript resolver picks
2
2
  // the iOS or Android component for the current build target.
3
- export { CameraView } from './CameraView'
3
+ export { CameraView } from './CameraView.tsrx'
4
4
  export type { CameraAccessibilityRole, CameraViewHandle, CameraViewProps } from './props'
5
5
  export { createCameraSession } from './session'
6
6
  export { CameraCaptureError } from './types'
7
7
  export type {
8
- CameraCaptureErrorKind,
9
- CameraDeviceInfo,
10
- CameraFacing,
11
- CameraInterruptionReason,
12
- CameraOrientation,
13
- CameraPermissionKind,
14
- CameraPermissionStatus,
15
- CameraPreviewPoint,
16
- CameraProfileCapability,
17
- CameraRecorderState,
18
- CameraSelection,
19
- CameraSession,
20
- CameraSessionCapabilities,
21
- CameraSessionConfig,
22
- CameraSessionEvent,
23
- CameraSessionSnapshot,
24
- CaptureIssue,
25
- EffectiveCaptureConfig,
26
- MovieClip,
27
- MovieEndReason,
28
- MovieOutcome,
29
- MovieOutput,
30
- MovieOutputHandle,
31
- MovieTake,
32
- StartRecordingOptions,
8
+ CameraCaptureErrorKind,
9
+ CameraDeviceInfo,
10
+ CameraFacing,
11
+ CameraInterruptionReason,
12
+ CameraOrientation,
13
+ CameraPermissionKind,
14
+ CameraPermissionStatus,
15
+ CameraPinchEvent,
16
+ CameraPreviewPoint,
17
+ CameraProfileCapability,
18
+ CameraRecorderState,
19
+ CameraSelection,
20
+ CameraSession,
21
+ CameraSessionCapabilities,
22
+ CameraSessionConfig,
23
+ CameraSessionEvent,
24
+ CameraSessionSnapshot,
25
+ CameraZoomState,
26
+ CaptureIssue,
27
+ EffectiveCaptureConfig,
28
+ MovieClip,
29
+ MovieEndReason,
30
+ MovieOutcome,
31
+ MovieOutput,
32
+ MovieOutputHandle,
33
+ MovieTake,
34
+ StartRecordingOptions,
33
35
  } from './types'
34
36
 
35
37
  export { createMemoryCameraStorage, createSyntheticCameraSession } from './synthetic-session'