@octane-xplat/camera 0.12.0 → 0.14.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 (83) hide show
  1. package/README.md +63 -3
  2. package/dist/linux/CameraView.web.tsrx.js +337 -0
  3. package/dist/linux/host-movie.web.js +100 -0
  4. package/dist/linux/index.js +5 -0
  5. package/dist/linux/layout-child.web.js +29 -0
  6. package/dist/linux/movie-metadata.web.js +65 -0
  7. package/dist/linux/octane-client-build.json +8 -0
  8. package/dist/linux/session-backend.linux.js +479 -0
  9. package/dist/linux/session-core.js +368 -0
  10. package/dist/linux/session.js +29 -0
  11. package/dist/linux/synthetic-session.js +280 -0
  12. package/dist/linux/types.js +19 -0
  13. package/dist/native/CameraView.android.js +25 -1
  14. package/dist/native/CameraView.ios.js +24 -1
  15. package/dist/native/CameraView.windows.js +173 -0
  16. package/dist/native/camera-permission.windows.js +43 -0
  17. package/dist/native/camera-session.windows.js +78 -0
  18. package/dist/native/cx.mobile.js +3 -2
  19. package/dist/native/cx.windows.js +9 -0
  20. package/dist/native/index.js +4 -1
  21. package/dist/native/layout-child.windows.js +53 -0
  22. package/dist/native/octane-client-build.json +1 -1
  23. package/dist/native/session-backend.android.js +234 -0
  24. package/dist/native/session-backend.ios.js +682 -0
  25. package/dist/native/session-backend.js +55 -0
  26. package/dist/native/session-backend.windows.js +905 -0
  27. package/dist/native/session-core.js +368 -0
  28. package/dist/native/session.js +29 -0
  29. package/dist/native/synthetic-session.js +280 -0
  30. package/dist/native/types.js +19 -0
  31. package/dist/web/CameraView.web.tsrx.js +28 -8
  32. package/dist/web/host-movie.web.js +100 -0
  33. package/dist/web/index.js +4 -1
  34. package/dist/web/movie-metadata.web.js +65 -0
  35. package/dist/web/movie-storage.web.js +119 -0
  36. package/dist/web/octane-client-build.json +1 -1
  37. package/dist/web/session-backend.web.js +490 -0
  38. package/dist/web/session-core.js +368 -0
  39. package/dist/web/session.js +29 -0
  40. package/dist/web/synthetic-session.js +280 -0
  41. package/dist/web/types.js +19 -0
  42. package/package.json +23 -5
  43. package/platforms/android/AndroidManifest.xml +2 -0
  44. package/platforms/android/include.gradle +1 -0
  45. package/platforms/android/java/com/octanexplat/camera/CameraPreviewView.java +4 -0
  46. package/platforms/android/java/com/octanexplat/camera/CameraSessionBridge.java +363 -0
  47. package/platforms/ios/Info.plist +2 -0
  48. package/platforms/macos/src/XplatCameraHost.swift +513 -0
  49. package/src/CameraView.android.tsrx +21 -1
  50. package/src/CameraView.ios.tsrx +28 -2
  51. package/src/CameraView.macos.tsrx +93 -0
  52. package/src/CameraView.web.tsrx +20 -2
  53. package/src/CameraView.windows.tsrx +124 -0
  54. package/src/camera-permission.windows.ts +76 -0
  55. package/src/camera-session.macos.ts +75 -0
  56. package/src/camera-session.windows.ts +123 -0
  57. package/src/cx.macos.ts +5 -0
  58. package/src/cx.mobile.ts +3 -2
  59. package/src/cx.windows.ts +6 -0
  60. package/src/host-movie.web.ts +180 -0
  61. package/src/index.ts +31 -0
  62. package/src/index.web.ts +31 -0
  63. package/src/layout-child.windows.ts +79 -0
  64. package/src/movie-metadata.web.ts +84 -0
  65. package/src/movie-storage.web.ts +164 -0
  66. package/src/props.ts +7 -1
  67. package/src/session-backend.android.ts +397 -0
  68. package/src/session-backend.ios.ts +1092 -0
  69. package/src/session-backend.linux.ts +869 -0
  70. package/src/session-backend.macos.ts +624 -0
  71. package/src/session-backend.ts +57 -0
  72. package/src/session-backend.web.ts +874 -0
  73. package/src/session-backend.windows.ts +1517 -0
  74. package/src/session-core.ts +659 -0
  75. package/src/session.ts +37 -0
  76. package/src/synthetic-session.ts +367 -0
  77. package/src/types.ts +329 -0
  78. package/types/index.d.ts +43 -0
  79. package/types/props.d.ts +7 -1
  80. package/types/session-core.d.ts +129 -0
  81. package/types/synthetic-session.d.ts +48 -0
  82. package/types/types.d.ts +263 -0
  83. package/src/CameraView.windows.ts +0 -5
@@ -0,0 +1,234 @@
1
+ import { CameraCaptureError } from "./types.js";
2
+ import { Application } from "@nativescript/core";
3
+ //#region src/session-backend.android.ts
4
+ var requestCode = 7820;
5
+ var permissionChain = Promise.resolve();
6
+ var owner;
7
+ var nativeBridge = () => globalThis.com?.octanexplat?.camera?.CameraSessionBridge;
8
+ var permissionName = (kind) => kind === "camera" ? "android.permission.CAMERA" : "android.permission.RECORD_AUDIO";
9
+ var error = (kind, operation, message, cause) => new CameraCaptureError({
10
+ kind,
11
+ operation,
12
+ message,
13
+ cause
14
+ });
15
+ var context = () => Application.android.context;
16
+ var preferences = () => context().getSharedPreferences("octane-camera-permissions", 0);
17
+ async function checkPermission(kind) {
18
+ const activity = Application.android.foregroundActivity ?? Application.android.startActivity;
19
+ if (!activity) return "unavailable";
20
+ const permission = permissionName(kind);
21
+ if (activity.checkSelfPermission(permission) === 0) return "granted";
22
+ return preferences().getBoolean(kind, false) ? activity.shouldShowRequestPermissionRationale(permission) ? "denied" : "blocked" : "notDetermined";
23
+ }
24
+ function requestPermission(kind) {
25
+ const result = permissionChain.then(async () => {
26
+ const status = await checkPermission(kind);
27
+ if (status !== "notDetermined") return status;
28
+ const activity = Application.android.foregroundActivity ?? Application.android.startActivity;
29
+ if (!activity) return "unavailable";
30
+ return new Promise((resolve) => {
31
+ const code = requestCode++;
32
+ const finish = (value) => {
33
+ clearTimeout(timer);
34
+ Application.android.off(Application.android.activityRequestPermissionsEvent, onResult);
35
+ resolve(value);
36
+ };
37
+ const onResult = (args) => {
38
+ if (args.requestCode !== code) return;
39
+ if (!args.grantResults?.length) {
40
+ finish("unknown");
41
+ return;
42
+ }
43
+ preferences().edit().putBoolean(kind, true).apply();
44
+ finish(args.grantResults[0] === 0 ? "granted" : activity.shouldShowRequestPermissionRationale(permissionName(kind)) ? "denied" : "blocked");
45
+ };
46
+ const timer = setTimeout(() => finish("unknown"), 12e4);
47
+ Application.android.on(Application.android.activityRequestPermissionsEvent, onResult);
48
+ try {
49
+ activity.requestPermissions([permissionName(kind)], code);
50
+ } catch {
51
+ finish("unavailable");
52
+ }
53
+ });
54
+ });
55
+ permissionChain = result.catch(() => {});
56
+ return result;
57
+ }
58
+ function createSessionBackend(config) {
59
+ let currentConfig = { ...config };
60
+ let observer;
61
+ let bridge;
62
+ let host;
63
+ let listener;
64
+ let sink;
65
+ let released = false;
66
+ const lease = {};
67
+ const selected = () => typeof currentConfig.camera === "object" ? `id:${currentConfig.camera.deviceId}` : currentConfig.camera ?? "default";
68
+ const releaseLease = () => {
69
+ if (owner === lease) owner = void 0;
70
+ };
71
+ const onSuspend = () => bridge?.background();
72
+ const onResume = () => bridge?.foreground();
73
+ const ensureBridge = () => {
74
+ if (bridge) return;
75
+ const Bridge = nativeBridge();
76
+ if (!Bridge) throw error("unsupportedPlatform", "preview", "CameraX video bridge is missing from the native build");
77
+ bridge = new Bridge(context(), new Bridge.Listener({ event(type, payload) {
78
+ if (type === "ready") {
79
+ observer?.previewReady(payload === "true");
80
+ if (payload === "true") listener?.onReady?.();
81
+ } else if (type === "availability") observer?.availability(payload === "true");
82
+ else if (type === "interruption") observer?.interruption("began", payload);
83
+ else if (type === "recovered") observer?.interruption("ended", payload);
84
+ else if (type === "previewError") {
85
+ observer?.availability(false);
86
+ listener?.onError?.(error("unavailable", "preview", payload));
87
+ if (!host) releaseLease();
88
+ } else if (type === "finishing") sink?.finishing(payload ? payload : void 0);
89
+ else if (type === "started") sink?.started(JSON.parse(payload));
90
+ else if (type === "finished" || type === "failed") {
91
+ const target = sink;
92
+ sink = void 0;
93
+ if (!host) releaseLease();
94
+ const result = JSON.parse(payload);
95
+ target?.settled(type === "finished" ? result : {
96
+ kind: "failed",
97
+ stage: result.stage,
98
+ issue: error(result.kind, result.stage, result.message)
99
+ });
100
+ }
101
+ } }));
102
+ Application.on(Application.suspendEvent, onSuspend);
103
+ Application.on(Application.resumeEvent, onResume);
104
+ };
105
+ return {
106
+ platform: "android",
107
+ get supported() {
108
+ return !!nativeBridge();
109
+ },
110
+ checkPermission,
111
+ requestPermission: async (kind) => {
112
+ const status = await requestPermission(kind);
113
+ if (kind === "camera" && status === "granted" && host && !sink && !released && !bridge?.isReady()) try {
114
+ ensureBridge();
115
+ bridge.attach(host, selected());
116
+ } catch (cause) {
117
+ observer?.availability(false);
118
+ listener?.onError?.(error("unavailable", "preview", "Could not activate CameraX after permission approval", cause));
119
+ }
120
+ return status;
121
+ },
122
+ getCapabilities: async () => {
123
+ const value = bridge ? JSON.parse(bridge.capabilities()) : {
124
+ cameras: [],
125
+ profiles: []
126
+ };
127
+ const supported = !!nativeBridge();
128
+ return {
129
+ supported,
130
+ available: !!bridge?.isReady(),
131
+ reason: !supported ? "CameraX video bridge is missing from the native build" : !bridge?.isReady() ? "An active permitted preview is required" : void 0,
132
+ cameras: value.cameras,
133
+ profiles: value.profiles,
134
+ audio: context().getPackageManager().hasSystemFeature("android.hardware.microphone"),
135
+ orientations: [],
136
+ durationLimit: "native",
137
+ elapsedTime: "nativeMedia",
138
+ output: {
139
+ mimeType: "video/mp4",
140
+ container: "mp4",
141
+ storage: "appPrivateFile",
142
+ destinationFileUrl: true
143
+ }
144
+ };
145
+ },
146
+ previewReady: () => !!bridge?.isReady(),
147
+ validateStart: (options) => {
148
+ if (options.maximumDurationMs !== void 0 && options.maximumDurationMs > 9223372036854) throw error("unsupportedConfiguration", "startRecording", "The duration exceeds CameraX media-time range");
149
+ if (options.orientation && options.orientation !== "unspecified") throw error("unsupportedConfiguration", "startRecording", "Fixed cardinal orientation has not been qualified on this Android source");
150
+ },
151
+ attachPreview: (target, callbacks) => {
152
+ if (released || sink) throw error("invalidState", "attachPreview", "The camera is disposed or finalizing");
153
+ if (owner && owner !== lease) throw error("busy", "attachPreview", "Another camera session is still finalizing");
154
+ owner = lease;
155
+ host = target;
156
+ listener = callbacks;
157
+ try {
158
+ ensureBridge();
159
+ } catch (cause) {
160
+ host = void 0;
161
+ listener = void 0;
162
+ releaseLease();
163
+ throw error("unavailable", "attachPreview", "Could not construct the CameraX native bridge", cause);
164
+ }
165
+ checkPermission("camera").then((status) => {
166
+ if (released || !host) return;
167
+ if (status !== "granted") {
168
+ listener?.onError?.(error("permissionDenied", "preview", "Request camera permission before activating this preview"));
169
+ return;
170
+ }
171
+ try {
172
+ bridge.attach(host, selected());
173
+ } catch (cause) {
174
+ listener?.onError?.(error("unavailable", "preview", "Could not bind shared CameraX preview", cause));
175
+ }
176
+ });
177
+ return () => {
178
+ host = void 0;
179
+ listener = void 0;
180
+ bridge.detach();
181
+ if (!sink) releaseLease();
182
+ };
183
+ },
184
+ configure: (next) => {
185
+ const sourceChanged = JSON.stringify(next.camera) !== JSON.stringify(currentConfig.camera) || next.profile !== currentConfig.profile;
186
+ currentConfig = { ...next };
187
+ if (host && sourceChanged) {
188
+ bridge.detach();
189
+ bridge.attach(host, selected());
190
+ }
191
+ },
192
+ startCapture: (request, target) => {
193
+ sink = target;
194
+ try {
195
+ bridge.start(request.audio, request.destinationPath ?? "", request.maximumDurationMs === void 0 ? 0 : Math.max(1, Math.ceil(request.maximumDurationMs)));
196
+ } catch (cause) {
197
+ sink = void 0;
198
+ target.settled({
199
+ kind: "failed",
200
+ stage: "preparation",
201
+ issue: error("captureFailed", "startRecording", "CameraX could not begin recording", cause)
202
+ });
203
+ }
204
+ },
205
+ stopCapture: () => bridge?.stop(),
206
+ elapsedMs: () => Number(bridge?.elapsedMs() ?? 0),
207
+ openOutput: async (output) => {
208
+ if (output.kind !== "nativeFile" || output.synthetic) throw error("invalidArgument", "openOutput", "Expected a native Android movie reference");
209
+ try {
210
+ const url = nativeBridge().openOutput(output.resourceId, output.fileUrl);
211
+ return {
212
+ url,
213
+ fileUrl: url,
214
+ release: () => {}
215
+ };
216
+ } catch (cause) {
217
+ throw error("destinationUnavailable", "openOutput", "The stored Android movie cannot be reopened", cause);
218
+ }
219
+ },
220
+ release: async () => {
221
+ released = true;
222
+ Application.off(Application.suspendEvent, onSuspend);
223
+ Application.off(Application.resumeEvent, onResume);
224
+ bridge?.release();
225
+ host = void 0;
226
+ releaseLease();
227
+ },
228
+ setObserver: (value) => {
229
+ observer = value;
230
+ }
231
+ };
232
+ }
233
+ //#endregion
234
+ export { createSessionBackend };