@octane-xplat/camera 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -132
- package/package.json +108 -103
- package/platforms/android/java/com/octanexplat/camera/CameraPreviewView.java +24 -0
- package/platforms/android/java/com/octanexplat/camera/CameraSessionBridge.java +153 -21
- package/platforms/ios/src/XplatSwitchingMovieWriter.swift +557 -0
- package/src/CameraView.android.tsrx +194 -118
- package/src/CameraView.ios.tsrx +129 -76
- package/src/CameraView.macos.tsrx +108 -70
- package/src/CameraView.tsrx +2 -0
- package/src/CameraView.web.tsrx +160 -125
- package/src/CameraView.windows.tsrx +141 -92
- package/src/camera-host.macos.ts +1059 -0
- package/src/camera-permission.mobile.ts +85 -81
- package/src/camera-permission.windows.ts +56 -53
- package/src/camera-session.ios.ts +89 -61
- package/src/camera-session.macos.ts +51 -49
- package/src/camera-session.windows.ts +113 -105
- package/src/host-movie.web.ts +266 -222
- package/src/index.ts +28 -26
- package/src/index.web.ts +27 -25
- package/src/layout-child.ts +88 -79
- package/src/layout-child.web.ts +57 -51
- package/src/layout-child.windows.ts +82 -71
- package/src/movie-metadata.web.ts +87 -74
- package/src/movie-storage.web.ts +142 -135
- package/src/movie-writer.ios.ts +170 -0
- package/src/photo-lifecycle.macos.ts +60 -0
- package/src/photo-sheet.macos.ts +505 -0
- package/src/preview-display.ios.ts +69 -0
- package/src/preview-pinch.ts +41 -0
- package/src/preview-tap.ts +22 -21
- package/src/props.ts +118 -68
- package/src/recording-haptics.ios.ts +39 -0
- package/src/recording-source.web.ts +159 -0
- package/src/session-backend.android.ts +552 -410
- package/src/session-backend.ios.ts +1500 -1148
- package/src/session-backend.linux.ts +886 -860
- package/src/session-backend.macos.ts +697 -679
- package/src/session-backend.ts +51 -49
- package/src/session-backend.web.ts +1181 -867
- package/src/session-backend.windows.ts +1556 -1467
- package/src/session-core.ts +925 -711
- package/src/session.ts +12 -12
- package/src/style-merge.ts +43 -43
- package/src/synthetic-session.ts +392 -333
- package/src/types.ts +384 -239
- package/types/generated/.tsrx-typegen-manifest.json +18 -0
- package/types/generated/CameraView.d.ts +2 -0
- package/types/generated/CameraView.web.d.ts +4 -0
- package/types/generated/camera-host.macos.d.ts +33 -0
- package/types/generated/index.d.ts +34 -0
- package/types/generated/layout-child.web.d.ts +7 -0
- package/types/generated/photo-lifecycle.macos.d.ts +12 -0
- package/types/generated/photo-sheet.macos.d.ts +36 -0
- package/types/generated/props.d.ts +111 -0
- package/types/generated/session-backend.d.ts +6 -0
- package/types/{session-core.d.ts → generated/session-core.d.ts} +30 -1
- package/types/generated/session.d.ts +16 -0
- package/types/{synthetic-session.d.ts → generated/synthetic-session.d.ts} +15 -1
- package/types/{types.d.ts → generated/types.d.ts} +145 -2
- package/LICENSE +0 -21
- package/platforms/macos/src/CameraOwnership.swift +0 -22
- package/platforms/macos/src/PhotoCaptureLifecycle.swift +0 -34
- package/platforms/macos/src/XplatCameraHost.swift +0 -639
- package/platforms/macos/src/XplatPhotoCaptureSheet.swift +0 -192
- package/types/index.d.ts +0 -48
- package/types/props.d.ts +0 -61
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import AppKit
|
|
2
|
-
import AVFoundation
|
|
3
|
-
|
|
4
|
-
/// App-owned still-photo UI. No microphone input, movie output or Photos writes.
|
|
5
|
-
@objc(XplatPhotoCaptureSheet)
|
|
6
|
-
public final class XplatPhotoCaptureSheet: NSObject, NSWindowDelegate {
|
|
7
|
-
private let host = XplatCameraHost()
|
|
8
|
-
private let lifecycle = PhotoCaptureLifecycle()
|
|
9
|
-
private var sheet: NSWindow?
|
|
10
|
-
private weak var parent: NSWindow?
|
|
11
|
-
private var reply: ((String?) -> Void)?
|
|
12
|
-
private var timeout: DispatchWorkItem?
|
|
13
|
-
private var closeObserver: NSObjectProtocol?
|
|
14
|
-
private var preview: NSView?
|
|
15
|
-
private var captureButton: NSButton?
|
|
16
|
-
private var statusLabel: NSTextField?
|
|
17
|
-
private var options: NSDictionary = [:]
|
|
18
|
-
private var disposed = false
|
|
19
|
-
var operationTimeout: TimeInterval = 15
|
|
20
|
-
|
|
21
|
-
@objc public func permissionStatus() -> NSString { host.permissionStatus("camera") }
|
|
22
|
-
|
|
23
|
-
@objc public func present(_ options: NSDictionary, reply: @escaping (String?) -> Void) {
|
|
24
|
-
guard let parent = NSApp.keyWindow ?? NSApp.mainWindow else { reply(nil); return }
|
|
25
|
-
presentOnWindow(parent, options: options, reply: reply)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Explicit host window also allows deterministic AppKit lifecycle checks.
|
|
29
|
-
func presentOnWindow(_ parent: NSWindow, options: NSDictionary, reply: @escaping (String?) -> Void) {
|
|
30
|
-
guard !disposed, sheet == nil, parent.attachedSheet == nil,
|
|
31
|
-
!(options["saveToGallery"] as? Bool ?? false)
|
|
32
|
-
else { reply(nil); return }
|
|
33
|
-
self.options = options
|
|
34
|
-
self.reply = reply
|
|
35
|
-
self.parent = parent
|
|
36
|
-
let sheet = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 640, height: 480),
|
|
37
|
-
styleMask: [.titled, .closable], backing: .buffered, defer: false)
|
|
38
|
-
sheet.title = "Take a photo"
|
|
39
|
-
sheet.delegate = self
|
|
40
|
-
let content = NSView(frame: NSRect(x: 0, y: 0, width: 640, height: 480))
|
|
41
|
-
let preview = NSView(frame: NSRect(x: 16, y: 80, width: 608, height: 384))
|
|
42
|
-
preview.wantsLayer = true
|
|
43
|
-
preview.layer?.backgroundColor = NSColor.black.cgColor
|
|
44
|
-
content.addSubview(preview)
|
|
45
|
-
let status = NSTextField(labelWithString: "Choose Capture to start the camera.")
|
|
46
|
-
status.frame = NSRect(x: 16, y: 48, width: 440, height: 22)
|
|
47
|
-
content.addSubview(status)
|
|
48
|
-
let cancel = NSButton(title: "Cancel", target: self, action: #selector(cancelPhoto))
|
|
49
|
-
cancel.keyEquivalent = "\u{1b}"
|
|
50
|
-
cancel.frame = NSRect(x: 432, y: 12, width: 92, height: 32)
|
|
51
|
-
content.addSubview(cancel)
|
|
52
|
-
let capture = NSButton(title: "Capture", target: self, action: #selector(capturePhoto))
|
|
53
|
-
capture.keyEquivalent = "\r"
|
|
54
|
-
capture.frame = NSRect(x: 528, y: 12, width: 96, height: 32)
|
|
55
|
-
content.addSubview(capture)
|
|
56
|
-
sheet.contentView = content
|
|
57
|
-
self.sheet = sheet
|
|
58
|
-
self.preview = preview
|
|
59
|
-
statusLabel = status
|
|
60
|
-
captureButton = capture
|
|
61
|
-
closeObserver = NotificationCenter.default.addObserver(forName: NSWindow.willCloseNotification,
|
|
62
|
-
object: parent, queue: .main) { [weak self] _ in self?.complete(nil) }
|
|
63
|
-
parent.beginSheet(sheet) { [weak self] _ in self?.complete(nil) }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private func deadline(_ token: Int) {
|
|
67
|
-
timeout?.cancel()
|
|
68
|
-
let work = DispatchWorkItem { [weak self] in
|
|
69
|
-
guard let self, lifecycle.accepts(token) else { return }
|
|
70
|
-
complete(nil)
|
|
71
|
-
}
|
|
72
|
-
timeout = work
|
|
73
|
-
DispatchQueue.main.asyncAfter(deadline: .now() + operationTimeout, execute: work)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@objc private func capturePhoto() {
|
|
77
|
-
if let token = lifecycle.prepare() {
|
|
78
|
-
captureButton?.isEnabled = false
|
|
79
|
-
statusLabel?.stringValue = "Starting camera…"
|
|
80
|
-
deadline(token)
|
|
81
|
-
// Authorization happens only after the user presses Capture.
|
|
82
|
-
host.requestPermission("camera") { [weak self] status in
|
|
83
|
-
guard let self, lifecycle.accepts(token) else { return }
|
|
84
|
-
guard status == "granted" else { complete(nil); return }
|
|
85
|
-
DispatchQueue.global(qos: .userInitiated).async { [self] in
|
|
86
|
-
let failure = self.host.configure(["photo": true, "audio": false])
|
|
87
|
-
DispatchQueue.main.async { [self] in
|
|
88
|
-
guard self.lifecycle.accepts(token) else { return }
|
|
89
|
-
guard failure == nil, let preview = self.preview else { self.complete(nil); return }
|
|
90
|
-
self.host.installObserver { [weak self] message in
|
|
91
|
-
guard let self, lifecycle.accepts(token),
|
|
92
|
-
let data = message.data(using: .utf8),
|
|
93
|
-
let event = try? JSONSerialization.jsonObject(with: data) as? [String: Any]
|
|
94
|
-
else { return }
|
|
95
|
-
if event["type"] as? String == "previewReady", event["ready"] as? Bool == true,
|
|
96
|
-
lifecycle.ready(token) {
|
|
97
|
-
timeout?.cancel()
|
|
98
|
-
captureButton?.isEnabled = true
|
|
99
|
-
statusLabel?.stringValue = "Frame your photo, then choose Capture."
|
|
100
|
-
} else if event["type"] as? String == "interrupted" ||
|
|
101
|
-
(event["type"] as? String == "availability" && event["available"] as? Bool == false) {
|
|
102
|
-
complete(nil)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if self.host.attachPreview(preview) != nil { self.complete(nil) }
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
guard let token = lifecycle.capture() else { return }
|
|
112
|
-
captureButton?.isEnabled = false
|
|
113
|
-
statusLabel?.stringValue = "Taking photo…"
|
|
114
|
-
deadline(token)
|
|
115
|
-
if host.capturePhoto({ [weak self] data in
|
|
116
|
-
guard let self, lifecycle.accepts(token) else { return }
|
|
117
|
-
guard let data, let result = persist(data as Data) else { complete(nil); return }
|
|
118
|
-
complete(result)
|
|
119
|
-
}) != nil { complete(nil) }
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
private func persist(_ data: Data) -> String? {
|
|
123
|
-
guard let source = NSBitmapImageRep(data: data) else { return nil }
|
|
124
|
-
let width = (options["width"] as? NSNumber)?.doubleValue ?? Double(source.pixelsWide)
|
|
125
|
-
let height = (options["height"] as? NSNumber)?.doubleValue ?? Double(source.pixelsHigh)
|
|
126
|
-
guard width.isFinite, height.isFinite, width >= 1, height >= 1, width <= 16384, height <= 16384, width * height <= 64_000_000 else { return nil }
|
|
127
|
-
let keepAspectRatio = options["keepAspectRatio"] as? Bool ?? true
|
|
128
|
-
let scale = min(width / Double(source.pixelsWide), height / Double(source.pixelsHigh), 1)
|
|
129
|
-
let size = NSSize(width: keepAspectRatio ? Double(source.pixelsWide) * scale : width,
|
|
130
|
-
height: keepAspectRatio ? Double(source.pixelsHigh) * scale : height)
|
|
131
|
-
guard let bitmap = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: Int(size.width),
|
|
132
|
-
pixelsHigh: Int(size.height), bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true,
|
|
133
|
-
isPlanar: false, colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0),
|
|
134
|
-
let context = NSGraphicsContext(bitmapImageRep: bitmap) else { return nil }
|
|
135
|
-
NSGraphicsContext.saveGraphicsState()
|
|
136
|
-
NSGraphicsContext.current = context
|
|
137
|
-
let image = NSImage(size: NSSize(width: source.pixelsWide, height: source.pixelsHigh))
|
|
138
|
-
image.addRepresentation(source)
|
|
139
|
-
image.draw(in: NSRect(origin: .zero, size: size))
|
|
140
|
-
NSGraphicsContext.restoreGraphicsState()
|
|
141
|
-
guard let jpeg = bitmap.representation(using: .jpeg, properties: [.compressionFactor: 0.9]) else { return nil }
|
|
142
|
-
let name = "octane-capture-\(UUID().uuidString).jpg"
|
|
143
|
-
let url = FileManager.default.temporaryDirectory.appendingPathComponent(name)
|
|
144
|
-
do {
|
|
145
|
-
let payload: [String: String] = ["name": name, "uri": url.path,
|
|
146
|
-
"dataUrl": "data:image/jpeg;base64," + jpeg.base64EncodedString()]
|
|
147
|
-
let message = try JSONSerialization.data(withJSONObject: payload)
|
|
148
|
-
try jpeg.write(to: url, options: .atomic)
|
|
149
|
-
return String(data: message, encoding: .utf8)
|
|
150
|
-
} catch {
|
|
151
|
-
try? FileManager.default.removeItem(at: url)
|
|
152
|
-
return nil
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
@objc private func cancelPhoto() { complete(nil) }
|
|
157
|
-
public func windowShouldClose(_ sender: NSWindow) -> Bool { complete(nil); return false }
|
|
158
|
-
|
|
159
|
-
private func complete(_ result: String?) {
|
|
160
|
-
guard lifecycle.finish() else { return }
|
|
161
|
-
let callback = reply
|
|
162
|
-
reply = nil
|
|
163
|
-
dispose()
|
|
164
|
-
callback?(result)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
@objc public func discard(_ path: String) {
|
|
168
|
-
let url = URL(fileURLWithPath: path).standardizedFileURL
|
|
169
|
-
guard url.deletingLastPathComponent() == FileManager.default.temporaryDirectory.standardizedFileURL,
|
|
170
|
-
url.lastPathComponent.hasPrefix("octane-capture-") else { return }
|
|
171
|
-
try? FileManager.default.removeItem(at: url)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
@objc public func dispose() {
|
|
175
|
-
guard !disposed else { return }
|
|
176
|
-
disposed = true
|
|
177
|
-
timeout?.cancel()
|
|
178
|
-
timeout = nil
|
|
179
|
-
if let closeObserver { NotificationCenter.default.removeObserver(closeObserver) }
|
|
180
|
-
closeObserver = nil
|
|
181
|
-
host.dispose()
|
|
182
|
-
if let sheet { parent?.endSheet(sheet); sheet.orderOut(nil) }
|
|
183
|
-
sheet = nil
|
|
184
|
-
preview = nil
|
|
185
|
-
captureButton = nil
|
|
186
|
-
statusLabel = nil
|
|
187
|
-
// Disposal is also a cancellation, including an external owner teardown.
|
|
188
|
-
if lifecycle.finish() { let callback = reply; reply = nil; callback?(nil) }
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
deinit { dispose() }
|
|
192
|
-
}
|
package/types/index.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { UniversalComponent } from 'octane/universal'
|
|
2
|
-
import type { CameraViewProps } from './props.js'
|
|
3
|
-
import type { CameraSession, CameraSessionConfig } from './types.js'
|
|
4
|
-
import type { SyntheticCameraScript, SyntheticCameraStorage } from './synthetic-session.js'
|
|
5
|
-
|
|
6
|
-
export declare const CameraView: UniversalComponent<CameraViewProps>
|
|
7
|
-
export type { CameraViewHandle, CameraViewProps, CameraAccessibilityRole } from './props.js'
|
|
8
|
-
|
|
9
|
-
export declare function createCameraSession(config?: CameraSessionConfig): CameraSession
|
|
10
|
-
export declare function createSyntheticCameraSession(
|
|
11
|
-
config?: CameraSessionConfig,
|
|
12
|
-
script?: Partial<SyntheticCameraScript>,
|
|
13
|
-
storage?: SyntheticCameraStorage,
|
|
14
|
-
): CameraSession
|
|
15
|
-
|
|
16
|
-
export declare function createMemoryCameraStorage(): SyntheticCameraStorage & {
|
|
17
|
-
files: Map<string, Uint8Array>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { CameraCaptureError } from './types.js'
|
|
21
|
-
export type {
|
|
22
|
-
CameraCaptureErrorKind,
|
|
23
|
-
CameraDeviceInfo,
|
|
24
|
-
CameraFacing,
|
|
25
|
-
CameraInterruptionReason,
|
|
26
|
-
CameraOrientation,
|
|
27
|
-
CameraPermissionKind,
|
|
28
|
-
CameraPermissionStatus,
|
|
29
|
-
CameraProfileCapability,
|
|
30
|
-
CameraRecorderState,
|
|
31
|
-
CameraSelection,
|
|
32
|
-
CameraSession,
|
|
33
|
-
CameraSessionCapabilities,
|
|
34
|
-
CameraSessionConfig,
|
|
35
|
-
CameraSessionEvent,
|
|
36
|
-
CameraSessionSnapshot,
|
|
37
|
-
CaptureIssue,
|
|
38
|
-
EffectiveCaptureConfig,
|
|
39
|
-
MovieClip,
|
|
40
|
-
MovieEndReason,
|
|
41
|
-
MovieOutcome,
|
|
42
|
-
MovieOutput,
|
|
43
|
-
MovieOutputHandle,
|
|
44
|
-
MovieTake,
|
|
45
|
-
StartRecordingOptions,
|
|
46
|
-
} from './types.js'
|
|
47
|
-
|
|
48
|
-
export type { SyntheticCameraScript, SyntheticCameraStorage } from './synthetic-session.js'
|
package/types/props.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Octane } from 'octane/jsx-runtime';
|
|
2
|
-
import type { CameraPreviewPoint, CameraSession } from './types';
|
|
3
|
-
export type CameraAccessibilityRole = 'button' | 'link' | 'search' | 'image' | 'heading' | 'adjustable' | 'summary' | 'text' | 'none' | 'progressbar' | 'checkbox' | 'switch' | 'radio' | 'spinbutton' | 'tab';
|
|
4
|
-
export interface CameraViewHandle {
|
|
5
|
-
/** The native preview surface (`HTMLVideoElement` on web). */
|
|
6
|
-
native: any;
|
|
7
|
-
}
|
|
8
|
-
export interface CameraViewProps {
|
|
9
|
-
className?: any;
|
|
10
|
-
style?: any;
|
|
11
|
-
id?: string;
|
|
12
|
-
row?: number;
|
|
13
|
-
col?: number;
|
|
14
|
-
rowSpan?: number;
|
|
15
|
-
colSpan?: number;
|
|
16
|
-
dock?: 'left' | 'top' | 'right' | 'bottom';
|
|
17
|
-
left?: number;
|
|
18
|
-
top?: number;
|
|
19
|
-
flexGrow?: number;
|
|
20
|
-
flexShrink?: number;
|
|
21
|
-
alignSelf?: string;
|
|
22
|
-
order?: number;
|
|
23
|
-
accessible?: boolean;
|
|
24
|
-
accessibilityLabel?: string;
|
|
25
|
-
accessibilityRole?: CameraAccessibilityRole;
|
|
26
|
-
accessibilityHint?: string;
|
|
27
|
-
accessibilityValue?: string;
|
|
28
|
-
accessibilityState?: {
|
|
29
|
-
disabled?: boolean;
|
|
30
|
-
selected?: boolean;
|
|
31
|
-
checked?: boolean;
|
|
32
|
-
};
|
|
33
|
-
accessibilityLiveRegion?: 'none' | 'polite' | 'assertive';
|
|
34
|
-
/** Shared camera owner enabling movie recording. When set, the preview
|
|
35
|
-
* attaches to the session's acquisition instead of owning one, and
|
|
36
|
-
* `facing` must be omitted — camera selection lives on the session. */
|
|
37
|
-
session?: CameraSession;
|
|
38
|
-
/** Lens — defaults to the rear camera. Invalid together with `session`. */
|
|
39
|
-
facing?: 'front' | 'back';
|
|
40
|
-
/** Default true. False releases the preview session. */
|
|
41
|
-
active?: boolean;
|
|
42
|
-
/** Fires after the preview surface starts. */
|
|
43
|
-
onReady?: () => void;
|
|
44
|
-
onError?: (error: {
|
|
45
|
-
message?: string;
|
|
46
|
-
}) => void;
|
|
47
|
-
/** Notification-only tap event — fires with the normalized
|
|
48
|
-
* preview-space position (`CameraPreviewPoint`) and never consumes
|
|
49
|
-
* the gesture, so recognizers layered above the preview (double-tap,
|
|
50
|
-
* pan) still run. Pair with `session.focusAtPoint` for tap-to-focus.
|
|
51
|
-
* Delivered on iOS, Android, and web; desktop runtimes do not dispatch
|
|
52
|
-
* it yet. */
|
|
53
|
-
onTap?: (point: CameraPreviewPoint) => void;
|
|
54
|
-
/** Native preview surface for platform-specific controls. */
|
|
55
|
-
ref?: Octane.Ref<CameraViewHandle>;
|
|
56
|
-
/** Platform-specific properties applied to the preview surface. */
|
|
57
|
-
ios?: Record<string, any>;
|
|
58
|
-
android?: Record<string, any>;
|
|
59
|
-
web?: Record<string, any>;
|
|
60
|
-
windows?: Record<string, any>;
|
|
61
|
-
}
|