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