@octane-xplat/camera 0.13.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.
- package/README.md +63 -3
- package/dist/linux/CameraView.web.tsrx.js +337 -0
- package/dist/linux/host-movie.web.js +100 -0
- package/dist/linux/index.js +5 -0
- package/dist/linux/layout-child.web.js +29 -0
- package/dist/linux/movie-metadata.web.js +65 -0
- package/dist/linux/octane-client-build.json +8 -0
- package/dist/linux/session-backend.linux.js +479 -0
- package/dist/linux/session-core.js +368 -0
- package/dist/linux/session.js +29 -0
- package/dist/linux/synthetic-session.js +280 -0
- package/dist/linux/types.js +19 -0
- package/dist/native/CameraView.android.js +25 -1
- package/dist/native/CameraView.ios.js +24 -1
- package/dist/native/CameraView.windows.js +173 -0
- package/dist/native/camera-permission.windows.js +43 -0
- package/dist/native/camera-session.windows.js +78 -0
- package/dist/native/cx.windows.js +9 -0
- package/dist/native/index.js +4 -1
- package/dist/native/layout-child.windows.js +53 -0
- package/dist/native/octane-client-build.json +1 -1
- package/dist/native/session-backend.android.js +234 -0
- package/dist/native/session-backend.ios.js +682 -0
- package/dist/native/session-backend.js +55 -0
- package/dist/native/session-backend.windows.js +905 -0
- package/dist/native/session-core.js +368 -0
- package/dist/native/session.js +29 -0
- package/dist/native/synthetic-session.js +280 -0
- package/dist/native/types.js +19 -0
- package/dist/web/CameraView.web.tsrx.js +27 -7
- package/dist/web/host-movie.web.js +100 -0
- package/dist/web/index.js +4 -1
- package/dist/web/movie-metadata.web.js +65 -0
- package/dist/web/movie-storage.web.js +119 -0
- package/dist/web/octane-client-build.json +1 -1
- package/dist/web/session-backend.web.js +490 -0
- package/dist/web/session-core.js +368 -0
- package/dist/web/session.js +29 -0
- package/dist/web/synthetic-session.js +280 -0
- package/dist/web/types.js +19 -0
- package/package.json +22 -4
- package/platforms/android/AndroidManifest.xml +2 -0
- package/platforms/android/include.gradle +1 -0
- package/platforms/android/java/com/octanexplat/camera/CameraPreviewView.java +4 -0
- package/platforms/android/java/com/octanexplat/camera/CameraSessionBridge.java +363 -0
- package/platforms/ios/Info.plist +2 -0
- package/platforms/macos/src/XplatCameraHost.swift +513 -0
- package/src/CameraView.android.tsrx +21 -1
- package/src/CameraView.ios.tsrx +28 -2
- package/src/CameraView.macos.tsrx +93 -0
- package/src/CameraView.web.tsrx +20 -2
- package/src/CameraView.windows.tsrx +124 -0
- package/src/camera-permission.windows.ts +76 -0
- package/src/camera-session.macos.ts +75 -0
- package/src/camera-session.windows.ts +123 -0
- package/src/cx.macos.ts +5 -0
- package/src/cx.windows.ts +6 -0
- package/src/host-movie.web.ts +180 -0
- package/src/index.ts +31 -0
- package/src/index.web.ts +31 -0
- package/src/layout-child.windows.ts +79 -0
- package/src/movie-metadata.web.ts +84 -0
- package/src/movie-storage.web.ts +164 -0
- package/src/props.ts +7 -1
- package/src/session-backend.android.ts +397 -0
- package/src/session-backend.ios.ts +1092 -0
- package/src/session-backend.linux.ts +869 -0
- package/src/session-backend.macos.ts +624 -0
- package/src/session-backend.ts +57 -0
- package/src/session-backend.web.ts +874 -0
- package/src/session-backend.windows.ts +1517 -0
- package/src/session-core.ts +659 -0
- package/src/session.ts +37 -0
- package/src/synthetic-session.ts +367 -0
- package/src/types.ts +329 -0
- package/types/index.d.ts +43 -0
- package/types/props.d.ts +7 -1
- package/types/session-core.d.ts +129 -0
- package/types/synthetic-session.d.ts +48 -0
- package/types/types.d.ts +263 -0
- package/src/CameraView.windows.ts +0 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attachSessionPreview } from "./session.js";
|
|
1
2
|
import { cameraHardwarePresent, ensureCameraPermission } from "./camera-permission.mobile.js";
|
|
2
3
|
import { applyEscapeProps, layoutChildProps, nativeAccessibilityRole, nativeAccessibilityState } from "./layout-child.js";
|
|
3
4
|
import { cx } from "./cx.mobile.js";
|
|
@@ -48,6 +49,25 @@ var CameraView = defineUniversalComponent("nativescript", function CameraView(pr
|
|
|
48
49
|
nativeView.setCameraActive(active);
|
|
49
50
|
if (!active) return () => nativeView.setCameraActive(false);
|
|
50
51
|
const fail = (message) => props.onError?.({ message });
|
|
52
|
+
if (props.session) {
|
|
53
|
+
if (props.facing !== void 0) {
|
|
54
|
+
fail("camera session conflicts with facing");
|
|
55
|
+
return () => nativeView.setCameraActive(false);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const detach = attachSessionPreview(props.session, nativeView, {
|
|
59
|
+
onReady: props.onReady,
|
|
60
|
+
onError: (issue) => fail(issue.message)
|
|
61
|
+
});
|
|
62
|
+
return () => {
|
|
63
|
+
detach();
|
|
64
|
+
nativeView.setCameraActive(false);
|
|
65
|
+
};
|
|
66
|
+
} catch (error) {
|
|
67
|
+
fail(error?.message ?? "camera session error");
|
|
68
|
+
return () => nativeView.setCameraActive(false);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
51
71
|
if (!cameraHardwarePresent()) {
|
|
52
72
|
fail("camera unsupported");
|
|
53
73
|
return () => nativeView.setCameraActive(false);
|
|
@@ -89,7 +109,11 @@ var CameraView = defineUniversalComponent("nativescript", function CameraView(pr
|
|
|
89
109
|
provider.unbind(preview);
|
|
90
110
|
} catch {}
|
|
91
111
|
};
|
|
92
|
-
}, [
|
|
112
|
+
}, [
|
|
113
|
+
active,
|
|
114
|
+
facing,
|
|
115
|
+
props.session
|
|
116
|
+
], _h$3);
|
|
93
117
|
useEffect(() => {
|
|
94
118
|
const view = host.current;
|
|
95
119
|
if (!view) return;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attachSessionPreview } from "./session.js";
|
|
1
2
|
import { cameraHardwarePresent, ensureCameraPermission } from "./camera-permission.mobile.js";
|
|
2
3
|
import { startCameraPreview } from "./camera-session.ios.js";
|
|
3
4
|
import { applyEscapeProps, layoutChildProps, nativeAccessibilityRole, nativeAccessibilityState } from "./layout-child.js";
|
|
@@ -29,6 +30,24 @@ var CameraView = defineUniversalComponent("nativescript", function CameraView(pr
|
|
|
29
30
|
let disposed = false;
|
|
30
31
|
let stopPreview;
|
|
31
32
|
const fail = (message) => props.onError?.({ message });
|
|
33
|
+
if (props.session) {
|
|
34
|
+
if (props.facing !== void 0) {
|
|
35
|
+
fail("camera session conflicts with facing");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const detach = attachSessionPreview(props.session, view, { onReady: () => {
|
|
40
|
+
if (!disposed) props.onReady?.();
|
|
41
|
+
} });
|
|
42
|
+
return () => {
|
|
43
|
+
disposed = true;
|
|
44
|
+
detach();
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
fail(error?.message ?? "camera session error");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
32
51
|
if (!cameraHardwarePresent()) {
|
|
33
52
|
fail("camera unsupported");
|
|
34
53
|
return;
|
|
@@ -49,7 +68,11 @@ var CameraView = defineUniversalComponent("nativescript", function CameraView(pr
|
|
|
49
68
|
disposed = true;
|
|
50
69
|
stopPreview?.();
|
|
51
70
|
};
|
|
52
|
-
}, [
|
|
71
|
+
}, [
|
|
72
|
+
active,
|
|
73
|
+
facing,
|
|
74
|
+
props.session
|
|
75
|
+
], _h$3);
|
|
53
76
|
useEffect(() => {
|
|
54
77
|
const view = host.current;
|
|
55
78
|
if (!view) return;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { attachSessionPreview } from "./session.js";
|
|
2
|
+
import { cameraHardwarePresent, ensureCameraPermission } from "./camera-permission.windows.js";
|
|
3
|
+
import { startCameraPreview } from "./camera-session.windows.js";
|
|
4
|
+
import { applyEscapeProps, layoutChildProps, nativeAccessibilityRole, nativeAccessibilityState } from "./layout-child.windows.js";
|
|
5
|
+
import { cx } from "./cx.windows.js";
|
|
6
|
+
import { defineUniversalComponent, hookSlots, registerElement, universalPlan, universalProps, universalValue, useCallback, useEffect, useImperativeHandle, useRef } from "@nativescript-community/octane";
|
|
7
|
+
import { View } from "@nativescript/core";
|
|
8
|
+
//#region src/CameraView.windows.tsrx
|
|
9
|
+
var _hs$ = /* @__PURE__ */ hookSlots(5);
|
|
10
|
+
var _h$0 = /* @__PURE__ */ Symbol(_hs$);
|
|
11
|
+
var _h$1 = /* @__PURE__ */ Symbol(_hs$ + 1);
|
|
12
|
+
var _h$2 = /* @__PURE__ */ Symbol(_hs$ + 2);
|
|
13
|
+
var _h$3 = /* @__PURE__ */ Symbol(_hs$ + 3);
|
|
14
|
+
var _h$4 = /* @__PURE__ */ Symbol(_hs$ + 4);
|
|
15
|
+
var __octaneUniversalPlan0 = universalPlan("nativescript", {
|
|
16
|
+
"kind": "host",
|
|
17
|
+
"type": "gridlayout",
|
|
18
|
+
"propsSlot": 0,
|
|
19
|
+
"children": [{
|
|
20
|
+
"kind": "host",
|
|
21
|
+
"type": "camerapreview",
|
|
22
|
+
"props": {
|
|
23
|
+
"row": 0,
|
|
24
|
+
"col": 0
|
|
25
|
+
},
|
|
26
|
+
"bindings": [["ref", 1]]
|
|
27
|
+
}]
|
|
28
|
+
});
|
|
29
|
+
var CameraPreview = class extends View {
|
|
30
|
+
createNativeView() {
|
|
31
|
+
const { Microsoft } = globalThis;
|
|
32
|
+
return new Microsoft.UI.Xaml.Controls.CaptureElement();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
registerElement("camerapreview", CameraPreview);
|
|
36
|
+
var CameraView = defineUniversalComponent("nativescript", function CameraView(props) {
|
|
37
|
+
const host = useRef(null, _h$0);
|
|
38
|
+
const active = props.active !== false;
|
|
39
|
+
const facing = props.facing ?? "back";
|
|
40
|
+
useImperativeHandle(props.ref, () => ({ native: host.current?.nativeViewProtected }), [], _h$1);
|
|
41
|
+
const bindHost = useCallback((view) => {
|
|
42
|
+
host.current = view;
|
|
43
|
+
}, [], _h$2);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const view = host.current;
|
|
46
|
+
if (!view || !active) return;
|
|
47
|
+
let disposed = false;
|
|
48
|
+
let stopPreview;
|
|
49
|
+
const fail = (message) => props.onError?.({ message });
|
|
50
|
+
if (props.session) {
|
|
51
|
+
if (props.facing !== void 0) {
|
|
52
|
+
fail("camera session conflicts with facing");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const detach = attachSessionPreview(props.session, view, {
|
|
57
|
+
onReady: () => {
|
|
58
|
+
if (!disposed) props.onReady?.();
|
|
59
|
+
},
|
|
60
|
+
onError: (issue) => {
|
|
61
|
+
if (!disposed) fail(issue.message);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return () => {
|
|
65
|
+
disposed = true;
|
|
66
|
+
detach();
|
|
67
|
+
};
|
|
68
|
+
} catch (error) {
|
|
69
|
+
fail(error?.message ?? "camera session error");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!cameraHardwarePresent()) {
|
|
74
|
+
fail("camera unsupported");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
ensureCameraPermission().then(async (granted) => {
|
|
78
|
+
if (disposed) return;
|
|
79
|
+
if (!granted) {
|
|
80
|
+
fail("camera permission denied");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
stopPreview = await startCameraPreview(view, facing, () => {
|
|
85
|
+
if (!disposed) props.onReady?.();
|
|
86
|
+
});
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (!disposed) fail(error?.message ?? "camera error");
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return () => {
|
|
92
|
+
disposed = true;
|
|
93
|
+
stopPreview?.();
|
|
94
|
+
};
|
|
95
|
+
}, [
|
|
96
|
+
active,
|
|
97
|
+
facing,
|
|
98
|
+
props.session
|
|
99
|
+
], _h$3);
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const view = host.current;
|
|
102
|
+
if (!view) return;
|
|
103
|
+
applyEscapeProps(view.nativeViewProtected, props);
|
|
104
|
+
}, [props.ref, props.windows], _h$4);
|
|
105
|
+
return universalValue(__octaneUniversalPlan0, [universalProps([
|
|
106
|
+
[
|
|
107
|
+
"set",
|
|
108
|
+
"id",
|
|
109
|
+
props.id
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
"set",
|
|
113
|
+
"rows",
|
|
114
|
+
"*"
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
"set",
|
|
118
|
+
"columns",
|
|
119
|
+
"*"
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
"set",
|
|
123
|
+
"className",
|
|
124
|
+
cx("vx-layers", "vx-cameraview", props.className)
|
|
125
|
+
],
|
|
126
|
+
[
|
|
127
|
+
"set",
|
|
128
|
+
"style",
|
|
129
|
+
{
|
|
130
|
+
backgroundColor: "#000",
|
|
131
|
+
...props.style
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
["spread", layoutChildProps(props)],
|
|
135
|
+
[
|
|
136
|
+
"set",
|
|
137
|
+
"accessible",
|
|
138
|
+
props.accessible
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
"set",
|
|
142
|
+
"accessibilityLabel",
|
|
143
|
+
props.accessibilityLabel
|
|
144
|
+
],
|
|
145
|
+
[
|
|
146
|
+
"set",
|
|
147
|
+
"accessibilityRole",
|
|
148
|
+
nativeAccessibilityRole(props.accessibilityRole)
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
"set",
|
|
152
|
+
"accessibilityHint",
|
|
153
|
+
props.accessibilityHint
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
"set",
|
|
157
|
+
"accessibilityValue",
|
|
158
|
+
props.accessibilityValue
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
"set",
|
|
162
|
+
"accessibilityState",
|
|
163
|
+
nativeAccessibilityState(props.accessibilityState)
|
|
164
|
+
],
|
|
165
|
+
[
|
|
166
|
+
"set",
|
|
167
|
+
"accessibilityLiveRegion",
|
|
168
|
+
props.accessibilityLiveRegion
|
|
169
|
+
]
|
|
170
|
+
]), bindHost]);
|
|
171
|
+
}, { "module": "@nativescript-community/octane" });
|
|
172
|
+
//#endregion
|
|
173
|
+
export { CameraView };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/camera-permission.windows.ts
|
|
2
|
+
/** Windows camera-permission probe for preview-only `CameraView` callers.
|
|
3
|
+
* Uses `AppCapability` when projected and falls back to
|
|
4
|
+
* `DeviceAccessInformation`; both are non-prompting checks — only
|
|
5
|
+
* `RequestAccessAsync` may show the system prompt. */
|
|
6
|
+
var windows = () => globalThis;
|
|
7
|
+
var toPromise = (op) => {
|
|
8
|
+
const { NSWinRT } = windows();
|
|
9
|
+
if (NSWinRT?.toPromise && op != null) return NSWinRT.toPromise(op);
|
|
10
|
+
if (op?.done) return new Promise((resolve, reject) => {
|
|
11
|
+
try {
|
|
12
|
+
op.done(resolve, reject);
|
|
13
|
+
} catch (cause) {
|
|
14
|
+
reject(cause);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return Promise.resolve(op);
|
|
18
|
+
};
|
|
19
|
+
function cameraHardwarePresent() {
|
|
20
|
+
const { Windows, Microsoft } = windows();
|
|
21
|
+
return !!(Windows?.Media?.Capture?.MediaCapture && Windows?.Devices?.Enumeration?.DeviceInformation && Microsoft?.UI?.Xaml?.Controls?.CaptureElement);
|
|
22
|
+
}
|
|
23
|
+
async function ensureCameraPermission() {
|
|
24
|
+
try {
|
|
25
|
+
const { Windows } = windows();
|
|
26
|
+
const capability = Windows?.Security?.Authorization?.AppCapabilityAccess?.AppCapability?.Create?.("webcam");
|
|
27
|
+
if (capability) {
|
|
28
|
+
const status = capability.CheckAccess();
|
|
29
|
+
if (status === 4) return true;
|
|
30
|
+
if (status === 3) return await toPromise(capability.RequestAccessAsync()) === 4;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const enumeration = Windows?.Devices?.Enumeration;
|
|
34
|
+
const deviceClass = enumeration?.DeviceClass?.VideoCapture;
|
|
35
|
+
const info = deviceClass === void 0 ? void 0 : enumeration?.DeviceAccessInformation?.CreateFromDeviceClass(deviceClass);
|
|
36
|
+
if (info) return info.CurrentStatus !== 2 && info.CurrentStatus !== 3;
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { cameraHardwarePresent, ensureCameraPermission };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/camera-session.windows.ts
|
|
2
|
+
/** Standalone (non-session) WinUI preview for `CameraView` without a
|
|
3
|
+
* `session` prop. Owns a private `MediaCapture` bound to a
|
|
4
|
+
* `CaptureElement`; the returned function stops preview and closes the
|
|
5
|
+
* device. Session-backed previews share their capture through
|
|
6
|
+
* `session-backend.windows.ts` instead. */
|
|
7
|
+
var windows = () => globalThis;
|
|
8
|
+
var toPromise = (op) => {
|
|
9
|
+
const { NSWinRT } = windows();
|
|
10
|
+
if (NSWinRT?.toPromise && op != null) return NSWinRT.toPromise(op);
|
|
11
|
+
if (op?.done) return new Promise((resolve, reject) => {
|
|
12
|
+
try {
|
|
13
|
+
op.done(resolve, reject);
|
|
14
|
+
} catch (cause) {
|
|
15
|
+
reject(cause);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return Promise.resolve(op);
|
|
19
|
+
};
|
|
20
|
+
var vectorToArray = (items) => {
|
|
21
|
+
const result = [];
|
|
22
|
+
const size = Number(items?.Size ?? items?.Count ?? 0);
|
|
23
|
+
for (let index = 0; index < size; index += 1) result.push(items.GetAt(index));
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
/** Attach a MediaCapture preview to the view's `CaptureElement`.
|
|
27
|
+
* `facing` maps to enclosure panels; desktop cameras without a panel fall
|
|
28
|
+
* back to the OS default — front/back is a preference, never a fabrication. */
|
|
29
|
+
async function startCameraPreview(view, facing, onReady) {
|
|
30
|
+
const { Windows } = windows();
|
|
31
|
+
const enumeration = Windows?.Devices?.Enumeration;
|
|
32
|
+
const captureApi = Windows?.Media?.Capture;
|
|
33
|
+
if (!enumeration || !captureApi) throw new Error("camera preview unsupported");
|
|
34
|
+
const devices = vectorToArray(await toPromise(enumeration.DeviceInformation.FindAllAsync(enumeration.DeviceClass.VideoCapture)));
|
|
35
|
+
if (!devices.length) throw new Error("camera unavailable");
|
|
36
|
+
const wantedPanel = facing === "front" ? 1 : 2;
|
|
37
|
+
const device = devices.find((entry) => Number(entry?.EnclosureLocation?.Panel) === wantedPanel) ?? devices[0];
|
|
38
|
+
const settings = new captureApi.MediaCaptureInitializationSettings();
|
|
39
|
+
settings.VideoDeviceId = String(device?.Id ?? device?.id ?? "");
|
|
40
|
+
settings.StreamingCaptureMode = 0;
|
|
41
|
+
const capture = new captureApi.MediaCapture();
|
|
42
|
+
try {
|
|
43
|
+
await toPromise(capture.InitializeAsync(settings));
|
|
44
|
+
} catch (cause) {
|
|
45
|
+
try {
|
|
46
|
+
capture.Close();
|
|
47
|
+
} catch {
|
|
48
|
+
try {
|
|
49
|
+
capture.Dispose();
|
|
50
|
+
} catch {}
|
|
51
|
+
}
|
|
52
|
+
throw cause instanceof Error ? cause : /* @__PURE__ */ new Error("camera unavailable");
|
|
53
|
+
}
|
|
54
|
+
const element = view?.nativeViewProtected ?? view;
|
|
55
|
+
element.Source = capture;
|
|
56
|
+
try {
|
|
57
|
+
if (Number(device?.EnclosureLocation?.Panel) === 1 && typeof capture.SetPreviewMirroring === "function") capture.SetPreviewMirroring(true);
|
|
58
|
+
} catch {}
|
|
59
|
+
await toPromise(capture.StartPreviewAsync());
|
|
60
|
+
onReady?.();
|
|
61
|
+
return async () => {
|
|
62
|
+
try {
|
|
63
|
+
element.Source = null;
|
|
64
|
+
} catch {}
|
|
65
|
+
try {
|
|
66
|
+
await toPromise(capture.StopPreviewAsync());
|
|
67
|
+
} catch {}
|
|
68
|
+
try {
|
|
69
|
+
capture.Close();
|
|
70
|
+
} catch {
|
|
71
|
+
try {
|
|
72
|
+
capture.Dispose();
|
|
73
|
+
} catch {}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { startCameraPreview };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/cx.windows.ts
|
|
2
|
+
/** Imperative `view.className` writes still need a pre-joined string —
|
|
3
|
+
* NativeScript's className setter splits on ' ' only. Normalize arrays here
|
|
4
|
+
* so they stay space separated. */
|
|
5
|
+
function cx(...parts) {
|
|
6
|
+
return parts.flat(Infinity).filter(Boolean).join(" ");
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { cx };
|
package/dist/native/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import { CameraCaptureError } from "./types.js";
|
|
2
|
+
import { createCameraSession } from "./session.js";
|
|
3
|
+
import { createMemoryCameraStorage, createSyntheticCameraSession } from "./synthetic-session.js";
|
|
1
4
|
import { CameraView } from "./src/CameraView";
|
|
2
|
-
export { CameraView };
|
|
5
|
+
export { CameraCaptureError, CameraView, createCameraSession, createMemoryCameraStorage, createSyntheticCameraSession };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/layout-child.windows.ts
|
|
2
|
+
/** Windows twins of the layout-child helpers — the unsuffixed module
|
|
3
|
+
* resolves the platform escape bag through `isIOS`, which has no Windows
|
|
4
|
+
* branch. Pure helpers are re-declared here to keep divergence at the file
|
|
5
|
+
* boundary. */
|
|
6
|
+
function layoutChildProps(props) {
|
|
7
|
+
const result = {};
|
|
8
|
+
for (const key of [
|
|
9
|
+
"row",
|
|
10
|
+
"col",
|
|
11
|
+
"rowSpan",
|
|
12
|
+
"colSpan",
|
|
13
|
+
"dock",
|
|
14
|
+
"left",
|
|
15
|
+
"top",
|
|
16
|
+
"flexGrow",
|
|
17
|
+
"flexShrink",
|
|
18
|
+
"alignSelf",
|
|
19
|
+
"order"
|
|
20
|
+
]) if (props[key] !== void 0) result[key] = props[key];
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function applyEscapeProps(view, props) {
|
|
24
|
+
if (view && props.windows) Object.assign(view, props.windows);
|
|
25
|
+
}
|
|
26
|
+
var nativeRoles = {
|
|
27
|
+
button: "button",
|
|
28
|
+
link: "link",
|
|
29
|
+
search: "search",
|
|
30
|
+
image: "image",
|
|
31
|
+
heading: "header",
|
|
32
|
+
adjustable: "adjustable",
|
|
33
|
+
summary: "summary",
|
|
34
|
+
text: "text",
|
|
35
|
+
none: "none",
|
|
36
|
+
progressbar: "progressBar",
|
|
37
|
+
checkbox: "checkbox",
|
|
38
|
+
switch: "switch",
|
|
39
|
+
radio: "radioButton",
|
|
40
|
+
spinbutton: "spinButton",
|
|
41
|
+
tab: "button"
|
|
42
|
+
};
|
|
43
|
+
function nativeAccessibilityRole(role) {
|
|
44
|
+
return role ? nativeRoles[role] : void 0;
|
|
45
|
+
}
|
|
46
|
+
function nativeAccessibilityState(state) {
|
|
47
|
+
if (state?.disabled) return "disabled";
|
|
48
|
+
if (state?.selected) return "selected";
|
|
49
|
+
if (state?.checked === true) return "checked";
|
|
50
|
+
if (state?.checked === false) return "unchecked";
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { applyEscapeProps, layoutChildProps, nativeAccessibilityRole, nativeAccessibilityState };
|
|
@@ -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 };
|