@solidnative-dev/camera 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +94 -2
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +307 -0
- package/dist/index.js.map +1 -0
- package/dist/nitro-adapter.d.ts +12 -0
- package/dist/nitro-adapter.d.ts.map +1 -0
- package/dist/nitro-adapter.js +57 -0
- package/dist/nitro-adapter.js.map +1 -0
- package/dist/react-native.d.ts +22 -0
- package/dist/react-native.d.ts.map +1 -0
- package/dist/react-native.js +365 -0
- package/dist/react-native.js.map +1 -0
- package/dist/solid.d.ts +28 -0
- package/dist/solid.d.ts.map +1 -0
- package/dist/solid.js +133 -0
- package/dist/solid.js.map +1 -0
- package/package.json +65 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Solid Native contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,95 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@solidnative-dev/camera`
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package exposes bounded camera permissions, device metadata, session
|
|
4
|
+
lifecycle, native-session events, serialized photo capture, and a Solid-owned
|
|
5
|
+
live preview. Portable application state sees only validated data and
|
|
6
|
+
`CameraSession`; VisionCamera's Nitro HybridObjects remain private to the React
|
|
7
|
+
Native adapter and runtime.
|
|
8
|
+
|
|
9
|
+
The first backend drives VisionCamera 5's imperative Nitro API directly:
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import {
|
|
13
|
+
CAMERA_PREVIEW_DESCRIPTOR,
|
|
14
|
+
CameraPreview,
|
|
15
|
+
createReactNativeCameraService,
|
|
16
|
+
} from "@solidnative-dev/camera/react-native";
|
|
17
|
+
import {
|
|
18
|
+
createCameraSessionEvent,
|
|
19
|
+
createOwnedCameraSession,
|
|
20
|
+
} from "@solidnative-dev/camera/solid";
|
|
21
|
+
|
|
22
|
+
const camera = createReactNativeCameraService();
|
|
23
|
+
await camera.requestPermission();
|
|
24
|
+
|
|
25
|
+
const owned = createOwnedCameraSession(camera, {
|
|
26
|
+
position: "back",
|
|
27
|
+
onError: console.error,
|
|
28
|
+
});
|
|
29
|
+
const session = await owned.ready;
|
|
30
|
+
const latestSessionEvent = createCameraSessionEvent(session);
|
|
31
|
+
|
|
32
|
+
const photo = await session.capturePhoto({
|
|
33
|
+
flashMode: "off",
|
|
34
|
+
enableShutterSound: false,
|
|
35
|
+
});
|
|
36
|
+
console.log(photo.filePath, photo.width, photo.height);
|
|
37
|
+
|
|
38
|
+
<CameraPreview session={session} resizeMode="cover" style={{ height: 240 }} />;
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Add `CAMERA_PREVIEW_DESCRIPTOR` to the descriptors given to
|
|
42
|
+
`createNativeFabricHost`. `createOwnedCameraSession` binds asynchronous opening,
|
|
43
|
+
lifecycle events, idempotent native stop, and all underlying output disposal to
|
|
44
|
+
the current Solid owner. `createCameraSessionEvent` projects a current or
|
|
45
|
+
lazily supplied session into an owner-bound accessor. Started, stopped,
|
|
46
|
+
interrupted, resumed, and error callbacks enter the causal protocol as stable
|
|
47
|
+
`platform.camera.session.*` default-priority events; device identities,
|
|
48
|
+
interruption reasons, and native error values remain outside telemetry.
|
|
49
|
+
Reactive session replacement detaches the previous subscription before
|
|
50
|
+
attaching the next one, root disposal removes the current subscription exactly
|
|
51
|
+
once, and setup/removal failures are reported without letting a failing
|
|
52
|
+
diagnostic callback break the handoff. `CameraPreview` separately binds the
|
|
53
|
+
exact preview output's native-resource retention to its own owner, including
|
|
54
|
+
reactive session replacement. A stopped session cannot be mounted again.
|
|
55
|
+
Because `CameraService.open()` resolves only after the native session is ready,
|
|
56
|
+
each later `CameraSession.subscribe()` receives one next-turn `started` event.
|
|
57
|
+
The public boundary deduplicates it against a synchronous or late native
|
|
58
|
+
callback, so native readiness cannot be lost between `open()` and subscription
|
|
59
|
+
or accidentally merge into the rendering transaction that consumes the
|
|
60
|
+
session.
|
|
61
|
+
|
|
62
|
+
The React Native adapter configures both a preview output and a smallest
|
|
63
|
+
device-supported JPEG photo output. The latter gives CameraX a usable readiness
|
|
64
|
+
path before the preview surface mounts and backs `CameraSession.capturePhoto()`.
|
|
65
|
+
The adapter installs the exact NitroModules `0.36.5` TurboModule through React
|
|
66
|
+
Native's narrow registry and resolves only the `CameraFactory` HybridObject. It
|
|
67
|
+
accepts both native success encodings (`null` on Android and `undefined` where
|
|
68
|
+
the binding omits a value), while rejecting string errors and every other
|
|
69
|
+
installer result. It
|
|
70
|
+
does not evaluate the `react-native`, VisionCamera, or NitroModules JavaScript
|
|
71
|
+
barrels; the production source-map gate rejects those package surfaces.
|
|
72
|
+
Captures are serialized, accepted captures finish before session teardown, and
|
|
73
|
+
the in-memory Nitro `Photo` is disposed immediately after it writes a temporary
|
|
74
|
+
file. The returned frozen value contains only a bounded path, dimensions,
|
|
75
|
+
orientation, format, host-clock timestamp, and mirrored state; callers remain
|
|
76
|
+
responsible for copying or otherwise managing the temporary file. The adapter
|
|
77
|
+
waits for the native started event because lifecycle activation can complete
|
|
78
|
+
before hardware reaches its open state.
|
|
79
|
+
|
|
80
|
+
The preview is a generated VisionCamera `PreviewView` committed directly by
|
|
81
|
+
Solid Native Fabric. No VisionCamera hook or React component tree is involved.
|
|
82
|
+
The runtime's bounded opaque-resource registry preserves the preview output's
|
|
83
|
+
exact JSI identity across RawProps while ordinary application props remain in
|
|
84
|
+
the transport-safe host-value domain.
|
|
85
|
+
|
|
86
|
+
A physical Pixel 9a Release test independently verifies camera acquisition,
|
|
87
|
+
the mounted Android `PreviewView`'s positive geometry and `STREAMING` state, a
|
|
88
|
+
real JPEG capture with positive dimensions and a temporary path, the capture
|
|
89
|
+
result's separate Solid/Fabric commit, then camera release after root disposal.
|
|
90
|
+
The signed physical-iPhone Release run also grants permission, selects a back
|
|
91
|
+
camera, starts the native session, mounts the generated preview, captures and
|
|
92
|
+
commits the real JPEG result, then stops the session. Independent iOS
|
|
93
|
+
operating-system assertions for streaming and release, video recording, frame
|
|
94
|
+
processors, preview callbacks, gallery persistence, and media library
|
|
95
|
+
permissions are not implied by the photo-capture proof.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export declare const CAMERA_MAX_DEVICE_COUNT = 128;
|
|
2
|
+
export declare const CAMERA_MAX_IDENTIFIER_LENGTH = 512;
|
|
3
|
+
export declare const CAMERA_MAX_LABEL_LENGTH = 1024;
|
|
4
|
+
export declare const CAMERA_MAX_EVENT_REASON_LENGTH = 2048;
|
|
5
|
+
export declare const CAMERA_MAX_FILE_PATH_LENGTH = 4096;
|
|
6
|
+
export type CameraAuthorization = "not-determined" | "denied" | "authorized" | "restricted";
|
|
7
|
+
export type CameraTargetPosition = "front" | "back" | "external";
|
|
8
|
+
export type CameraPosition = CameraTargetPosition | "unspecified";
|
|
9
|
+
export interface CameraPermission {
|
|
10
|
+
readonly authorization: CameraAuthorization;
|
|
11
|
+
}
|
|
12
|
+
export interface CameraDevice {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly position: CameraPosition;
|
|
16
|
+
readonly type: string;
|
|
17
|
+
}
|
|
18
|
+
export type CameraSessionEventKind = "started" | "stopped" | "interrupted" | "resumed" | "error";
|
|
19
|
+
export interface CameraSessionEvent {
|
|
20
|
+
readonly kind: CameraSessionEventKind;
|
|
21
|
+
readonly reason?: string;
|
|
22
|
+
}
|
|
23
|
+
export type CameraFlashMode = "off" | "on" | "auto";
|
|
24
|
+
export type CameraPhotoOrientation = "up" | "right" | "down" | "left";
|
|
25
|
+
export type CameraPhotoContainerFormat = "jpeg" | "heic" | "dng" | "tiff" | "dcm" | "unknown";
|
|
26
|
+
export interface CameraPhotoCaptureOptions {
|
|
27
|
+
readonly flashMode?: CameraFlashMode;
|
|
28
|
+
readonly enableShutterSound?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface CameraPhoto {
|
|
31
|
+
/** Temporary filesystem path, without a `file://` prefix. */
|
|
32
|
+
readonly filePath: string;
|
|
33
|
+
readonly width: number;
|
|
34
|
+
readonly height: number;
|
|
35
|
+
readonly orientation: CameraPhotoOrientation;
|
|
36
|
+
readonly containerFormat: CameraPhotoContainerFormat;
|
|
37
|
+
/** Native host-clock timestamp in seconds. */
|
|
38
|
+
readonly timestamp: number;
|
|
39
|
+
readonly isMirrored: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface CameraSubscriptionOptions {
|
|
42
|
+
readonly onError?: (error: unknown) => unknown;
|
|
43
|
+
}
|
|
44
|
+
export interface CameraSubscription {
|
|
45
|
+
remove(): void;
|
|
46
|
+
}
|
|
47
|
+
export interface CameraSession {
|
|
48
|
+
readonly device: CameraDevice;
|
|
49
|
+
readonly stopped: boolean;
|
|
50
|
+
capturePhoto(options?: CameraPhotoCaptureOptions): Promise<CameraPhoto>;
|
|
51
|
+
subscribe(listener: (event: CameraSessionEvent) => unknown, options?: CameraSubscriptionOptions): CameraSubscription;
|
|
52
|
+
stop(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export interface CameraService {
|
|
55
|
+
getPermission(): CameraPermission;
|
|
56
|
+
requestPermission(): Promise<CameraPermission>;
|
|
57
|
+
listDevices(): Promise<readonly CameraDevice[]>;
|
|
58
|
+
open(position: CameraTargetPosition): Promise<CameraSession>;
|
|
59
|
+
}
|
|
60
|
+
export interface CameraAdapterSession {
|
|
61
|
+
readonly device: unknown;
|
|
62
|
+
capturePhoto(options: CameraPhotoCaptureOptions): Promise<unknown>;
|
|
63
|
+
subscribe(listener: (event: unknown) => void): unknown;
|
|
64
|
+
stop(): Promise<unknown>;
|
|
65
|
+
}
|
|
66
|
+
/** @internal Adapter-specific packages use this without exposing it on CameraSession. */
|
|
67
|
+
export declare function cameraAdapterSessionFor(session: CameraSession): CameraAdapterSession | undefined;
|
|
68
|
+
export interface CameraAdapter {
|
|
69
|
+
getPermission(): unknown;
|
|
70
|
+
requestPermission(): Promise<unknown>;
|
|
71
|
+
listDevices(): Promise<unknown>;
|
|
72
|
+
open(position: CameraTargetPosition): Promise<unknown>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Narrows a camera backend to bounded, portable permission, device, session,
|
|
76
|
+
* capture, and lifecycle values. Native failures remain rejected promises.
|
|
77
|
+
*/
|
|
78
|
+
export declare function createCameraService(adapter: CameraAdapter): CameraService;
|
|
79
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d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E,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnE,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC;IACvD,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B;AAOD,yFAAyF;AACzF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,aAAa,GACrB,oBAAoB,GAAG,SAAS,CAElC;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,IAAI,OAAO,CAAC;IACzB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,IAAI,CAAC,QAAQ,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxD;AAuTD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CA8DzE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
export const CAMERA_MAX_DEVICE_COUNT = 128;
|
|
2
|
+
export const CAMERA_MAX_IDENTIFIER_LENGTH = 512;
|
|
3
|
+
export const CAMERA_MAX_LABEL_LENGTH = 1_024;
|
|
4
|
+
export const CAMERA_MAX_EVENT_REASON_LENGTH = 2_048;
|
|
5
|
+
export const CAMERA_MAX_FILE_PATH_LENGTH = 4_096;
|
|
6
|
+
const ADAPTER_SESSION_BY_CAMERA_SESSION = new WeakMap();
|
|
7
|
+
/** @internal Adapter-specific packages use this without exposing it on CameraSession. */
|
|
8
|
+
export function cameraAdapterSessionFor(session) {
|
|
9
|
+
return ADAPTER_SESSION_BY_CAMERA_SESSION.get(session);
|
|
10
|
+
}
|
|
11
|
+
function plainRecord(value, path) {
|
|
12
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
13
|
+
throw new TypeError(`${path} must be an object.`);
|
|
14
|
+
}
|
|
15
|
+
const prototype = Object.getPrototypeOf(value);
|
|
16
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
17
|
+
throw new TypeError(`${path} must be a plain object.`);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function boundedString(value, path, maximumLength) {
|
|
22
|
+
if (typeof value !== "string" ||
|
|
23
|
+
value.length === 0 ||
|
|
24
|
+
value.length > maximumLength ||
|
|
25
|
+
value.includes("\0")) {
|
|
26
|
+
throw new TypeError(`${path} must be a 1-${maximumLength} character string without null bytes.`);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
function permission(value) {
|
|
31
|
+
const record = plainRecord(value, "Camera permission");
|
|
32
|
+
if (record.authorization !== "not-determined" &&
|
|
33
|
+
record.authorization !== "denied" &&
|
|
34
|
+
record.authorization !== "authorized" &&
|
|
35
|
+
record.authorization !== "restricted") {
|
|
36
|
+
throw new TypeError("Camera permission authorization status is invalid.");
|
|
37
|
+
}
|
|
38
|
+
return Object.freeze({ authorization: record.authorization });
|
|
39
|
+
}
|
|
40
|
+
function targetPosition(value) {
|
|
41
|
+
if (value !== "front" && value !== "back" && value !== "external") {
|
|
42
|
+
throw new TypeError("Camera target position is invalid.");
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
function position(value) {
|
|
47
|
+
if (value !== "front" &&
|
|
48
|
+
value !== "back" &&
|
|
49
|
+
value !== "external" &&
|
|
50
|
+
value !== "unspecified") {
|
|
51
|
+
throw new TypeError("Camera device position is invalid.");
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
function device(value, path = "Camera device") {
|
|
56
|
+
const record = plainRecord(value, path);
|
|
57
|
+
return Object.freeze({
|
|
58
|
+
id: boundedString(record.id, `${path} id`, CAMERA_MAX_IDENTIFIER_LENGTH),
|
|
59
|
+
name: boundedString(record.name, `${path} name`, CAMERA_MAX_LABEL_LENGTH),
|
|
60
|
+
position: position(record.position),
|
|
61
|
+
type: boundedString(record.type, `${path} type`, CAMERA_MAX_IDENTIFIER_LENGTH),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function sessionEvent(value) {
|
|
65
|
+
const record = plainRecord(value, "Camera session event");
|
|
66
|
+
if (record.kind !== "started" &&
|
|
67
|
+
record.kind !== "stopped" &&
|
|
68
|
+
record.kind !== "interrupted" &&
|
|
69
|
+
record.kind !== "resumed" &&
|
|
70
|
+
record.kind !== "error") {
|
|
71
|
+
throw new TypeError("Camera session event kind is invalid.");
|
|
72
|
+
}
|
|
73
|
+
return Object.freeze({
|
|
74
|
+
kind: record.kind,
|
|
75
|
+
...(record.reason === undefined
|
|
76
|
+
? {}
|
|
77
|
+
: {
|
|
78
|
+
reason: boundedString(record.reason, "Camera session event reason", CAMERA_MAX_EVENT_REASON_LENGTH),
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function photoCaptureOptions(value) {
|
|
83
|
+
const record = plainRecord(value, "Camera photo capture options");
|
|
84
|
+
const flashMode = record.flashMode ?? "off";
|
|
85
|
+
if (flashMode !== "off" && flashMode !== "on" && flashMode !== "auto") {
|
|
86
|
+
throw new TypeError("Camera photo flash mode is invalid.");
|
|
87
|
+
}
|
|
88
|
+
const enableShutterSound = record.enableShutterSound ?? true;
|
|
89
|
+
if (typeof enableShutterSound !== "boolean") {
|
|
90
|
+
throw new TypeError("Camera photo shutter-sound preference must be a boolean.");
|
|
91
|
+
}
|
|
92
|
+
return Object.freeze({ flashMode, enableShutterSound });
|
|
93
|
+
}
|
|
94
|
+
function positiveDimension(value, path) {
|
|
95
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
96
|
+
throw new TypeError(`${path} must be a positive safe integer.`);
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
function photo(value) {
|
|
101
|
+
const record = plainRecord(value, "Captured camera photo");
|
|
102
|
+
if (record.orientation !== "up" &&
|
|
103
|
+
record.orientation !== "right" &&
|
|
104
|
+
record.orientation !== "down" &&
|
|
105
|
+
record.orientation !== "left") {
|
|
106
|
+
throw new TypeError("Captured camera photo orientation is invalid.");
|
|
107
|
+
}
|
|
108
|
+
if (record.containerFormat !== "jpeg" &&
|
|
109
|
+
record.containerFormat !== "heic" &&
|
|
110
|
+
record.containerFormat !== "dng" &&
|
|
111
|
+
record.containerFormat !== "tiff" &&
|
|
112
|
+
record.containerFormat !== "dcm" &&
|
|
113
|
+
record.containerFormat !== "unknown") {
|
|
114
|
+
throw new TypeError("Captured camera photo container format is invalid.");
|
|
115
|
+
}
|
|
116
|
+
if (typeof record.timestamp !== "number" ||
|
|
117
|
+
!Number.isFinite(record.timestamp) ||
|
|
118
|
+
record.timestamp < 0) {
|
|
119
|
+
throw new TypeError("Captured camera photo timestamp must be a finite non-negative number.");
|
|
120
|
+
}
|
|
121
|
+
if (typeof record.isMirrored !== "boolean") {
|
|
122
|
+
throw new TypeError("Captured camera photo mirrored state must be a boolean.");
|
|
123
|
+
}
|
|
124
|
+
return Object.freeze({
|
|
125
|
+
filePath: boundedString(record.filePath, "Captured camera photo file path", CAMERA_MAX_FILE_PATH_LENGTH),
|
|
126
|
+
width: positiveDimension(record.width, "Captured camera photo width"),
|
|
127
|
+
height: positiveDimension(record.height, "Captured camera photo height"),
|
|
128
|
+
orientation: record.orientation,
|
|
129
|
+
containerFormat: record.containerFormat,
|
|
130
|
+
timestamp: record.timestamp,
|
|
131
|
+
isMirrored: record.isMirrored,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function adapterMethod(adapter, name) {
|
|
135
|
+
if (typeof adapter[name] !== "function") {
|
|
136
|
+
throw new TypeError(`Camera adapter ${name} must be a function.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function reportSubscriptionError(error, options) {
|
|
140
|
+
try {
|
|
141
|
+
const reported = options.onError?.(error);
|
|
142
|
+
void Promise.resolve(reported).catch(() => undefined);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// A diagnostic callback cannot escape a native event boundary.
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function cameraSession(value, requestedPosition) {
|
|
149
|
+
const adapterSession = plainRecord(value, "Camera adapter session");
|
|
150
|
+
if (typeof adapterSession.subscribe !== "function") {
|
|
151
|
+
throw new TypeError("Camera adapter session subscribe must be a function.");
|
|
152
|
+
}
|
|
153
|
+
if (typeof adapterSession.capturePhoto !== "function") {
|
|
154
|
+
throw new TypeError("Camera adapter session capturePhoto must be a function.");
|
|
155
|
+
}
|
|
156
|
+
if (typeof adapterSession.stop !== "function") {
|
|
157
|
+
throw new TypeError("Camera adapter session stop must be a function.");
|
|
158
|
+
}
|
|
159
|
+
const normalizedDevice = device(adapterSession.device);
|
|
160
|
+
if (normalizedDevice.position !== requestedPosition) {
|
|
161
|
+
throw new Error("The camera adapter opened a different device position.");
|
|
162
|
+
}
|
|
163
|
+
let stopped = false;
|
|
164
|
+
let stopping = false;
|
|
165
|
+
let stopPromise;
|
|
166
|
+
const subscriptions = new Set();
|
|
167
|
+
const session = {
|
|
168
|
+
device: normalizedDevice,
|
|
169
|
+
get stopped() {
|
|
170
|
+
return stopped;
|
|
171
|
+
},
|
|
172
|
+
async capturePhoto(options = {}) {
|
|
173
|
+
if (stopping || stopped) {
|
|
174
|
+
throw new Error("Cannot capture a photo from a stopped camera session.");
|
|
175
|
+
}
|
|
176
|
+
const normalizedOptions = photoCaptureOptions(options);
|
|
177
|
+
return photo(await adapterSession.capturePhoto(normalizedOptions));
|
|
178
|
+
},
|
|
179
|
+
subscribe(listener, options = {}) {
|
|
180
|
+
if (typeof listener !== "function") {
|
|
181
|
+
throw new TypeError("Camera session listener must be a function.");
|
|
182
|
+
}
|
|
183
|
+
if (stopping || stopped) {
|
|
184
|
+
throw new Error("Cannot subscribe to a stopped camera session.");
|
|
185
|
+
}
|
|
186
|
+
let active = true;
|
|
187
|
+
let startedDelivered = false;
|
|
188
|
+
const deliver = (value) => {
|
|
189
|
+
if (!active)
|
|
190
|
+
return;
|
|
191
|
+
try {
|
|
192
|
+
const event = sessionEvent(value);
|
|
193
|
+
if (event.kind === "started") {
|
|
194
|
+
if (startedDelivered)
|
|
195
|
+
return;
|
|
196
|
+
startedDelivered = true;
|
|
197
|
+
}
|
|
198
|
+
const result = listener(event);
|
|
199
|
+
void Promise.resolve(result).catch((error) => {
|
|
200
|
+
reportSubscriptionError(error, options);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
reportSubscriptionError(error, options);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const remove = adapterSession.subscribe(deliver);
|
|
208
|
+
if (typeof remove !== "function") {
|
|
209
|
+
throw new TypeError("Camera adapter session subscribe must return a cleanup function.");
|
|
210
|
+
}
|
|
211
|
+
const cleanup = () => {
|
|
212
|
+
if (!active)
|
|
213
|
+
return;
|
|
214
|
+
active = false;
|
|
215
|
+
subscriptions.delete(cleanup);
|
|
216
|
+
remove();
|
|
217
|
+
};
|
|
218
|
+
subscriptions.add(cleanup);
|
|
219
|
+
// Opening a public session is the readiness boundary. Some native
|
|
220
|
+
// backends emit their started event while open() is still awaiting that
|
|
221
|
+
// readiness, before a public subscriber can exist. Replay it on the next
|
|
222
|
+
// event-loop turn and deduplicate a synchronous or late adapter callback.
|
|
223
|
+
// A separate turn also keeps subscription setup out of the first native
|
|
224
|
+
// rendering transaction that consumes the session.
|
|
225
|
+
const timers = globalThis;
|
|
226
|
+
timers.setTimeout(() => deliver({ kind: "started" }), 0);
|
|
227
|
+
return Object.freeze({ remove: cleanup });
|
|
228
|
+
},
|
|
229
|
+
stop() {
|
|
230
|
+
if (stopPromise === undefined) {
|
|
231
|
+
stopping = true;
|
|
232
|
+
stopPromise = Promise.resolve()
|
|
233
|
+
.then(() => adapterSession.stop())
|
|
234
|
+
.then(() => undefined)
|
|
235
|
+
.finally(() => {
|
|
236
|
+
stopped = true;
|
|
237
|
+
for (const cleanup of [...subscriptions])
|
|
238
|
+
cleanup();
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return stopPromise;
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
ADAPTER_SESSION_BY_CAMERA_SESSION.set(session, adapterSession);
|
|
245
|
+
return Object.freeze(session);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Narrows a camera backend to bounded, portable permission, device, session,
|
|
249
|
+
* capture, and lifecycle values. Native failures remain rejected promises.
|
|
250
|
+
*/
|
|
251
|
+
export function createCameraService(adapter) {
|
|
252
|
+
if (typeof adapter !== "object" || adapter === null) {
|
|
253
|
+
throw new TypeError("Camera adapter must be an object.");
|
|
254
|
+
}
|
|
255
|
+
adapterMethod(adapter, "getPermission");
|
|
256
|
+
adapterMethod(adapter, "requestPermission");
|
|
257
|
+
adapterMethod(adapter, "listDevices");
|
|
258
|
+
adapterMethod(adapter, "open");
|
|
259
|
+
return Object.freeze({
|
|
260
|
+
getPermission() {
|
|
261
|
+
return permission(adapter.getPermission());
|
|
262
|
+
},
|
|
263
|
+
async requestPermission() {
|
|
264
|
+
return permission(await adapter.requestPermission());
|
|
265
|
+
},
|
|
266
|
+
async listDevices() {
|
|
267
|
+
const value = await adapter.listDevices();
|
|
268
|
+
if (!Array.isArray(value)) {
|
|
269
|
+
throw new TypeError("The camera adapter returned a non-array device list.");
|
|
270
|
+
}
|
|
271
|
+
if (value.length > CAMERA_MAX_DEVICE_COUNT) {
|
|
272
|
+
throw new RangeError(`Camera devices cannot exceed ${CAMERA_MAX_DEVICE_COUNT} entries.`);
|
|
273
|
+
}
|
|
274
|
+
const devices = value.map((entry, index) => device(entry, `Camera device ${String(index)}`));
|
|
275
|
+
if (new Set(devices.map((entry) => entry.id)).size !== devices.length) {
|
|
276
|
+
throw new TypeError("Camera device ids must be unique.");
|
|
277
|
+
}
|
|
278
|
+
return Object.freeze(devices);
|
|
279
|
+
},
|
|
280
|
+
async open(requestedPosition) {
|
|
281
|
+
const normalizedPosition = targetPosition(requestedPosition);
|
|
282
|
+
if (permission(adapter.getPermission()).authorization !== "authorized") {
|
|
283
|
+
throw new Error("Camera permission must be authorized before opening.");
|
|
284
|
+
}
|
|
285
|
+
const adapterSession = await adapter.open(normalizedPosition);
|
|
286
|
+
try {
|
|
287
|
+
return cameraSession(adapterSession, normalizedPosition);
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
if (typeof adapterSession === "object" &&
|
|
291
|
+
adapterSession !== null &&
|
|
292
|
+
"stop" in adapterSession &&
|
|
293
|
+
typeof adapterSession.stop === "function") {
|
|
294
|
+
try {
|
|
295
|
+
await adapterSession.stop();
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
// Preserve the portable validation failure while best-effort
|
|
299
|
+
// releasing a malformed native session.
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAChD,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC;AAC7C,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AACpD,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAkFjD,MAAM,iCAAiC,GAAG,IAAI,OAAO,EAGlD,CAAC;AAEJ,yFAAyF;AACzF,MAAM,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,CAAC,CAAC;YAC3D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IACE,OAAO,cAAc,KAAK,QAAQ;oBAClC,cAAc,KAAK,IAAI;oBACvB,MAAM,IAAI,cAAc;oBACxB,OAAO,cAAc,CAAC,IAAI,KAAK,UAAU,EACzC,CAAC;oBACD,IAAI,CAAC;wBACH,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC;oBAC9B,CAAC;oBAAC,MAAM,CAAC;wBACP,6DAA6D;wBAC7D,wCAAwC;oBAC1C,CAAC;gBACH,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface NitroModuleRegistry {
|
|
2
|
+
getEnforcing(name: string): unknown;
|
|
3
|
+
}
|
|
4
|
+
export interface NitroRuntimeGlobals {
|
|
5
|
+
readonly NitroModulesProxy?: unknown;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Installs and resolves one pinned Nitro HybridObject without evaluating the
|
|
9
|
+
* package's React-facing barrel. The caller owns the exact native package pin.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveNitroHybridObject<T>(registry: NitroModuleRegistry, globals: NitroRuntimeGlobals, expectedVersion: string, hybridObjectName: string): T;
|
|
12
|
+
//# sourceMappingURL=nitro-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nitro-adapter.d.ts","sourceRoot":"","sources":["../src/nitro-adapter.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACrC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CACtC;AAoCD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,mBAAmB,EAC5B,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,GACvB,CAAC,CA8CH"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function isObjectLike(value) {
|
|
2
|
+
return ((typeof value === "object" && value !== null) || typeof value === "function");
|
|
3
|
+
}
|
|
4
|
+
function validateProxy(value, expectedVersion) {
|
|
5
|
+
if (!isObjectLike(value)) {
|
|
6
|
+
throw new TypeError("The installed Nitro Modules proxy must be an object.");
|
|
7
|
+
}
|
|
8
|
+
if (value.version !== expectedVersion) {
|
|
9
|
+
throw new Error(`The native Nitro Modules runtime must be ${expectedVersion}; received ${String(value.version)}.`);
|
|
10
|
+
}
|
|
11
|
+
if (typeof value.createHybridObject !== "function") {
|
|
12
|
+
throw new TypeError("The installed Nitro Modules proxy must create hybrid objects.");
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Installs and resolves one pinned Nitro HybridObject without evaluating the
|
|
18
|
+
* package's React-facing barrel. The caller owns the exact native package pin.
|
|
19
|
+
*/
|
|
20
|
+
export function resolveNitroHybridObject(registry, globals, expectedVersion, hybridObjectName) {
|
|
21
|
+
if (typeof registry?.getEnforcing !== "function") {
|
|
22
|
+
throw new TypeError("The Nitro TurboModule registry is unavailable.");
|
|
23
|
+
}
|
|
24
|
+
if (!/^[0-9A-Za-z][0-9A-Za-z.+-]{0,127}$/u.test(expectedVersion)) {
|
|
25
|
+
throw new TypeError("The expected Nitro Modules version is invalid.");
|
|
26
|
+
}
|
|
27
|
+
if (!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/u.test(hybridObjectName)) {
|
|
28
|
+
throw new TypeError("The Nitro hybrid-object name is invalid.");
|
|
29
|
+
}
|
|
30
|
+
let installed = globals.NitroModulesProxy;
|
|
31
|
+
if (installed === undefined) {
|
|
32
|
+
const candidate = registry.getEnforcing("NitroModules");
|
|
33
|
+
if (!isObjectLike(candidate) || typeof candidate.install !== "function") {
|
|
34
|
+
throw new TypeError("The NitroModules TurboModule must expose an install function.");
|
|
35
|
+
}
|
|
36
|
+
const result = candidate.install();
|
|
37
|
+
if (typeof result === "string") {
|
|
38
|
+
throw new Error(`The Nitro Modules runtime failed to install: ${result}`);
|
|
39
|
+
}
|
|
40
|
+
// Android's nullable String TurboModule return crosses JSI as null on
|
|
41
|
+
// success, while iOS and deterministic adapters may expose undefined.
|
|
42
|
+
if (result !== undefined && result !== null) {
|
|
43
|
+
throw new TypeError("The Nitro Modules installer returned an invalid result.");
|
|
44
|
+
}
|
|
45
|
+
installed = globals.NitroModulesProxy;
|
|
46
|
+
if (installed === undefined) {
|
|
47
|
+
throw new Error("The Nitro Modules installer did not publish its runtime proxy.");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const proxy = validateProxy(installed, expectedVersion);
|
|
51
|
+
const hybridObject = proxy.createHybridObject(hybridObjectName);
|
|
52
|
+
if (!isObjectLike(hybridObject)) {
|
|
53
|
+
throw new TypeError(`Nitro did not create the ${hybridObjectName} hybrid object.`);
|
|
54
|
+
}
|
|
55
|
+
return hybridObject;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=nitro-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nitro-adapter.js","sourceRoot":"","sources":["../src/nitro-adapter.ts"],"names":[],"mappings":"AAiBA,SAAS,YAAY,CACnB,KAAc;IAEd,OAAO,CACL,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,IAAI,OAAO,KAAK,KAAK,UAAU,CAC7E,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,KAAc,EAAE,eAAuB;IAC5D,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,SAAS,CAAC,sDAAsD,CAAC,CAAC;IAC9E,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,KAA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,gDAAgD,MAAM,EAAE,CAAC,CAAC;QAC5E,CAAC;QACD,sEAAsE;QACtE,sEAAsE;QACtE,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YAC5C,MAAM,IAAI,SAAS,CACjB,yDAAyD,CAC1D,CAAC;QACJ,CAAC;QACD,SAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACtC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,aAAa,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IACxD,MAAM,YAAY,GAAG,KAAK,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;IAChE,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CACjB,4BAA4B,gBAAgB,iBAAiB,CAC9D,CAAC;IACJ,CAAC;IACD,OAAO,YAAiB,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type NativeElementProps } from "@solidnative-dev/core";
|
|
2
|
+
import { type CameraService, type CameraSession } from "./index.js";
|
|
3
|
+
export declare const CAMERA_PREVIEW_RESOURCE_KIND: "vision-camera.preview-output";
|
|
4
|
+
export declare const CAMERA_PREVIEW_DESCRIPTOR: import("@solidnative-dev/host-contract").NativeComponentDescriptor;
|
|
5
|
+
export interface CameraPreviewProps extends NativeElementProps {
|
|
6
|
+
readonly session: CameraSession;
|
|
7
|
+
readonly resizeMode?: "cover" | "contain";
|
|
8
|
+
readonly implementationMode?: "performance" | "compatible";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Mounts VisionCamera's generated Fabric view without a React component tree.
|
|
12
|
+
* The preview output's exact JSI identity follows this Solid component owner.
|
|
13
|
+
*/
|
|
14
|
+
export declare function CameraPreview(props: CameraPreviewProps): import("@solidnative-dev/renderer").NativeNode;
|
|
15
|
+
export type { CameraAuthorization, CameraDevice, CameraFlashMode, CameraPermission, CameraPhoto, CameraPhotoCaptureOptions, CameraPhotoContainerFormat, CameraPhotoOrientation, CameraService, CameraSession, CameraSessionEvent, CameraTargetPosition, } from "./index.js";
|
|
16
|
+
/**
|
|
17
|
+
* Drives VisionCamera 5's imperative Nitro API directly. React hooks and a
|
|
18
|
+
* React component tree are not involved in permission, device, or session
|
|
19
|
+
* ownership.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createReactNativeCameraService(): CameraService;
|
|
22
|
+
//# sourceMappingURL=react-native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.d.ts","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,aAAa,EAEnB,MAAM,YAAY,CAAC;AAkBpB,eAAO,MAAM,4BAA4B,EACvC,8BAAuC,CAAC;AAC1C,eAAO,MAAM,yBAAyB,oEACU,CAAC;AAejD,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;IAC5D,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,kBAAkB,CAAC,EAAE,aAAa,GAAG,YAAY,CAAC;CAC5D;AAKD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,kDA6CtD;AAED,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,yBAAyB,EACzB,0BAA0B,EAC1B,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAiDpB;;;;GAIG;AACH,wBAAgB,8BAA8B,IAAI,aAAa,CAyQ9D"}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import * as TurboModuleRegistry from "react-native/Libraries/TurboModule/TurboModuleRegistry";
|
|
2
|
+
import { createNativeComponent, createNativeComponentDescriptor, } from "@solidnative-dev/core";
|
|
3
|
+
import { getNativeHostBinding, retainNativeResource, } from "@solidnative-dev/fabric-host";
|
|
4
|
+
import { createMemo, onCleanup } from "solid-js";
|
|
5
|
+
import { createCameraService, cameraAdapterSessionFor, } from "./index.js";
|
|
6
|
+
import { resolveNitroHybridObject } from "./nitro-adapter.js";
|
|
7
|
+
const VERIFIED_NITRO_MODULES_VERSION = "0.36.5";
|
|
8
|
+
let visionCamera;
|
|
9
|
+
function getVisionCamera() {
|
|
10
|
+
visionCamera ??= resolveNitroHybridObject(TurboModuleRegistry, globalThis, VERIFIED_NITRO_MODULES_VERSION, "CameraFactory");
|
|
11
|
+
return visionCamera;
|
|
12
|
+
}
|
|
13
|
+
export const CAMERA_PREVIEW_RESOURCE_KIND = "vision-camera.preview-output";
|
|
14
|
+
export const CAMERA_PREVIEW_DESCRIPTOR = createNativeComponentDescriptor("PreviewView");
|
|
15
|
+
const PREVIEW_OUTPUT_BY_ADAPTER_SESSION = new WeakMap();
|
|
16
|
+
const NativeCameraPreview = createNativeComponent("PreviewView");
|
|
17
|
+
/**
|
|
18
|
+
* Mounts VisionCamera's generated Fabric view without a React component tree.
|
|
19
|
+
* The preview output's exact JSI identity follows this Solid component owner.
|
|
20
|
+
*/
|
|
21
|
+
export function CameraPreview(props) {
|
|
22
|
+
const resource = createMemo(() => {
|
|
23
|
+
const adapterSession = cameraAdapterSessionFor(props.session);
|
|
24
|
+
const previewOutput = adapterSession === undefined
|
|
25
|
+
? undefined
|
|
26
|
+
: PREVIEW_OUTPUT_BY_ADAPTER_SESSION.get(adapterSession);
|
|
27
|
+
if (previewOutput === undefined) {
|
|
28
|
+
throw new Error("CameraPreview requires a running session created by the React Native camera adapter.");
|
|
29
|
+
}
|
|
30
|
+
const resource = retainNativeResource(getNativeHostBinding(), CAMERA_PREVIEW_RESOURCE_KIND, previewOutput);
|
|
31
|
+
onCleanup(() => resource.release());
|
|
32
|
+
return resource;
|
|
33
|
+
});
|
|
34
|
+
const nativeProps = new Proxy({}, {
|
|
35
|
+
get(_target, property) {
|
|
36
|
+
if (property === "session")
|
|
37
|
+
return undefined;
|
|
38
|
+
if (property === "previewOutput")
|
|
39
|
+
return resource().reference;
|
|
40
|
+
return Reflect.get(props, property, props);
|
|
41
|
+
},
|
|
42
|
+
getOwnPropertyDescriptor(_target, property) {
|
|
43
|
+
if (property === "session")
|
|
44
|
+
return undefined;
|
|
45
|
+
if (property === "previewOutput") {
|
|
46
|
+
return { configurable: true, enumerable: true };
|
|
47
|
+
}
|
|
48
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(props, property);
|
|
49
|
+
return descriptor === undefined
|
|
50
|
+
? undefined
|
|
51
|
+
: { ...descriptor, configurable: true };
|
|
52
|
+
},
|
|
53
|
+
ownKeys() {
|
|
54
|
+
const keys = Reflect.ownKeys(props).filter((property) => property !== "session");
|
|
55
|
+
if (!keys.includes("previewOutput"))
|
|
56
|
+
keys.push("previewOutput");
|
|
57
|
+
return keys;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
return NativeCameraPreview(nativeProps);
|
|
61
|
+
}
|
|
62
|
+
function authorization(value) {
|
|
63
|
+
switch (value) {
|
|
64
|
+
case "not-determined":
|
|
65
|
+
case "denied":
|
|
66
|
+
case "authorized":
|
|
67
|
+
case "restricted":
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function position(value) {
|
|
72
|
+
switch (value) {
|
|
73
|
+
case "front":
|
|
74
|
+
case "back":
|
|
75
|
+
case "external":
|
|
76
|
+
case "unspecified":
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function cameraDevice(value) {
|
|
81
|
+
return {
|
|
82
|
+
id: value.id,
|
|
83
|
+
name: value.localizedName,
|
|
84
|
+
position: position(value.position),
|
|
85
|
+
type: value.type,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function errorReason(value) {
|
|
89
|
+
return value instanceof Error ? value.message : String(value);
|
|
90
|
+
}
|
|
91
|
+
function disposeHybridObjects(objects) {
|
|
92
|
+
for (const object of objects) {
|
|
93
|
+
if (object === undefined)
|
|
94
|
+
continue;
|
|
95
|
+
try {
|
|
96
|
+
object.dispose();
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Eager disposal is best-effort; one wrapper cannot prevent the others
|
|
100
|
+
// from releasing after the native resource has been disconnected.
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Drives VisionCamera 5's imperative Nitro API directly. React hooks and a
|
|
106
|
+
* React component tree are not involved in permission, device, or session
|
|
107
|
+
* ownership.
|
|
108
|
+
*/
|
|
109
|
+
export function createReactNativeCameraService() {
|
|
110
|
+
const camera = getVisionCamera();
|
|
111
|
+
return createCameraService({
|
|
112
|
+
getPermission() {
|
|
113
|
+
return {
|
|
114
|
+
authorization: authorization(camera.cameraPermissionStatus),
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
async requestPermission() {
|
|
118
|
+
if (camera.cameraPermissionStatus === "not-determined") {
|
|
119
|
+
await camera.requestCameraPermission();
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
authorization: authorization(camera.cameraPermissionStatus),
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
async listDevices() {
|
|
126
|
+
const factory = await camera.createDeviceFactory();
|
|
127
|
+
try {
|
|
128
|
+
const devices = factory.cameraDevices;
|
|
129
|
+
try {
|
|
130
|
+
return devices.map(cameraDevice);
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
disposeHybridObjects(devices);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
disposeHybridObjects([factory]);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
async open(requestedPosition) {
|
|
141
|
+
const factory = await camera.createDeviceFactory();
|
|
142
|
+
let selectedForFailedAcquisition;
|
|
143
|
+
let previewForFailedAcquisition;
|
|
144
|
+
const { selectedDevice, photoOutput, previewOutput } = (() => {
|
|
145
|
+
try {
|
|
146
|
+
const selectedDevice = factory.getDefaultCamera(requestedPosition);
|
|
147
|
+
selectedForFailedAcquisition = selectedDevice;
|
|
148
|
+
if (selectedDevice === undefined) {
|
|
149
|
+
throw new Error(`No ${requestedPosition} camera is available on this device.`);
|
|
150
|
+
}
|
|
151
|
+
const previewOutput = camera.createPreviewOutput();
|
|
152
|
+
previewForFailedAcquisition = previewOutput;
|
|
153
|
+
const photoResolutions = selectedDevice.getSupportedResolutions("photo");
|
|
154
|
+
const targetResolution = photoResolutions.reduce((smallest, candidate) => {
|
|
155
|
+
if (smallest === undefined)
|
|
156
|
+
return candidate;
|
|
157
|
+
return candidate.width * candidate.height <
|
|
158
|
+
smallest.width * smallest.height
|
|
159
|
+
? candidate
|
|
160
|
+
: smallest;
|
|
161
|
+
}, undefined);
|
|
162
|
+
if (targetResolution === undefined) {
|
|
163
|
+
throw new Error(`The ${requestedPosition} camera has no supported photo resolution.`);
|
|
164
|
+
}
|
|
165
|
+
const photoOutput = camera.createPhotoOutput({
|
|
166
|
+
targetResolution,
|
|
167
|
+
containerFormat: "jpeg",
|
|
168
|
+
quality: 0.8,
|
|
169
|
+
qualityPrioritization: "balanced",
|
|
170
|
+
});
|
|
171
|
+
return { selectedDevice, photoOutput, previewOutput };
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
disposeHybridObjects([
|
|
175
|
+
previewForFailedAcquisition,
|
|
176
|
+
selectedForFailedAcquisition,
|
|
177
|
+
factory,
|
|
178
|
+
]);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
})();
|
|
182
|
+
let nativeSession;
|
|
183
|
+
try {
|
|
184
|
+
nativeSession = await camera.createCameraSession(false);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
disposeHybridObjects([
|
|
188
|
+
photoOutput,
|
|
189
|
+
previewOutput,
|
|
190
|
+
selectedDevice,
|
|
191
|
+
factory,
|
|
192
|
+
]);
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
const nativeControllers = [];
|
|
196
|
+
const listeners = new Set();
|
|
197
|
+
const emit = (event) => {
|
|
198
|
+
for (const listener of [...listeners])
|
|
199
|
+
listener(event);
|
|
200
|
+
};
|
|
201
|
+
let nativeStartSettled = false;
|
|
202
|
+
let resolveNativeStart;
|
|
203
|
+
let rejectNativeStart;
|
|
204
|
+
const nativeStart = new Promise((resolve, reject) => {
|
|
205
|
+
resolveNativeStart = () => {
|
|
206
|
+
if (nativeStartSettled)
|
|
207
|
+
return;
|
|
208
|
+
nativeStartSettled = true;
|
|
209
|
+
resolve();
|
|
210
|
+
};
|
|
211
|
+
rejectNativeStart = (error) => {
|
|
212
|
+
if (nativeStartSettled)
|
|
213
|
+
return;
|
|
214
|
+
nativeStartSettled = true;
|
|
215
|
+
reject(error);
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
// Configuration can fail before the readiness boundary is awaited.
|
|
219
|
+
// Register a rejection observer immediately to avoid an unhandled native
|
|
220
|
+
// error while still preserving the original promise for the await below.
|
|
221
|
+
void nativeStart.catch(() => undefined);
|
|
222
|
+
const nativeSubscriptions = [
|
|
223
|
+
nativeSession.addOnStartedListener(() => {
|
|
224
|
+
emit({ kind: "started" });
|
|
225
|
+
resolveNativeStart();
|
|
226
|
+
}),
|
|
227
|
+
nativeSession.addOnStoppedListener(() => emit({ kind: "stopped" })),
|
|
228
|
+
nativeSession.addOnErrorListener((error) => {
|
|
229
|
+
const reason = errorReason(error);
|
|
230
|
+
emit({ kind: "error", reason });
|
|
231
|
+
rejectNativeStart(new Error(reason));
|
|
232
|
+
}),
|
|
233
|
+
nativeSession.addOnInterruptionStartedListener((reason) => emit({ kind: "interrupted", reason })),
|
|
234
|
+
nativeSession.addOnInterruptionEndedListener(() => emit({ kind: "resumed" })),
|
|
235
|
+
];
|
|
236
|
+
const removeNativeSubscriptions = () => {
|
|
237
|
+
for (const subscription of nativeSubscriptions)
|
|
238
|
+
subscription.remove();
|
|
239
|
+
};
|
|
240
|
+
let nativeObjectsDisposed = false;
|
|
241
|
+
const disposeNativeObjects = () => {
|
|
242
|
+
if (nativeObjectsDisposed)
|
|
243
|
+
return;
|
|
244
|
+
nativeObjectsDisposed = true;
|
|
245
|
+
const objects = [
|
|
246
|
+
...nativeControllers,
|
|
247
|
+
photoOutput,
|
|
248
|
+
previewOutput,
|
|
249
|
+
selectedDevice,
|
|
250
|
+
nativeSession,
|
|
251
|
+
factory,
|
|
252
|
+
];
|
|
253
|
+
disposeHybridObjects(objects);
|
|
254
|
+
};
|
|
255
|
+
try {
|
|
256
|
+
const controllers = await nativeSession.configure([
|
|
257
|
+
{
|
|
258
|
+
input: selectedDevice,
|
|
259
|
+
outputs: [
|
|
260
|
+
{ output: previewOutput, mirrorMode: "off" },
|
|
261
|
+
{ output: photoOutput, mirrorMode: "off" },
|
|
262
|
+
],
|
|
263
|
+
constraints: [],
|
|
264
|
+
},
|
|
265
|
+
]);
|
|
266
|
+
nativeControllers.push(...controllers);
|
|
267
|
+
if (controllers.length !== 1) {
|
|
268
|
+
throw new Error("VisionCamera did not return exactly one camera controller.");
|
|
269
|
+
}
|
|
270
|
+
await nativeSession.start();
|
|
271
|
+
if (nativeSession.isRunning)
|
|
272
|
+
resolveNativeStart();
|
|
273
|
+
const timers = globalThis;
|
|
274
|
+
const timeoutHandle = timers.setTimeout(() => {
|
|
275
|
+
rejectNativeStart(new Error("VisionCamera session did not start within 10 seconds."));
|
|
276
|
+
}, 10_000);
|
|
277
|
+
try {
|
|
278
|
+
// On CameraX, start() activates the lifecycle before the hardware has
|
|
279
|
+
// reached OPEN. The native started callback is the readiness boundary.
|
|
280
|
+
await nativeStart;
|
|
281
|
+
}
|
|
282
|
+
finally {
|
|
283
|
+
timers.clearTimeout(timeoutHandle);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
removeNativeSubscriptions();
|
|
288
|
+
try {
|
|
289
|
+
await nativeSession.stop();
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
// Preserve the configuration/start failure.
|
|
293
|
+
}
|
|
294
|
+
disposeNativeObjects();
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
let captureTail = Promise.resolve();
|
|
298
|
+
let stopPromise;
|
|
299
|
+
const adapterSession = {
|
|
300
|
+
device: cameraDevice(selectedDevice),
|
|
301
|
+
capturePhoto(options) {
|
|
302
|
+
if (stopPromise !== undefined) {
|
|
303
|
+
return Promise.reject(new Error("Cannot capture a photo while the camera is stopping."));
|
|
304
|
+
}
|
|
305
|
+
const capture = captureTail.then(async () => {
|
|
306
|
+
const photo = await photoOutput.capturePhoto({
|
|
307
|
+
flashMode: options.flashMode ?? "off",
|
|
308
|
+
enableShutterSound: options.enableShutterSound ?? true,
|
|
309
|
+
}, {});
|
|
310
|
+
try {
|
|
311
|
+
const filePath = await photo.saveToTemporaryFileAsync();
|
|
312
|
+
return {
|
|
313
|
+
filePath,
|
|
314
|
+
width: photo.width,
|
|
315
|
+
height: photo.height,
|
|
316
|
+
orientation: photo.orientation,
|
|
317
|
+
containerFormat: photo.containerFormat,
|
|
318
|
+
timestamp: photo.timestamp,
|
|
319
|
+
isMirrored: photo.isMirrored,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
finally {
|
|
323
|
+
photo.dispose();
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
captureTail = capture.then(() => undefined, () => undefined);
|
|
327
|
+
return capture;
|
|
328
|
+
},
|
|
329
|
+
subscribe(listener) {
|
|
330
|
+
listeners.add(listener);
|
|
331
|
+
return () => listeners.delete(listener);
|
|
332
|
+
},
|
|
333
|
+
stop() {
|
|
334
|
+
stopPromise ??= (async () => {
|
|
335
|
+
let stopFailure;
|
|
336
|
+
await captureTail;
|
|
337
|
+
try {
|
|
338
|
+
await nativeSession.stop();
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
stopFailure = error;
|
|
342
|
+
}
|
|
343
|
+
try {
|
|
344
|
+
await nativeSession.configure([]);
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
stopFailure ??= error;
|
|
348
|
+
}
|
|
349
|
+
if (stopFailure !== undefined)
|
|
350
|
+
throw stopFailure;
|
|
351
|
+
})().finally(() => {
|
|
352
|
+
PREVIEW_OUTPUT_BY_ADAPTER_SESSION.delete(adapterSession);
|
|
353
|
+
removeNativeSubscriptions();
|
|
354
|
+
listeners.clear();
|
|
355
|
+
disposeNativeObjects();
|
|
356
|
+
});
|
|
357
|
+
return stopPromise;
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
PREVIEW_OUTPUT_BY_ADAPTER_SESSION.set(adapterSession, previewOutput);
|
|
361
|
+
return adapterSession;
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,mBAAmB,MAAM,wDAAwD,CAAC;AAC9F,OAAO,EACL,qBAAqB,EACrB,+BAA+B,GAEhC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GAErB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEjD,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GAOxB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;A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CAAC,OAAO,CAAC,GAAG,EAAE;wBAChB,iCAAiC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;wBACzD,yBAAyB,EAAE,CAAC;wBAC5B,SAAS,CAAC,KAAK,EAAE,CAAC;wBAClB,oBAAoB,EAAE,CAAC;oBACzB,CAAC,CAAC,CAAC;oBACH,OAAO,WAAW,CAAC;gBACrB,CAAC;aACF,CAAC;YACF,iCAAiC,CAAC,GAAG,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;YACrE,OAAO,cAAc,CAAC;QACxB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/solid.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Accessor } from "solid-js";
|
|
2
|
+
import { type CameraDevice, type CameraService, type CameraSession, type CameraSessionEvent, type CameraSubscriptionOptions, type CameraTargetPosition } from "./index.js";
|
|
3
|
+
export interface CameraSessionEventAccessorOptions extends CameraSubscriptionOptions {
|
|
4
|
+
readonly initialValue?: CameraSessionEvent;
|
|
5
|
+
}
|
|
6
|
+
export type CameraSessionEventSource = CameraSession | Accessor<CameraSession | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Projects validated native camera-session events into one fine-grained Solid
|
|
9
|
+
* accessor and binds subscription replacement to the current owner.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createCameraSessionEvent(source: CameraSessionEventSource, options?: CameraSessionEventAccessorOptions): Accessor<CameraSessionEvent | undefined>;
|
|
12
|
+
export type OwnedCameraSessionState = "starting" | "running" | "stopping" | "stopped" | "failed";
|
|
13
|
+
export interface OwnedCameraSessionOptions {
|
|
14
|
+
readonly position: CameraTargetPosition;
|
|
15
|
+
readonly onError?: (error: unknown) => unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface OwnedCameraSession {
|
|
18
|
+
readonly state: Accessor<OwnedCameraSessionState>;
|
|
19
|
+
readonly device: Accessor<CameraDevice | undefined>;
|
|
20
|
+
readonly ready: Promise<CameraSession>;
|
|
21
|
+
stop(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Opens an imperative camera session immediately and binds its native
|
|
25
|
+
* listeners and asynchronous stop boundary to the current Solid owner.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createOwnedCameraSession(service: CameraService, options: OwnedCameraSessionOptions): OwnedCameraSession;
|
|
28
|
+
//# sourceMappingURL=solid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.d.ts","sourceRoot":"","sources":["../src/solid.ts"],"names":[],"mappings":"AACA,OAAO,EAAyC,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEhF,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EAGvB,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EAC1B,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,iCAAkC,SAAQ,yBAAyB;IAClF,QAAQ,CAAC,YAAY,CAAC,EAAE,kBAAkB,CAAC;CAC5C;AAED,MAAM,MAAM,wBAAwB,GAClC,aAAa,GAAG,QAAQ,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;AAsBtD;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,wBAAwB,EAChC,OAAO,GAAE,iCAAsC,GAC9C,QAAQ,CAAC,kBAAkB,GAAG,SAAS,CAAC,CA2D1C;AAED,MAAM,MAAM,uBAAuB,GACjC,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE7D,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CAChD;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC;IAClD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IACpD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACvC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAWD;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,yBAAyB,GACjC,kBAAkB,CA+DpB"}
|
package/dist/solid.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createCausalPlatformEventHandler } from "@solidnative-dev/core";
|
|
2
|
+
import { createEffect, createSignal, onCleanup } from "solid-js";
|
|
3
|
+
import {} from "./index.js";
|
|
4
|
+
const CAMERA_SESSION_EVENT_NAMES = Object.freeze({
|
|
5
|
+
started: "platform.camera.session.started",
|
|
6
|
+
stopped: "platform.camera.session.stopped",
|
|
7
|
+
interrupted: "platform.camera.session.interrupted",
|
|
8
|
+
resumed: "platform.camera.session.resumed",
|
|
9
|
+
error: "platform.camera.session.error",
|
|
10
|
+
});
|
|
11
|
+
function reportAccessorError(error, options) {
|
|
12
|
+
try {
|
|
13
|
+
const reported = options.onError?.(error);
|
|
14
|
+
void Promise.resolve(reported).catch(() => undefined);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// Diagnostics cannot break subscription handoff or owner disposal.
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Projects validated native camera-session events into one fine-grained Solid
|
|
22
|
+
* accessor and binds subscription replacement to the current owner.
|
|
23
|
+
*/
|
|
24
|
+
export function createCameraSessionEvent(source, options = {}) {
|
|
25
|
+
const [event, setEvent] = createSignal(options.initialValue);
|
|
26
|
+
const handlers = Object.freeze({
|
|
27
|
+
started: createCausalPlatformEventHandler(CAMERA_SESSION_EVENT_NAMES.started, setEvent),
|
|
28
|
+
stopped: createCausalPlatformEventHandler(CAMERA_SESSION_EVENT_NAMES.stopped, setEvent),
|
|
29
|
+
interrupted: createCausalPlatformEventHandler(CAMERA_SESSION_EVENT_NAMES.interrupted, setEvent),
|
|
30
|
+
resumed: createCausalPlatformEventHandler(CAMERA_SESSION_EVENT_NAMES.resumed, setEvent),
|
|
31
|
+
error: createCausalPlatformEventHandler(CAMERA_SESSION_EVENT_NAMES.error, setEvent),
|
|
32
|
+
});
|
|
33
|
+
let removeSubscription;
|
|
34
|
+
const removeCurrentSubscription = () => {
|
|
35
|
+
const remove = removeSubscription;
|
|
36
|
+
removeSubscription = undefined;
|
|
37
|
+
if (remove === undefined)
|
|
38
|
+
return;
|
|
39
|
+
try {
|
|
40
|
+
remove();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
reportAccessorError(error, options);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
createEffect(() => (typeof source === "function" ? source() : source), (session) => {
|
|
47
|
+
removeCurrentSubscription();
|
|
48
|
+
if (session === undefined)
|
|
49
|
+
return;
|
|
50
|
+
try {
|
|
51
|
+
const subscription = session.subscribe((nextEvent) => handlers[nextEvent.kind](nextEvent), options);
|
|
52
|
+
removeSubscription = () => subscription.remove();
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
reportAccessorError(error, options);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
onCleanup(removeCurrentSubscription);
|
|
59
|
+
return event;
|
|
60
|
+
}
|
|
61
|
+
function reportError(error, options) {
|
|
62
|
+
try {
|
|
63
|
+
const reported = options.onError?.(error);
|
|
64
|
+
void Promise.resolve(reported).catch(() => undefined);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Owner cleanup and native event delivery cannot be broken by diagnostics.
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Opens an imperative camera session immediately and binds its native
|
|
72
|
+
* listeners and asynchronous stop boundary to the current Solid owner.
|
|
73
|
+
*/
|
|
74
|
+
export function createOwnedCameraSession(service, options) {
|
|
75
|
+
const [state, setState] = createSignal("starting");
|
|
76
|
+
const [device, setDevice] = createSignal();
|
|
77
|
+
let ownerActive = true;
|
|
78
|
+
let openingFailed = false;
|
|
79
|
+
let subscription;
|
|
80
|
+
let stopPromise;
|
|
81
|
+
const ready = service.open(options.position).then(async (session) => {
|
|
82
|
+
setDevice(session.device);
|
|
83
|
+
subscription = session.subscribe((event) => {
|
|
84
|
+
if (event.kind === "stopped")
|
|
85
|
+
setState("stopped");
|
|
86
|
+
if (event.kind === "error") {
|
|
87
|
+
setState("failed");
|
|
88
|
+
reportError(new Error(event.reason ?? "Native camera session failed."), options);
|
|
89
|
+
}
|
|
90
|
+
}, { onError: (error) => reportError(error, options) });
|
|
91
|
+
if (!ownerActive) {
|
|
92
|
+
setState("stopping");
|
|
93
|
+
await session.stop();
|
|
94
|
+
setState("stopped");
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
setState("running");
|
|
98
|
+
}
|
|
99
|
+
return session;
|
|
100
|
+
});
|
|
101
|
+
void ready.catch((error) => {
|
|
102
|
+
openingFailed = true;
|
|
103
|
+
if (ownerActive)
|
|
104
|
+
setState("failed");
|
|
105
|
+
reportError(error, options);
|
|
106
|
+
});
|
|
107
|
+
const stop = () => {
|
|
108
|
+
if (stopPromise !== undefined)
|
|
109
|
+
return stopPromise;
|
|
110
|
+
ownerActive = false;
|
|
111
|
+
if (state() !== "stopped" && state() !== "failed") {
|
|
112
|
+
setState("stopping");
|
|
113
|
+
}
|
|
114
|
+
stopPromise = ready
|
|
115
|
+
.then((session) => session.stop())
|
|
116
|
+
.then(() => {
|
|
117
|
+
subscription?.remove();
|
|
118
|
+
setState("stopped");
|
|
119
|
+
})
|
|
120
|
+
.catch((error) => {
|
|
121
|
+
setState("failed");
|
|
122
|
+
if (!openingFailed)
|
|
123
|
+
reportError(error, options);
|
|
124
|
+
throw error;
|
|
125
|
+
});
|
|
126
|
+
return stopPromise;
|
|
127
|
+
};
|
|
128
|
+
onCleanup(() => {
|
|
129
|
+
void stop().catch(() => undefined);
|
|
130
|
+
});
|
|
131
|
+
return Object.freeze({ state, device, ready, stop });
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=solid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.js","sourceRoot":"","sources":["../src/solid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAiB,MAAM,UAAU,CAAC;AAEhF,OAAO,EASN,MAAM,YAAY,CAAC;AASpB,MAAM,0BAA0B,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/C,OAAO,EAAE,iCAAiC;IAC1C,OAAO,EAAE,iCAAiC;IAC1C,WAAW,EAAE,qCAAqC;IAClD,OAAO,EAAE,iCAAiC;IAC1C,KAAK,EAAE,+BAA+B;CACU,CAAC,CAAC;AAEpD,SAAS,mBAAmB,CAC1B,KAAc,EACd,OAA0C;IAE1C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;QAC1C,KAAK,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,mEAAmE;IACrE,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAAgC,EAChC,UAA6C,EAAE;IAE/C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,YAAY,CACpC,OAAO,CAAC,YAAY,CACrB,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,OAAO,EAAE,gCAAgC,CACvC,0BAA0B,CAAC,OAAO,EAClC,QAAQ,CACT;QACD,OAAO,EAAE,g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KAAK,CAAC;QACd,CAAC,CAAC,CAAC;QACL,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACvD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidnative-dev/camera",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Validated camera sessions, photo capture, and Solid-owned native previews.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://solidnative.dev",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/solid-native/solid-native.git",
|
|
11
|
+
"directory": "packages/camera"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": "^22.13.0 || ^24.3.0 || >=26.0.0"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./solid": {
|
|
25
|
+
"types": "./dist/solid.d.ts",
|
|
26
|
+
"default": "./dist/solid.js"
|
|
27
|
+
},
|
|
28
|
+
"./react-native": {
|
|
29
|
+
"types": "./dist/react-native.d.ts",
|
|
30
|
+
"default": "./dist/react-native.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@solidnative-dev/core": "0.1.0-alpha.0",
|
|
38
|
+
"@solidnative-dev/fabric-host": "0.1.0-alpha.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react-native-nitro-image": "0.15.1",
|
|
42
|
+
"react-native-nitro-modules": "0.36.5",
|
|
43
|
+
"react-native-vision-camera": "5.2.2",
|
|
44
|
+
"solid-js": "2.0.4"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"react-native-nitro-image": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"react-native-nitro-modules": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"react-native-vision-camera": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"react-native-nitro-image": "0.15.1",
|
|
59
|
+
"react-native-nitro-modules": "0.36.5",
|
|
60
|
+
"react-native-vision-camera": "5.2.2",
|
|
61
|
+
"solid-js": "2.0.4"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "tsc -p tsconfig.json",
|
|
65
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
66
|
+
"test": "pnpm build && node --conditions=browser --test test/*.test.mjs"
|
|
67
|
+
}
|
|
6
68
|
}
|