@capacitor-community/camera-preview 1.1.3 → 2.0.0-beta.2

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.
@@ -19,35 +19,46 @@ public class CameraPreview: CAPPlugin {
19
19
  var rotateWhenOrientationChanged: Bool?
20
20
  var toBack: Bool?
21
21
  var storeToFile: Bool?
22
-
22
+ var highResolutionOutput: Bool = false
23
+
23
24
  @objc func rotated() {
24
-
25
- let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
26
25
 
27
26
  if UIDevice.current.orientation.isLandscape {
28
-
29
- self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: height, height: self.width!)
30
- self.cameraController.previewLayer?.frame = self.previewView.frame
31
-
32
- if (UIDevice.current.orientation == UIDeviceOrientation.landscapeLeft) {
33
- self.cameraController.previewLayer?.connection?.videoOrientation = .landscapeRight
34
- }
35
-
36
- if (UIDevice.current.orientation == UIDeviceOrientation.landscapeRight) {
37
- self.cameraController.previewLayer?.connection?.videoOrientation = .landscapeLeft
27
+ if(self.width! > self.height!) {
28
+ // we started in landscape
29
+ let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
30
+ self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: self.width!, height: height)
31
+ } else {
32
+ // we started in portrait
33
+ let width = self.paddingBottom != nil ? self.width! - self.paddingBottom!: self.width!;
34
+ self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: self.height!, height: width)
38
35
  }
36
+ self.cameraController.previewLayer?.frame = self.previewView.frame
39
37
  }
40
38
 
41
39
  if UIDevice.current.orientation.isPortrait {
42
- self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: self.width!, height: self.height!)
40
+ if (self.previewView != nil && self.x != nil && self.y != nil && self.width != nil && self.height != nil) {
41
+ if(self.height! > self.width!) {
42
+ // we started in portrait
43
+ let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
44
+ self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: self.width!, height: height)
45
+ } else {
46
+ // we started in landscape
47
+ let width = self.paddingBottom != nil ? self.width! - self.paddingBottom!: self.width!;
48
+ self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: self.height!, height: width)
49
+ }
50
+ }
43
51
  self.cameraController.previewLayer?.frame = self.previewView.frame
44
- self.cameraController.previewLayer?.connection?.videoOrientation = .portrait
45
52
  }
53
+
54
+ cameraController.updateVideoOrientation()
46
55
  }
47
56
 
48
57
  @objc func start(_ call: CAPPluginCall) {
49
58
  self.cameraPosition = call.getString("position") ?? "rear"
50
-
59
+ self.highResolutionOutput = call.getBool("enableHighResolution") ?? false
60
+ self.cameraController.highResolutionOutput = self.highResolutionOutput;
61
+
51
62
  if call.getInt("width") != nil {
52
63
  self.width = CGFloat(call.getInt("width")!)
53
64
  } else {
@@ -64,44 +75,48 @@ public class CameraPreview: CAPPlugin {
64
75
  self.paddingBottom = CGFloat(call.getInt("paddingBottom")!)
65
76
  }
66
77
 
67
- AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in
68
- if (!granted) {
69
- call.reject("permission failed");
70
- }
71
- });
72
-
73
78
  self.rotateWhenOrientationChanged = call.getBool("rotateWhenOrientationChanged") ?? true
74
79
  self.toBack = call.getBool("toBack") ?? false
75
80
  self.storeToFile = call.getBool("storeToFile") ?? false
76
81
 
77
- if (self.rotateWhenOrientationChanged == true) {
78
- NotificationCenter.default.addObserver(self, selector: #selector(CameraPreview.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
79
- }
80
-
81
- DispatchQueue.main.async {
82
- if (self.cameraController.captureSession?.isRunning ?? false) {
83
- call.reject("camera already started")
84
- } else {
85
- self.cameraController.prepare(cameraPosition: self.cameraPosition){error in
86
- if let error = error {
87
- print(error)
88
- call.reject(error.localizedDescription)
89
- return
90
- }
91
- self.previewView = UIView(frame: CGRect(x: self.x!, y: self.y!, width: self.width!, height: self.height!))
92
- self.webView.isOpaque = false
93
- self.webView.backgroundColor = UIColor.clear
94
- self.webView.scrollView.backgroundColor = UIColor.clear
95
- self.webView.superview?.addSubview(self.previewView)
96
- if (self.toBack!) {
97
- self.webView.superview?.bringSubviewToFront(self.webView)
98
- }
99
- try? self.cameraController.displayPreview(on: self.previewView)
100
- call.resolve()
82
+ AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in
83
+ guard granted else {
84
+ call.reject("permission failed");
85
+ return
86
+ }
87
+
88
+ DispatchQueue.main.async {
89
+ if (self.cameraController.captureSession?.isRunning ?? false) {
90
+ call.reject("camera already started")
91
+ } else {
92
+ self.cameraController.prepare(cameraPosition: self.cameraPosition){error in
93
+ if let error = error {
94
+ print(error)
95
+ call.reject(error.localizedDescription)
96
+ return
97
+ }
98
+ let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
99
+ self.previewView = UIView(frame: CGRect(x: 0, y: 0, width: self.width!, height: height))
100
+ self.webView?.isOpaque = false
101
+ self.webView?.backgroundColor = UIColor.clear
102
+ self.webView?.scrollView.backgroundColor = UIColor.clear
103
+ self.webView?.superview?.addSubview(self.previewView)
104
+ if (self.toBack!) {
105
+ self.webView?.superview?.bringSubviewToFront(self.webView!)
106
+ }
107
+ try? self.cameraController.displayPreview(on: self.previewView)
108
+
109
+ if (self.rotateWhenOrientationChanged == true) {
110
+ NotificationCenter.default.addObserver(self, selector: #selector(CameraPreview.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
111
+ }
112
+
113
+ call.resolve()
101
114
 
115
+ }
102
116
  }
103
117
  }
104
- }
118
+ });
119
+
105
120
  }
106
121
 
107
122
  @objc func flip(_ call: CAPPluginCall) {
@@ -118,7 +133,7 @@ public class CameraPreview: CAPPlugin {
118
133
  if (self.cameraController.captureSession?.isRunning ?? false) {
119
134
  self.cameraController.captureSession?.stopRunning()
120
135
  self.previewView.removeFromSuperview()
121
- self.webView.isOpaque = true
136
+ self.webView?.isOpaque = true
122
137
  call.resolve()
123
138
  } else {
124
139
  call.reject("camera already stopped")
@@ -153,11 +168,11 @@ public class CameraPreview: CAPPlugin {
153
168
  return
154
169
  }
155
170
  let imageData: Data?
156
- if (self.cameraPosition == "front") {
171
+ if (self.cameraController.currentCameraPosition == .front) {
157
172
  let flippedImage = image.withHorizontallyFlippedOrientation()
158
- imageData = flippedImage.jpegData(compressionQuality: CGFloat(quality!))
173
+ imageData = flippedImage.jpegData(compressionQuality: CGFloat(quality!/100))
159
174
  } else {
160
- imageData = image.jpegData(compressionQuality: CGFloat(quality!))
175
+ imageData = image.jpegData(compressionQuality: CGFloat(quality!/100))
161
176
  }
162
177
 
163
178
  if (self.storeToFile == false){
@@ -175,6 +190,41 @@ public class CameraPreview: CAPPlugin {
175
190
  }
176
191
  }
177
192
  }
193
+
194
+ @objc func captureSample(_ call: CAPPluginCall) {
195
+ DispatchQueue.main.async {
196
+ let quality: Int? = call.getInt("quality", 85)
197
+
198
+ self.cameraController.captureSample { image, error in
199
+ guard let image = image else {
200
+ print("Image capture error: \(String(describing: error))")
201
+ call.reject("Image capture error: \(String(describing: error))")
202
+ return
203
+ }
204
+
205
+ let imageData: Data?
206
+ if (self.cameraPosition == "front") {
207
+ let flippedImage = image.withHorizontallyFlippedOrientation()
208
+ imageData = flippedImage.jpegData(compressionQuality: CGFloat(quality!/100))
209
+ } else {
210
+ imageData = image.jpegData(compressionQuality: CGFloat(quality!/100))
211
+ }
212
+
213
+ if (self.storeToFile == false){
214
+ let imageBase64 = imageData?.base64EncodedString()
215
+ call.resolve(["value": imageBase64!])
216
+ } else {
217
+ do {
218
+ let fileUrl = self.getTempFilePath()
219
+ try imageData?.write(to:fileUrl)
220
+ call.resolve(["value": fileUrl.absoluteString])
221
+ } catch {
222
+ call.reject("Error writing image to file")
223
+ }
224
+ }
225
+ }
226
+ }
227
+ }
178
228
 
179
229
  @objc func getSupportedFlashModes(_ call: CAPPluginCall) {
180
230
  do {
@@ -214,5 +264,37 @@ public class CameraPreview: CAPPlugin {
214
264
  call.reject("failed to set flash mode")
215
265
  }
216
266
  }
267
+
268
+ @objc func startRecordVideo(_ call: CAPPluginCall) {
269
+ DispatchQueue.main.async {
270
+
271
+ let quality: Int? = call.getInt("quality", 85)
272
+
273
+ self.cameraController.captureVideo { (image, error) in
274
+
275
+ guard let image = image else {
276
+ print(error ?? "Image capture error")
277
+ guard let error = error else {
278
+ call.reject("Image capture error")
279
+ return
280
+ }
281
+ call.reject(error.localizedDescription)
282
+ return
283
+ }
284
+
285
+ //self.videoUrl = image
286
+
287
+ call.resolve(["value":image.absoluteString])
288
+ }
289
+ }
290
+ }
291
+
292
+
293
+ @objc func stopRecordVideo(_ call: CAPPluginCall) {
294
+
295
+ self.cameraController.stopRecording { (error) in
296
+
297
+ }
298
+ }
217
299
 
218
300
  }
@@ -14,8 +14,6 @@
14
14
  4C2070D622DA87B100D1AD33 /* CoreImage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070D522DA87B100D1AD33 /* CoreImage.framework */; };
15
15
  4C2070D822DA87C600D1AD33 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070D722DA87C500D1AD33 /* QuartzCore.framework */; };
16
16
  4C2070DA22DA87CE00D1AD33 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070D922DA87CE00D1AD33 /* CoreVideo.framework */; };
17
- 4C2070DC22DA87D700D1AD33 /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070DB22DA87D700D1AD33 /* GLKit.framework */; };
18
- 4C2070DE22DA87E700D1AD33 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070DD22DA87E700D1AD33 /* OpenGLES.framework */; };
19
17
  4C2070E022DA87F500D1AD33 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070DF22DA87F500D1AD33 /* CoreGraphics.framework */; };
20
18
  4C2070E222DA87FB00D1AD33 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070E122DA87FB00D1AD33 /* AssetsLibrary.framework */; };
21
19
  4C2070E422DA881600D1AD33 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070E322DA881600D1AD33 /* CoreLocation.framework */; };
@@ -77,8 +75,6 @@
77
75
  4C2070E422DA881600D1AD33 /* CoreLocation.framework in Frameworks */,
78
76
  4C2070E222DA87FB00D1AD33 /* AssetsLibrary.framework in Frameworks */,
79
77
  4C2070E022DA87F500D1AD33 /* CoreGraphics.framework in Frameworks */,
80
- 4C2070DE22DA87E700D1AD33 /* OpenGLES.framework in Frameworks */,
81
- 4C2070DC22DA87D700D1AD33 /* GLKit.framework in Frameworks */,
82
78
  4C2070D822DA87C600D1AD33 /* QuartzCore.framework in Frameworks */,
83
79
  4C2070D622DA87B100D1AD33 /* CoreImage.framework in Frameworks */,
84
80
  4C2070D222DA878E00D1AD33 /* ImageIO.framework in Frameworks */,
@@ -418,7 +414,7 @@
418
414
  GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
419
415
  GCC_WARN_UNUSED_FUNCTION = YES;
420
416
  GCC_WARN_UNUSED_VARIABLE = YES;
421
- IPHONEOS_DEPLOYMENT_TARGET = 11.0;
417
+ IPHONEOS_DEPLOYMENT_TARGET = 12.1;
422
418
  MTL_ENABLE_DEBUG_INFO = YES;
423
419
  ONLY_ACTIVE_ARCH = YES;
424
420
  SDKROOT = iphoneos;
@@ -473,7 +469,7 @@
473
469
  GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
474
470
  GCC_WARN_UNUSED_FUNCTION = YES;
475
471
  GCC_WARN_UNUSED_VARIABLE = YES;
476
- IPHONEOS_DEPLOYMENT_TARGET = 11.0;
472
+ IPHONEOS_DEPLOYMENT_TARGET = 12.1;
477
473
  MTL_ENABLE_DEBUG_INFO = NO;
478
474
  SDKROOT = iphoneos;
479
475
  SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
@@ -497,7 +493,7 @@
497
493
  DYLIB_INSTALL_NAME_BASE = "@rpath";
498
494
  INFOPLIST_FILE = Plugin/Info.plist;
499
495
  INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
500
- IPHONEOS_DEPLOYMENT_TARGET = 11.0;
496
+ IPHONEOS_DEPLOYMENT_TARGET = 12.1;
501
497
  LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)";
502
498
  ONLY_ACTIVE_ARCH = YES;
503
499
  PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin;
@@ -522,7 +518,7 @@
522
518
  DYLIB_INSTALL_NAME_BASE = "@rpath";
523
519
  INFOPLIST_FILE = Plugin/Info.plist;
524
520
  INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
525
- IPHONEOS_DEPLOYMENT_TARGET = 11.0;
521
+ IPHONEOS_DEPLOYMENT_TARGET = 12.1;
526
522
  LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)";
527
523
  ONLY_ACTIVE_ARCH = NO;
528
524
  PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin;
package/ios/Podfile CHANGED
@@ -1,4 +1,4 @@
1
- platform :ios, '11.0'
1
+ platform :ios, '12.1'
2
2
 
3
3
  target 'Plugin' do
4
4
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
@@ -10,4 +10,4 @@ target 'PluginTests' do
10
10
  use_frameworks!
11
11
 
12
12
  pod 'Capacitor', :path => '../node_modules/@capacitor/ios'
13
- end
13
+ end
package/ios/Podfile.lock CHANGED
@@ -1,6 +1,6 @@
1
1
  PODS:
2
- - Capacitor (2.0.1):
3
- - CapacitorCordova (= 2.0.1)
2
+ - Capacitor (3.0.0):
3
+ - CapacitorCordova
4
4
  - CapacitorCordova (2.0.1)
5
5
 
6
6
  DEPENDENCIES:
@@ -15,9 +15,9 @@ EXTERNAL SOURCES:
15
15
  :path: "../node_modules/@capacitor/ios"
16
16
 
17
17
  SPEC CHECKSUMS:
18
- Capacitor: 893baa42b33635ddf23d29d23d2a7f33f7c08bc7
18
+ Capacitor: 06cd8cd01340f5b162e9528bf5569d87a6f29009
19
19
  CapacitorCordova: 9fee2eb6780331b6ff09710d6a7d1f2e4707f1b9
20
20
 
21
- PODFILE CHECKSUM: 38d083712967e4c216faff8d0b7c5eb7faa2b523
21
+ PODFILE CHECKSUM: d3e2703a3105a8e75e11dfc45c25f5cbf9801486
22
22
 
23
- COCOAPODS: 1.9.1
23
+ COCOAPODS: 1.9.3
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@capacitor-community/camera-preview",
3
- "version": "1.1.3",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "Camera preview",
5
5
  "main": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "npm run clean && tsc",
9
- "clean": "rm -rf ./dist",
9
+ "clean": "rimraf './dist'",
10
10
  "watch": "tsc --watch",
11
- "prepublishOnly": "npm run build"
11
+ "prepublishOnly": "npm run build",
12
+ "prepare": "npm run build"
12
13
  },
13
14
  "author": "Ariel Hernandez Musa",
14
15
  "license": "MIT",
@@ -18,7 +19,8 @@
18
19
  "devDependencies": {
19
20
  "@capacitor/android": "latest",
20
21
  "@capacitor/ios": "latest",
21
- "typescript": "^3.2.4"
22
+ "rimraf": "^3.0.2",
23
+ "typescript": "^4.3.2"
22
24
  },
23
25
  "files": [
24
26
  "dist/",
@@ -1 +0,0 @@
1
- /build
@@ -1,8 +0,0 @@
1
- ## This file must *NOT* be checked into Version Control Systems,
2
- # as it contains information specific to your local configuration.
3
- #
4
- # Location of the SDK. This is only used by Gradle.
5
- # For customization when using a Version Control System, please read the
6
- # header note.
7
- #Sun Jul 14 21:09:11 UYT 2019
8
- sdk.dir=/Users/arielhernandezmusa/Library/Android/sdk
package/ios/.DS_Store DELETED
Binary file
@@ -1,14 +0,0 @@
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>