@capgo/camera-preview 5.0.0 → 5.0.1

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.
Files changed (133) hide show
  1. package/README.md +22 -30
  2. package/android/.gradle/8.0.2/checksums/checksums.lock +0 -0
  3. package/android/.gradle/8.0.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  4. package/android/.gradle/8.0.2/dependencies-accessors/gc.properties +0 -0
  5. package/android/.gradle/8.0.2/executionHistory/executionHistory.bin +0 -0
  6. package/android/.gradle/8.0.2/executionHistory/executionHistory.lock +0 -0
  7. package/android/.gradle/8.0.2/fileChanges/last-build.bin +0 -0
  8. package/android/.gradle/8.0.2/fileHashes/fileHashes.bin +0 -0
  9. package/android/.gradle/8.0.2/fileHashes/fileHashes.lock +0 -0
  10. package/android/.gradle/8.0.2/fileHashes/resourceHashesCache.bin +0 -0
  11. package/android/.gradle/8.0.2/gc.properties +0 -0
  12. package/android/.gradle/8.2.1/checksums/checksums.lock +0 -0
  13. package/android/.gradle/8.2.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  14. package/android/.gradle/8.2.1/dependencies-accessors/gc.properties +0 -0
  15. package/android/.gradle/8.2.1/executionHistory/executionHistory.bin +0 -0
  16. package/android/.gradle/8.2.1/executionHistory/executionHistory.lock +0 -0
  17. package/android/.gradle/8.2.1/fileChanges/last-build.bin +0 -0
  18. package/android/.gradle/8.2.1/fileHashes/fileHashes.bin +0 -0
  19. package/android/.gradle/8.2.1/fileHashes/fileHashes.lock +0 -0
  20. package/android/.gradle/8.2.1/gc.properties +0 -0
  21. package/android/.gradle/8.7/checksums/checksums.lock +0 -0
  22. package/android/.gradle/8.7/dependencies-accessors/gc.properties +0 -0
  23. package/android/.gradle/8.7/executionHistory/executionHistory.bin +0 -0
  24. package/android/.gradle/8.7/executionHistory/executionHistory.lock +0 -0
  25. package/android/.gradle/8.7/fileChanges/last-build.bin +0 -0
  26. package/android/.gradle/8.7/fileHashes/fileHashes.bin +0 -0
  27. package/android/.gradle/8.7/fileHashes/fileHashes.lock +0 -0
  28. package/android/.gradle/8.7/fileHashes/resourceHashesCache.bin +0 -0
  29. package/android/.gradle/8.7/gc.properties +0 -0
  30. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  31. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  32. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  33. package/android/.gradle/file-system.probe +0 -0
  34. package/android/.gradle/vcs-1/gc.properties +0 -0
  35. package/android/build.gradle +1 -1
  36. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  37. package/android/gradle/wrapper/gradle-wrapper.properties +1 -0
  38. package/android/gradlew +17 -12
  39. package/android/gradlew.bat +10 -10
  40. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +219 -219
  41. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +108 -85
  42. package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomSurfaceView.java +4 -3
  43. package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +5 -5
  44. package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +44 -23
  45. package/dist/docs.json +29 -22
  46. package/dist/esm/definitions.d.ts +6 -2
  47. package/dist/esm/definitions.js.map +1 -1
  48. package/dist/esm/index.d.ts +2 -2
  49. package/dist/esm/index.js +4 -4
  50. package/dist/esm/index.js.map +1 -1
  51. package/dist/esm/web.d.ts +2 -2
  52. package/dist/esm/web.js +44 -45
  53. package/dist/esm/web.js.map +1 -1
  54. package/dist/plugin.cjs.js +45 -46
  55. package/dist/plugin.cjs.js.map +1 -1
  56. package/dist/plugin.js +45 -46
  57. package/dist/plugin.js.map +1 -1
  58. package/ios/Plugin/CameraController.swift +35 -14
  59. package/ios/Plugin/Plugin.swift +25 -26
  60. package/ios/Plugin.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  61. package/ios/Plugin.xcworkspace/xcuserdata/martindonadieu.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  62. package/ios/PluginTests/PluginTests.swift +61 -13
  63. package/ios/Podfile.lock +3 -3
  64. package/ios/Pods/CapacitorCordova/LICENSE +23 -0
  65. package/ios/Pods/CapacitorCordova/README.md +39 -0
  66. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/CapacitorCordova.h +21 -0
  67. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.h +8 -0
  68. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.m +5 -0
  69. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDV.h +28 -0
  70. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVAvailability.h +109 -0
  71. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegate.h +51 -0
  72. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.h +39 -0
  73. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.m +154 -0
  74. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.h +31 -0
  75. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.m +81 -0
  76. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.h +52 -0
  77. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.m +116 -0
  78. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.h +81 -0
  79. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.m +154 -0
  80. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.h +25 -0
  81. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.m +77 -0
  82. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.h +82 -0
  83. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.m +216 -0
  84. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVScreenOrientationDelegate.h +33 -0
  85. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUIWebViewDelegate.h +41 -0
  86. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUIWebViewDelegate.m +399 -0
  87. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.h +27 -0
  88. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.m +74 -0
  89. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUserAgentUtil.h +27 -0
  90. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUserAgentUtil.m +156 -0
  91. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.h +30 -0
  92. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.m +34 -0
  93. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.h +35 -0
  94. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.m +63 -0
  95. package/ios/Pods/Local Podspecs/Capacitor.podspec.json +31 -0
  96. package/ios/Pods/Manifest.lock +23 -0
  97. package/ios/Pods/Pods.xcodeproj/project.pbxproj +1489 -0
  98. package/ios/Pods/Pods.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/Capacitor.xcscheme +58 -0
  99. package/ios/Pods/Pods.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/CapacitorCordova.xcscheme +58 -0
  100. package/ios/Pods/Pods.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/Pods-Plugin.xcscheme +58 -0
  101. package/ios/Pods/Pods.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/Pods-PluginTests.xcscheme +58 -0
  102. package/ios/Pods/Pods.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/xcschememanagement.plist +39 -0
  103. package/ios/Pods/Target Support Files/Capacitor/Capacitor-Info.plist +26 -0
  104. package/ios/Pods/Target Support Files/Capacitor/Capacitor-dummy.m +5 -0
  105. package/ios/Pods/Target Support Files/Capacitor/Capacitor-prefix.pch +12 -0
  106. package/ios/Pods/Target Support Files/Capacitor/Capacitor.debug.xcconfig +16 -0
  107. package/ios/Pods/Target Support Files/Capacitor/Capacitor.modulemap +8 -0
  108. package/ios/Pods/Target Support Files/Capacitor/Capacitor.release.xcconfig +16 -0
  109. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-Info.plist +26 -0
  110. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-dummy.m +5 -0
  111. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-prefix.pch +12 -0
  112. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-umbrella.h +32 -0
  113. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.debug.xcconfig +13 -0
  114. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.modulemap +6 -0
  115. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.release.xcconfig +13 -0
  116. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-Info.plist +26 -0
  117. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-acknowledgements.markdown +55 -0
  118. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-acknowledgements.plist +93 -0
  119. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-dummy.m +5 -0
  120. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-umbrella.h +16 -0
  121. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.debug.xcconfig +14 -0
  122. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.modulemap +6 -0
  123. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.release.xcconfig +14 -0
  124. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-Info.plist +26 -0
  125. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-acknowledgements.markdown +55 -0
  126. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-acknowledgements.plist +93 -0
  127. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-dummy.m +5 -0
  128. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-frameworks.sh +188 -0
  129. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-umbrella.h +16 -0
  130. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.debug.xcconfig +15 -0
  131. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.modulemap +6 -0
  132. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.release.xcconfig +15 -0
  133. package/package.json +41 -48
@@ -36,10 +36,12 @@ class CameraController: NSObject {
36
36
  var audioInput: AVCaptureDeviceInput?
37
37
 
38
38
  var zoomFactor: CGFloat = 1.0
39
+
40
+ var videoFileURL: URL?
39
41
  }
40
42
 
41
43
  extension CameraController {
42
- func prepare(cameraPosition: String, disableAudio: Bool, completionHandler: @escaping (Error?) -> Void) {
44
+ func prepare(cameraPosition: String, disableAudio: Bool, cameraMode: Bool, completionHandler: @escaping (Error?) -> Void) {
43
45
  func createCaptureSession() {
44
46
  self.captureSession = AVCaptureSession()
45
47
  }
@@ -103,9 +105,16 @@ extension CameraController {
103
105
  }
104
106
  }
105
107
 
106
- func configurePhotoOutput() throws {
108
+ func configurePhotoOutput(cameraMode: Bool) throws {
107
109
  guard let captureSession = self.captureSession else { throw CameraControllerError.captureSessionIsMissing }
108
110
 
111
+ // TODO: check if that really useful
112
+ if !cameraMode && self.highResolutionOutput && captureSession.canSetSessionPreset(.photo) {
113
+ captureSession.sessionPreset = .photo
114
+ } else if cameraMode && self.highResolutionOutput && captureSession.canSetSessionPreset(.high) {
115
+ captureSession.sessionPreset = .high
116
+ }
117
+
109
118
  self.photoOutput = AVCapturePhotoOutput()
110
119
  self.photoOutput!.setPreparedPhotoSettingsArray([AVCapturePhotoSettings(format: [AVVideoCodecKey: AVVideoCodecType.jpeg])], completionHandler: nil)
111
120
  self.photoOutput?.isHighResolutionCaptureEnabled = self.highResolutionOutput
@@ -136,7 +145,7 @@ extension CameraController {
136
145
  createCaptureSession()
137
146
  try configureCaptureDevices()
138
147
  try configureDeviceInputs()
139
- try configurePhotoOutput()
148
+ try configurePhotoOutput(cameraMode: cameraMode)
140
149
  try configureDataOutput()
141
150
  // try configureVideoOutput()
142
151
  } catch {
@@ -414,10 +423,9 @@ extension CameraController {
414
423
 
415
424
  }
416
425
 
417
- func captureVideo(completion: @escaping (URL?, Error?) -> Void) {
426
+ func captureVideo() throws {
418
427
  guard let captureSession = self.captureSession, captureSession.isRunning else {
419
- completion(nil, CameraControllerError.captureSessionIsMissing)
420
- return
428
+ throw CameraControllerError.captureSessionIsMissing
421
429
  }
422
430
  let path = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
423
431
  let identifier = UUID()
@@ -427,16 +435,24 @@ extension CameraController {
427
435
 
428
436
  let fileUrl = path.appendingPathComponent(fileName)
429
437
  try? FileManager.default.removeItem(at: fileUrl)
430
- /*videoOutput!.startRecording(to: fileUrl, recordingDelegate: self)
431
- self.videoRecordCompletionBlock = completion*/
438
+
439
+ // Start recording video
440
+ // ...
441
+
442
+ // Save the file URL for later use
443
+ self.videoFileURL = fileUrl
432
444
  }
433
445
 
434
- func stopRecording(completion: @escaping (Error?) -> Void) {
446
+ func stopRecording(completion: @escaping (URL?, Error?) -> Void) {
435
447
  guard let captureSession = self.captureSession, captureSession.isRunning else {
436
- completion(CameraControllerError.captureSessionIsMissing)
448
+ completion(nil, CameraControllerError.captureSessionIsMissing)
437
449
  return
438
450
  }
439
- // self.videoOutput?.stopRecording()
451
+ // Stop recording video
452
+ // ...
453
+
454
+ // Return the video file URL in the completion handler
455
+ completion(self.videoFileURL, nil)
440
456
  }
441
457
  }
442
458
 
@@ -504,8 +520,10 @@ extension CameraController: UIGestureRecognizerDelegate {
504
520
  extension CameraController: AVCapturePhotoCaptureDelegate {
505
521
  public func photoOutput(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?,
506
522
  resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Swift.Error?) {
507
- if let error = error { self.photoCaptureCompletionBlock?(nil, error) } else if let buffer = photoSampleBuffer, let data = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: buffer, previewPhotoSampleBuffer: nil),
508
- let image = UIImage(data: data) {
523
+ if let error = error {
524
+ self.photoCaptureCompletionBlock?(nil, error)
525
+ } else if let buffer = photoSampleBuffer, let data = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: buffer, previewPhotoSampleBuffer: nil),
526
+ let image = UIImage(data: data) {
509
527
  self.photoCaptureCompletionBlock?(image.fixedOrientation(), nil)
510
528
  } else {
511
529
  self.photoCaptureCompletionBlock?(nil, CameraControllerError.unknown)
@@ -603,7 +621,10 @@ extension UIImage {
603
621
  return nil
604
622
  }
605
623
 
606
- guard let colorSpace = cgImage.colorSpace, let ctx = CGContext(data: nil, width: Int(size.width), height: Int(size.height), bitsPerComponent: cgImage.bitsPerComponent, bytesPerRow: 0, space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else {
624
+ guard let colorSpace = cgImage.colorSpace, let ctx = CGContext(data: nil,
625
+ width: Int(size.width), height: Int(size.height),
626
+ bitsPerComponent: cgImage.bitsPerComponent, bytesPerRow: 0,
627
+ space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else {
607
628
  return nil // Not able to create CGContext
608
629
  }
609
630
 
@@ -37,8 +37,8 @@ public class CameraPreview: CAPPlugin {
37
37
  var previewView: UIView!
38
38
  var cameraPosition = String()
39
39
  let cameraController = CameraController()
40
- var x: CGFloat?
41
- var y: CGFloat?
40
+ var posX: CGFloat?
41
+ var posY: CGFloat?
42
42
  var width: CGFloat?
43
43
  var height: CGFloat?
44
44
  var paddingBottom: CGFloat?
@@ -53,13 +53,13 @@ public class CameraPreview: CAPPlugin {
53
53
  let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!
54
54
 
55
55
  if UIWindow.isLandscape {
56
- self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: max(height, self.width!), height: min(height, self.width!))
56
+ self.previewView.frame = CGRect(x: self.posY!, y: self.posX!, width: max(height, self.width!), height: min(height, self.width!))
57
57
  self.cameraController.previewLayer?.frame = self.previewView.frame
58
58
  }
59
59
 
60
60
  if UIWindow.isPortrait {
61
- if self.previewView != nil && self.x != nil && self.y != nil && self.width != nil && self.height != nil {
62
- self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: min(height, self.width!), height: max(height, self.width!))
61
+ if self.previewView != nil && self.posX != nil && self.posY != nil && self.width != nil && self.height != nil {
62
+ self.previewView.frame = CGRect(x: self.posX!, y: self.posY!, width: min(height, self.width!), height: max(height, self.width!))
63
63
  }
64
64
  self.cameraController.previewLayer?.frame = self.previewView.frame
65
65
  }
@@ -69,6 +69,7 @@ public class CameraPreview: CAPPlugin {
69
69
 
70
70
  @objc func start(_ call: CAPPluginCall) {
71
71
  self.cameraPosition = call.getString("position") ?? "rear"
72
+ let cameraMode = call.getBool("cameraMode") ?? false
72
73
  self.highResolutionOutput = call.getBool("enableHighResolution") ?? false
73
74
  self.cameraController.highResolutionOutput = self.highResolutionOutput
74
75
 
@@ -82,8 +83,8 @@ public class CameraPreview: CAPPlugin {
82
83
  } else {
83
84
  self.height = UIScreen.main.bounds.size.height
84
85
  }
85
- self.x = call.getInt("x") != nil ? CGFloat(call.getInt("x")!)/UIScreen.main.scale: 0
86
- self.y = call.getInt("y") != nil ? CGFloat(call.getInt("y")!)/UIScreen.main.scale: 0
86
+ self.posX = call.getInt("x") != nil ? CGFloat(call.getInt("x")!)/UIScreen.main.scale: 0
87
+ self.posY = call.getInt("y") != nil ? CGFloat(call.getInt("y")!)/UIScreen.main.scale: 0
87
88
  if call.getInt("paddingBottom") != nil {
88
89
  self.paddingBottom = CGFloat(call.getInt("paddingBottom")!)
89
90
  }
@@ -104,14 +105,14 @@ public class CameraPreview: CAPPlugin {
104
105
  if self.cameraController.captureSession?.isRunning ?? false {
105
106
  call.reject("camera already started")
106
107
  } else {
107
- self.cameraController.prepare(cameraPosition: self.cameraPosition, disableAudio: self.disableAudio) {error in
108
+ self.cameraController.prepare(cameraPosition: self.cameraPosition, disableAudio: self.disableAudio, cameraMode: cameraMode) {error in
108
109
  if let error = error {
109
110
  print(error)
110
111
  call.reject(error.localizedDescription)
111
112
  return
112
113
  }
113
114
  let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!
114
- self.previewView = UIView(frame: CGRect(x: self.x ?? 0, y: self.y ?? 0, width: self.width!, height: height))
115
+ self.previewView = UIView(frame: CGRect(x: self.posX ?? 0, y: self.posY ?? 0, width: self.width!, height: height))
115
116
  self.webView?.isOpaque = false
116
117
  self.webView?.backgroundColor = UIColor.clear
117
118
  self.webView?.scrollView.backgroundColor = UIColor.clear
@@ -294,33 +295,31 @@ public class CameraPreview: CAPPlugin {
294
295
 
295
296
  @objc func startRecordVideo(_ call: CAPPluginCall) {
296
297
  DispatchQueue.main.async {
298
+ do {
299
+ try self.cameraController.captureVideo()
300
+ call.resolve()
301
+ } catch {
302
+ call.reject(error.localizedDescription)
303
+ }
304
+ }
305
+ }
297
306
 
298
- let quality: Int? = call.getInt("quality", 85)
299
-
300
- self.cameraController.captureVideo { (image, error) in
301
-
302
- guard let image = image else {
303
- print(error ?? "Image capture error")
307
+ @objc func stopRecordVideo(_ call: CAPPluginCall) {
308
+ DispatchQueue.main.async {
309
+ self.cameraController.stopRecording { (fileURL, error) in
310
+ guard let fileURL = fileURL else {
311
+ print(error ?? "Video capture error")
304
312
  guard let error = error else {
305
- call.reject("Image capture error")
313
+ call.reject("Video capture error")
306
314
  return
307
315
  }
308
316
  call.reject(error.localizedDescription)
309
317
  return
310
318
  }
311
319
 
312
- // self.videoUrl = image
313
-
314
- call.resolve(["value": image.absoluteString])
320
+ call.resolve(["videoUrl": fileURL.absoluteString])
315
321
  }
316
322
  }
317
323
  }
318
324
 
319
- @objc func stopRecordVideo(_ call: CAPPluginCall) {
320
-
321
- self.cameraController.stopRecording { (_) in
322
- call.resolve()
323
- }
324
- }
325
-
326
325
  }
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>SchemeUserState</key>
6
+ <dict>
7
+ <key>Plugin.xcscheme_^#shared#^_</key>
8
+ <dict>
9
+ <key>orderHint</key>
10
+ <integer>4</integer>
11
+ </dict>
12
+ </dict>
13
+ </dict>
14
+ </plist>
@@ -3,33 +3,81 @@ import Capacitor
3
3
  @testable import Plugin
4
4
 
5
5
  class PluginTests: XCTestCase {
6
+ var plugin: CameraPreview?
6
7
 
7
8
  override func setUp() {
8
9
  super.setUp()
9
- // Put setup code here. This method is called before the invocation of each test method in the class.
10
+ plugin = CameraPreview()
10
11
  }
11
12
 
12
13
  override func tearDown() {
13
- // Put teardown code here. This method is called after the invocation of each test method in the class.
14
+ plugin = nil
14
15
  super.tearDown()
15
16
  }
16
17
 
17
- func testEcho() {
18
- // This is an example of a functional test case for a plugin.
19
- // Use XCTAssert and related functions to verify your tests produce the correct results.
18
+ func testStartCamera() {
19
+ let call = CAPPluginCall(callbackId: "testStartCamera", options: [
20
+ "position": "rear",
21
+ "quality": 85,
22
+ "width": 800,
23
+ "height": 600
24
+ ], success: { (_, _) in
25
+ // Camera started successfully
26
+ XCTAssert(true)
27
+ }, error: { (_) in
28
+ XCTFail("Error shouldn't have been called")
29
+ })
30
+
31
+ plugin?.start(call!)
32
+ }
33
+
34
+ func testFlipCamera() {
35
+ let call = CAPPluginCall(callbackId: "testFlipCamera", options: [:], success: { (_, _) in
36
+ // Camera flipped successfully
37
+ XCTAssert(true)
38
+ }, error: { (_) in
39
+ XCTFail("Error shouldn't have been called")
40
+ })
41
+
42
+ plugin?.flip(call!)
43
+ }
44
+
45
+ func testStopCamera() {
46
+ let call = CAPPluginCall(callbackId: "testStopCamera", options: [:], success: { (_, _) in
47
+ // Camera stopped successfully
48
+ XCTAssert(true)
49
+ }, error: { (_) in
50
+ XCTFail("Error shouldn't have been called")
51
+ })
52
+
53
+ plugin?.stop(call!)
54
+ }
55
+
56
+ func testStartRecordVideo() {
57
+ let call = CAPPluginCall(callbackId: "testStartRecordVideo", options: [:], success: { (_, _) in
58
+ // Video recording started successfully
59
+ XCTAssert(true)
60
+ }, error: { (_) in
61
+ XCTFail("Error shouldn't have been called")
62
+ })
20
63
 
21
- let value = "Hello, World!"
22
- let plugin = MyPlugin()
64
+ plugin?.startRecordVideo(call!)
65
+ }
66
+
67
+ func testStopRecordVideo() {
68
+ let expectation = self.expectation(description: "Video recording stopped")
23
69
 
24
- let call = CAPPluginCall(callbackId: "test", options: [
25
- "value": value
26
- ], success: { (result, _) in
27
- let resultValue = result!.data["value"] as? String
28
- XCTAssertEqual(value, resultValue)
70
+ let call = CAPPluginCall(callbackId: "testStopRecordVideo", options: [:], success: { (result, _) in
71
+ // Video recording stopped successfully
72
+ let videoUrl = result?.data?["videoUrl"] as? String
73
+ XCTAssertNotNil(videoUrl)
74
+ expectation.fulfill()
29
75
  }, error: { (_) in
30
76
  XCTFail("Error shouldn't have been called")
31
77
  })
32
78
 
33
- plugin.echo(call!)
79
+ plugin?.stopRecordVideo(call!)
80
+
81
+ waitForExpectations(timeout: 5, handler: nil)
34
82
  }
35
83
  }
package/ios/Podfile.lock CHANGED
@@ -1,5 +1,5 @@
1
1
  PODS:
2
- - Capacitor (5.0.3):
2
+ - Capacitor (6.0.0):
3
3
  - CapacitorCordova
4
4
  - CapacitorCordova (2.0.1)
5
5
 
@@ -15,9 +15,9 @@ EXTERNAL SOURCES:
15
15
  :path: "../node_modules/@capacitor/ios"
16
16
 
17
17
  SPEC CHECKSUMS:
18
- Capacitor: 304a960e431f9e6f78556554ca71c41c1b2b9680
18
+ Capacitor: 559d073c4ca6c27f8e7002c807eea94c3ba435a9
19
19
  CapacitorCordova: 9fee2eb6780331b6ff09710d6a7d1f2e4707f1b9
20
20
 
21
21
  PODFILE CHECKSUM: e80ffb7ef3a0ac7d0d6143f3e64f287d4d027c84
22
22
 
23
- COCOAPODS: 1.12.1
23
+ COCOAPODS: 1.15.2
@@ -0,0 +1,23 @@
1
+ Copyright 2015-present Drifty Co.
2
+ http://drifty.com/
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ [![Build Status][circle-badge]][circle-badge-url]
2
+
3
+ # ⚡️ Cross-platform apps with JavaScript and the Web ⚡️
4
+
5
+ Capacitor is a cross-platform API and code execution layer that makes it easy to call Native SDKs from web code and to write custom Native plugins that your app might need. Additionally, Capacitor provides first-class Progressive Web App support so you can write one app and deploy it to the app stores, _and_ the mobile web.
6
+
7
+ Capacitor was created by the Ionic Framework team as a spiritual successor to Cordova, though it does have backward compatibility with the majority of Cordova plugins. Capacitor can be used without [Ionic Framework](https://ionicframework.com/docs/components), but since it's a core part of the Ionic Platform, it's recommended for the best app development experience.
8
+
9
+ Capacitor also comes with a Plugin API for building native plugins. On iOS, first-class Swift support is available, and much of the iOS Capacitor runtime is written in Swift. Plugins may also be written in Objective-C. On Android, writing plugins in Java and Kotlin is supported.
10
+
11
+ ## Roadmap
12
+
13
+ _Disclaimer: Our roadmap is subject to change at any time and has no specific date guarantees_
14
+
15
+ 2020 and beyond: The core Capacitor project is now stable. Maintenance is ongoing (including support for new mobile operating system versions, bugs, etc.). Going forward, most new functionality will be implemented as plugins. For the latest updates, track new releases [here](https://github.com/ionic-team/capacitor/releases) or milestones [here](https://github.com/ionic-team/capacitor/milestones).
16
+
17
+ [2019](https://blog.ionicframework.com/capacitor-in-2019-native-progressive-web-apps-for-all/)
18
+
19
+ 2018
20
+
21
+ - __Cordova Plugin Integration__
22
+ - Preliminary support for using plugins from the existing Cordova community
23
+ - __Electron support__
24
+ - Support for building Electron apps and interacting with Node.js libraries
25
+ - __Enterprise Premium Plugins__
26
+ - Paid add-on plugins with support for common Enterprise use cases, such as storage, authentication, security, and more
27
+ - Developer Support options with SLAs and priority patches
28
+ - We are working with a few large teams/businesses as early development partners. Interested? Email [max@ionicframework.com](mailto:max@ionicframework.com)
29
+
30
+ ## Contributing
31
+
32
+ Contributing to Capacitor may involve writing TypeScript, Swift/Objective-C, Java, or Markdown depending on the component you are working on. We are looking for help in any of these areas!
33
+
34
+ Please read the [Contributing](.github/CONTRIBUTING.md) guide for more information.
35
+
36
+ For details on updating the Capacitor website or documentation, [see here](site/CONTRIBUTING.md).
37
+
38
+ [circle-badge]: https://circleci.com/gh/ionic-team/capacitor.svg?style=shield
39
+ [circle-badge-url]: https://circleci.com/gh/ionic-team/capacitor
@@ -0,0 +1,21 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ //! Project version number for CapacitorCordova.
4
+ FOUNDATION_EXPORT double CapacitorCordovaVersionNumber;
5
+
6
+ //! Project version string for CapacitorCordova.
7
+ FOUNDATION_EXPORT const unsigned char CapacitorCordovaVersionString[];
8
+
9
+ // In this header, you should import all the public headers of your framework using statements like #import <CapacitorCordova/PublicHeader.h>
10
+
11
+ #import <Cordova/CDV.h>
12
+ #import <Cordova/CDVCommandDelegateImpl.h>
13
+ #import <Cordova/CDVAvailability.h>
14
+ #import <Cordova/CDVPlugin.h>
15
+ #import <Cordova/CDVPluginResult.h>
16
+ #import <Cordova/CDVCommandDelegate.h>
17
+ #import <Cordova/CDVInvokedUrlCommand.h>
18
+ #import <Cordova/CDVConfigParser.h>
19
+ #import <Cordova/CDVViewController.h>
20
+ #import <Cordova/NSDictionary+CordovaPreferences.h>
21
+ #import <Cordova/CDVURLProtocol.h>
@@ -0,0 +1,8 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "CDVViewController.h"
3
+
4
+ @interface AppDelegate : NSObject
5
+
6
+ @property (nonatomic, strong) CDVViewController* viewController;
7
+
8
+ @end
@@ -0,0 +1,5 @@
1
+ #import "AppDelegate.h"
2
+
3
+ @implementation AppDelegate
4
+
5
+ @end
@@ -0,0 +1,28 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+ #import "CDVAvailability.h"
21
+ #import "CDVPlugin.h"
22
+ #import "CDVPluginResult.h"
23
+ #import "CDVCommandDelegate.h"
24
+ #import "CDVInvokedUrlCommand.h"
25
+ #import "CDVViewController.h"
26
+ #import "CDVURLProtocol.h"
27
+ #import "CDVScreenOrientationDelegate.h"
28
+
@@ -0,0 +1,109 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+ #define __CORDOVA_IOS__
21
+
22
+ #define __CORDOVA_0_9_6 906
23
+ #define __CORDOVA_1_0_0 10000
24
+ #define __CORDOVA_1_1_0 10100
25
+ #define __CORDOVA_1_2_0 10200
26
+ #define __CORDOVA_1_3_0 10300
27
+ #define __CORDOVA_1_4_0 10400
28
+ #define __CORDOVA_1_4_1 10401
29
+ #define __CORDOVA_1_5_0 10500
30
+ #define __CORDOVA_1_6_0 10600
31
+ #define __CORDOVA_1_6_1 10601
32
+ #define __CORDOVA_1_7_0 10700
33
+ #define __CORDOVA_1_8_0 10800
34
+ #define __CORDOVA_1_8_1 10801
35
+ #define __CORDOVA_1_9_0 10900
36
+ #define __CORDOVA_2_0_0 20000
37
+ #define __CORDOVA_2_1_0 20100
38
+ #define __CORDOVA_2_2_0 20200
39
+ #define __CORDOVA_2_3_0 20300
40
+ #define __CORDOVA_2_4_0 20400
41
+ #define __CORDOVA_2_5_0 20500
42
+ #define __CORDOVA_2_6_0 20600
43
+ #define __CORDOVA_2_7_0 20700
44
+ #define __CORDOVA_2_8_0 20800
45
+ #define __CORDOVA_2_9_0 20900
46
+ #define __CORDOVA_3_0_0 30000
47
+ #define __CORDOVA_3_1_0 30100
48
+ #define __CORDOVA_3_2_0 30200
49
+ #define __CORDOVA_3_3_0 30300
50
+ #define __CORDOVA_3_4_0 30400
51
+ #define __CORDOVA_3_4_1 30401
52
+ #define __CORDOVA_3_5_0 30500
53
+ #define __CORDOVA_3_6_0 30600
54
+ #define __CORDOVA_3_7_0 30700
55
+ #define __CORDOVA_3_8_0 30800
56
+ #define __CORDOVA_3_9_0 30900
57
+ #define __CORDOVA_3_9_1 30901
58
+ #define __CORDOVA_3_9_2 30902
59
+ #define __CORDOVA_4_0_0 40000
60
+ #define __CORDOVA_4_0_1 40001
61
+ #define __CORDOVA_4_1_0 40100
62
+ #define __CORDOVA_4_1_1 40101
63
+ #define __CORDOVA_4_2_0 40200
64
+ #define __CORDOVA_4_2_1 40201
65
+ #define __CORDOVA_4_3_0 40300
66
+ #define __CORDOVA_4_3_1 40301
67
+ #define __CORDOVA_4_4_0 40400
68
+ #define __CORDOVA_4_5_0 40500
69
+ #define __CORDOVA_4_5_1 40501
70
+ #define __CORDOVA_4_5_2 40502
71
+ #define __CORDOVA_4_5_4 40504
72
+ /* coho:next-version,insert-before */
73
+ #define __CORDOVA_NA 99999 /* not available */
74
+
75
+ /*
76
+ #if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_4_0_0
77
+ // do something when its at least 4.0.0
78
+ #else
79
+ // do something else (non 4.0.0)
80
+ #endif
81
+ */
82
+ #ifndef CORDOVA_VERSION_MIN_REQUIRED
83
+ /* coho:next-version-min-required,replace-after */
84
+ #define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_4_5_4
85
+ #endif
86
+
87
+ /*
88
+ Returns YES if it is at least version specified as NSString(X)
89
+ Usage:
90
+ if (IsAtLeastiOSVersion(@"5.1")) {
91
+ // do something for iOS 5.1 or greater
92
+ }
93
+ */
94
+ #define IsAtLeastiOSVersion(X) ([[[UIDevice currentDevice] systemVersion] compare:X options:NSNumericSearch] != NSOrderedAscending)
95
+
96
+ /* Return the string version of the decimal version */
97
+ #define CDV_VERSION [NSString stringWithFormat:@"%d.%d.%d", \
98
+ (CORDOVA_VERSION_MIN_REQUIRED / 10000), \
99
+ (CORDOVA_VERSION_MIN_REQUIRED % 10000) / 100, \
100
+ (CORDOVA_VERSION_MIN_REQUIRED % 10000) % 100]
101
+
102
+ // Enable this to log all exec() calls.
103
+ #define CDV_ENABLE_EXEC_LOGGING 0
104
+ #if CDV_ENABLE_EXEC_LOGGING
105
+ #define CDV_EXEC_LOG NSLog
106
+ #else
107
+ #define CDV_EXEC_LOG(...) do { \
108
+ } while (NO)
109
+ #endif
@@ -0,0 +1,51 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+ #import "CDVInvokedUrlCommand.h"
21
+
22
+ @class CDVPlugin;
23
+ @class CDVPluginResult;
24
+
25
+ typedef NSURL* (^ UrlTransformerBlock)(NSURL*);
26
+
27
+ @protocol CDVCommandDelegate <NSObject>
28
+
29
+ @property (nonatomic, readonly) NSDictionary* settings;
30
+ @property (nonatomic, copy) UrlTransformerBlock urlTransformer;
31
+
32
+ - (NSString*)pathForResource:(NSString*)resourcepath;
33
+ - (id)getCommandInstance:(NSString*)pluginName;
34
+
35
+ // Sends a plugin result to the JS. This is thread-safe.
36
+ - (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId;
37
+ // Evaluates the given JS. This is thread-safe.
38
+ - (void)evalJs:(NSString*)js;
39
+ // Can be used to evaluate JS right away instead of scheduling it on the run-loop.
40
+ // This is required for dispatch resign and pause events, but should not be used
41
+ // without reason. Without the run-loop delay, alerts used in JS callbacks may result
42
+ // in dead-lock. This method must be called from the UI thread.
43
+ - (void)evalJs:(NSString*)js scheduledOnRunLoop:(BOOL)scheduledOnRunLoop;
44
+ // Run the javascript
45
+ - (void)evalJsHelper2:(NSString*)js;
46
+ // Runs the given block on a background thread using a shared thread-pool.
47
+ - (void)runInBackground:(void (^)())block;
48
+ // Returns the User-Agent of the associated UIWebView.
49
+ - (NSString*)userAgent;
50
+
51
+ @end