capacitor-camera-module 0.0.48 → 0.0.50
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.
|
@@ -7,7 +7,26 @@ import Photos
|
|
|
7
7
|
@objc(CameraModule)
|
|
8
8
|
public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOutputSampleBufferDelegate {
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
public let identifier = "CameraModule"
|
|
12
|
+
public let jsName = "CameraModule"
|
|
13
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
14
|
+
CAPPluginMethod(name: "checkPermission", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "requestPermission", returnType: CAPPluginReturnPromise),
|
|
16
|
+
CAPPluginMethod(name: "checkGalleryPermission", returnType: CAPPluginReturnPromise),
|
|
17
|
+
CAPPluginMethod(name: "requestGalleryPermission", returnType: CAPPluginReturnPromise),
|
|
18
|
+
CAPPluginMethod(name: "checkAndRequestGalleryPermission", returnType: CAPPluginReturnPromise),
|
|
19
|
+
CAPPluginMethod(name: "pickImageBase64", returnType: CAPPluginReturnPromise),
|
|
20
|
+
CAPPluginMethod(name: "startPreview", returnType: CAPPluginReturnPromise),
|
|
21
|
+
CAPPluginMethod(name: "stopPreview", returnType: CAPPluginReturnPromise),
|
|
22
|
+
CAPPluginMethod(name: "toggleFlash", returnType: CAPPluginReturnPromise),
|
|
23
|
+
CAPPluginMethod(name: "hasFlash", returnType: CAPPluginReturnPromise),
|
|
24
|
+
CAPPluginMethod(name: "takePhotoBase64", returnType: CAPPluginReturnPromise),
|
|
25
|
+
CAPPluginMethod(name: "startBarcodeScan", returnType: CAPPluginReturnPromise),
|
|
26
|
+
CAPPluginMethod(name: "stopBarcodeScan", returnType: CAPPluginReturnPromise)
|
|
27
|
+
|
|
28
|
+
]
|
|
29
|
+
|
|
11
30
|
|
|
12
31
|
private var previewView: UIView?
|
|
13
32
|
private var captureSession: AVCaptureSession?
|
|
@@ -29,33 +48,6 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
29
48
|
|
|
30
49
|
private var galleryCall: CAPPluginCall?
|
|
31
50
|
|
|
32
|
-
// MARK: - Capacitor Bridge
|
|
33
|
-
|
|
34
|
-
public static let identifier = "CameraModule"
|
|
35
|
-
public static let jsName = "CameraModule"
|
|
36
|
-
|
|
37
|
-
public static let pluginMethods: [CAPPluginMethod] = [
|
|
38
|
-
CAPPluginMethod(name: "checkPermission", returnType: CAPPluginReturnPromise),
|
|
39
|
-
CAPPluginMethod(name: "requestPermission", returnType: CAPPluginReturnPromise),
|
|
40
|
-
|
|
41
|
-
CAPPluginMethod(name: "checkGalleryPermission", returnType: CAPPluginReturnPromise),
|
|
42
|
-
CAPPluginMethod(name: "requestGalleryPermission", returnType: CAPPluginReturnPromise),
|
|
43
|
-
CAPPluginMethod(name: "checkAndRequestGalleryPermission", returnType: CAPPluginReturnPromise),
|
|
44
|
-
CAPPluginMethod(name: "pickImageBase64", returnType: CAPPluginReturnPromise),
|
|
45
|
-
|
|
46
|
-
CAPPluginMethod(name: "startPreview", returnType: CAPPluginReturnPromise),
|
|
47
|
-
CAPPluginMethod(name: "stopPreview", returnType: CAPPluginReturnPromise),
|
|
48
|
-
|
|
49
|
-
CAPPluginMethod(name: "toggleFlash", returnType: CAPPluginReturnPromise),
|
|
50
|
-
CAPPluginMethod(name: "hasFlash", returnType: CAPPluginReturnPromise),
|
|
51
|
-
|
|
52
|
-
CAPPluginMethod(name: "takePhotoBase64", returnType: CAPPluginReturnPromise),
|
|
53
|
-
|
|
54
|
-
CAPPluginMethod(name: "startBarcodeScan", returnType: CAPPluginReturnPromise),
|
|
55
|
-
CAPPluginMethod(name: "stopBarcodeScan", returnType: CAPPluginReturnPromise)
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
|
|
59
51
|
// MARK: - Lifecycle
|
|
60
52
|
|
|
61
53
|
public override func load() {
|
|
@@ -154,6 +146,11 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
154
146
|
return
|
|
155
147
|
}
|
|
156
148
|
|
|
149
|
+
guard AVCaptureDevice.authorizationStatus(for: .video) == .authorized else {
|
|
150
|
+
call.reject("Camera permission not granted")
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
|
|
157
154
|
let session = AVCaptureSession()
|
|
158
155
|
session.sessionPreset = .photo
|
|
159
156
|
|
|
@@ -163,10 +160,18 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
163
160
|
return
|
|
164
161
|
}
|
|
165
162
|
|
|
166
|
-
session.
|
|
167
|
-
|
|
163
|
+
if session.canAddInput(input) {
|
|
164
|
+
session.addInput(input)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if session.canAddOutput(self.photoOutput) {
|
|
168
|
+
session.addOutput(self.photoOutput)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
let container = self.bridge?.viewController?.view
|
|
173
|
+
let view = UIView(frame: container?.bounds ?? .zero)
|
|
168
174
|
|
|
169
|
-
let view = UIView(frame: UIScreen.main.bounds)
|
|
170
175
|
let layer = AVCaptureVideoPreviewLayer(session: session)
|
|
171
176
|
layer.videoGravity = .resizeAspectFill
|
|
172
177
|
layer.frame = view.bounds
|
|
@@ -285,8 +290,15 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
285
290
|
|
|
286
291
|
if videoDataOutput == nil {
|
|
287
292
|
let output = AVCaptureVideoDataOutput()
|
|
293
|
+
output.videoSettings = [
|
|
294
|
+
kCVPixelBufferPixelFormatTypeKey as String:
|
|
295
|
+
kCVPixelFormatType_32BGRA
|
|
296
|
+
]
|
|
297
|
+
output.alwaysDiscardsLateVideoFrames = true
|
|
288
298
|
output.setSampleBufferDelegate(self, queue: DispatchQueue(label: "barcode.queue"))
|
|
289
|
-
session.
|
|
299
|
+
if session.canAddOutput(output) {
|
|
300
|
+
session.addOutput(output)
|
|
301
|
+
}
|
|
290
302
|
videoDataOutput = output
|
|
291
303
|
}
|
|
292
304
|
}
|
|
@@ -299,6 +311,9 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
299
311
|
videoDataOutput = nil
|
|
300
312
|
scanCall?.keepAlive = false
|
|
301
313
|
scanCall = nil
|
|
314
|
+
barcodeRequest = nil
|
|
315
|
+
lastScannedValue = nil
|
|
316
|
+
lastScanTime = nil
|
|
302
317
|
call.resolve()
|
|
303
318
|
}
|
|
304
319
|
|
|
@@ -311,7 +326,8 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
311
326
|
|
|
312
327
|
let handler = VNImageRequestHandler(
|
|
313
328
|
cvPixelBuffer: pixelBuffer,
|
|
314
|
-
orientation: .right
|
|
329
|
+
orientation: CGImagePropertyOrientation.right
|
|
330
|
+
,
|
|
315
331
|
options: [:]
|
|
316
332
|
)
|
|
317
333
|
|
|
@@ -360,7 +376,7 @@ extension UIImage {
|
|
|
360
376
|
let scale = maxSize / maxSide
|
|
361
377
|
let newSize = CGSize(width: size.width * scale, height: size.height * scale)
|
|
362
378
|
|
|
363
|
-
UIGraphicsBeginImageContextWithOptions(newSize, false,
|
|
379
|
+
UIGraphicsBeginImageContextWithOptions(newSize, false, 0)
|
|
364
380
|
draw(in: CGRect(origin: .zero, size: newSize))
|
|
365
381
|
let img = UIGraphicsGetImageFromCurrentImageContext()
|
|
366
382
|
UIGraphicsEndImageContext()
|