capacitor-camera-module 0.0.47 → 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?
|
|
@@ -31,26 +29,27 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
31
29
|
|
|
32
30
|
// MARK: - Capacitor Bridge
|
|
33
31
|
|
|
32
|
+
public static let identifier = "CameraModule"
|
|
33
|
+
public static let jsName = "CameraModule"
|
|
34
34
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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)
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
CAPPluginMethod(name: "stopPreview", returnType: CAPPluginReturnPromise),
|
|
49
|
+
]
|
|
45
50
|
|
|
46
|
-
CAPPluginMethod(name: "toggleFlash", returnType: CAPPluginReturnPromise),
|
|
47
|
-
CAPPluginMethod(name: "hasFlash", returnType: CAPPluginReturnPromise),
|
|
48
51
|
|
|
49
|
-
CAPPluginMethod(name: "takePhotoBase64", returnType: CAPPluginReturnPromise),
|
|
50
52
|
|
|
51
|
-
CAPPluginMethod(name: "startBarcodeScan", returnType: CAPPluginReturnPromise),
|
|
52
|
-
CAPPluginMethod(name: "stopBarcodeScan", returnType: CAPPluginReturnPromise)
|
|
53
|
-
]
|
|
54
53
|
|
|
55
54
|
// MARK: - Lifecycle
|
|
56
55
|
|
|
@@ -150,6 +149,11 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
150
149
|
return
|
|
151
150
|
}
|
|
152
151
|
|
|
152
|
+
guard AVCaptureDevice.authorizationStatus(for: .video) == .authorized else {
|
|
153
|
+
call.reject("Camera permission not granted")
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
|
|
153
157
|
let session = AVCaptureSession()
|
|
154
158
|
session.sessionPreset = .photo
|
|
155
159
|
|
|
@@ -159,10 +163,18 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
159
163
|
return
|
|
160
164
|
}
|
|
161
165
|
|
|
162
|
-
session.
|
|
163
|
-
|
|
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)
|
|
164
177
|
|
|
165
|
-
let view = UIView(frame: UIScreen.main.bounds)
|
|
166
178
|
let layer = AVCaptureVideoPreviewLayer(session: session)
|
|
167
179
|
layer.videoGravity = .resizeAspectFill
|
|
168
180
|
layer.frame = view.bounds
|
|
@@ -281,8 +293,15 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
281
293
|
|
|
282
294
|
if videoDataOutput == nil {
|
|
283
295
|
let output = AVCaptureVideoDataOutput()
|
|
296
|
+
output.videoSettings = [
|
|
297
|
+
kCVPixelBufferPixelFormatTypeKey as String:
|
|
298
|
+
kCVPixelFormatType_32BGRA
|
|
299
|
+
]
|
|
300
|
+
output.alwaysDiscardsLateVideoFrames = true
|
|
284
301
|
output.setSampleBufferDelegate(self, queue: DispatchQueue(label: "barcode.queue"))
|
|
285
|
-
session.
|
|
302
|
+
if session.canAddOutput(output) {
|
|
303
|
+
session.addOutput(output)
|
|
304
|
+
}
|
|
286
305
|
videoDataOutput = output
|
|
287
306
|
}
|
|
288
307
|
}
|
|
@@ -295,6 +314,9 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
295
314
|
videoDataOutput = nil
|
|
296
315
|
scanCall?.keepAlive = false
|
|
297
316
|
scanCall = nil
|
|
317
|
+
barcodeRequest = nil
|
|
318
|
+
lastScannedValue = nil
|
|
319
|
+
lastScanTime = nil
|
|
298
320
|
call.resolve()
|
|
299
321
|
}
|
|
300
322
|
|
|
@@ -307,7 +329,8 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
307
329
|
|
|
308
330
|
let handler = VNImageRequestHandler(
|
|
309
331
|
cvPixelBuffer: pixelBuffer,
|
|
310
|
-
orientation: .right
|
|
332
|
+
orientation: CGImagePropertyOrientation.right
|
|
333
|
+
,
|
|
311
334
|
options: [:]
|
|
312
335
|
)
|
|
313
336
|
|
|
@@ -356,7 +379,7 @@ extension UIImage {
|
|
|
356
379
|
let scale = maxSize / maxSide
|
|
357
380
|
let newSize = CGSize(width: size.width * scale, height: size.height * scale)
|
|
358
381
|
|
|
359
|
-
UIGraphicsBeginImageContextWithOptions(newSize, false,
|
|
382
|
+
UIGraphicsBeginImageContextWithOptions(newSize, false, 0)
|
|
360
383
|
draw(in: CGRect(origin: .zero, size: newSize))
|
|
361
384
|
let img = UIGraphicsGetImageFromCurrentImageContext()
|
|
362
385
|
UIGraphicsEndImageContext()
|