capacitor-community-multilens-camerapreview 0.0.8 → 0.0.9-a

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.
@@ -265,6 +265,57 @@ extension CameraController {
265
265
 
266
266
  captureSession.commitConfiguration()
267
267
  }
268
+
269
+ func changeOrientation() throws {
270
+ guard let currentCameraPosition = currentCameraPosition, let captureSession = self.captureSession, captureSession.isRunning else { throw CameraControllerError.captureSessionIsMissing }
271
+
272
+ captureSession.beginConfiguration()
273
+
274
+ func switchToFrontCamera() throws {
275
+
276
+ guard let rearCameraInput = self.rearCameraInput, captureSession.inputs.contains(rearCameraInput),
277
+ let frontCamera = self.frontCamera else { throw CameraControllerError.invalidOperation }
278
+
279
+ self.frontCameraInput = try AVCaptureDeviceInput(device: frontCamera)
280
+
281
+ captureSession.removeInput(rearCameraInput)
282
+
283
+ if captureSession.canAddInput(self.frontCameraInput!) {
284
+ captureSession.addInput(self.frontCameraInput!)
285
+
286
+ self.currentCameraPosition = .front
287
+ } else {
288
+ throw CameraControllerError.invalidOperation
289
+ }
290
+ }
291
+
292
+ func switchToRearCamera() throws {
293
+
294
+ guard let frontCameraInput = self.frontCameraInput, captureSession.inputs.contains(frontCameraInput),
295
+ let rearCamera = self.rearCamera else { throw CameraControllerError.invalidOperation }
296
+
297
+ self.rearCameraInput = try AVCaptureDeviceInput(device: rearCamera)
298
+
299
+ captureSession.removeInput(frontCameraInput)
300
+
301
+ if captureSession.canAddInput(self.rearCameraInput!) {
302
+ captureSession.addInput(self.rearCameraInput!)
303
+
304
+ self.currentCameraPosition = .rear
305
+ } else { throw CameraControllerError.invalidOperation }
306
+ }
307
+
308
+ switch currentCameraPosition {
309
+ case .front:
310
+ try switchToRearCamera()
311
+
312
+ case .rear:
313
+ try switchToFrontCamera()
314
+ }
315
+
316
+ captureSession.commitConfiguration()
317
+ }
318
+
268
319
  func setZoom(lens: String) throws {
269
320
  print(lens)
270
321
  guard let captureSession = self.captureSession, captureSession.isRunning else { throw CameraControllerError.captureSessionIsMissing }
@@ -9,6 +9,7 @@ CAP_PLUGIN(CameraPreview, "CameraPreview",
9
9
  CAP_PLUGIN_METHOD(capture, CAPPluginReturnPromise);
10
10
  CAP_PLUGIN_METHOD(captureSample, CAPPluginReturnPromise);
11
11
  CAP_PLUGIN_METHOD(flip, CAPPluginReturnPromise);
12
+ CAP_PLUGIN_METHOD(changeOrientation, CAPPluginReturnPromise);
12
13
  CAP_PLUGIN_METHOD(setZoom, CAPPluginReturnPromise);
13
14
  CAP_PLUGIN_METHOD(getSupportedFlashModes, CAPPluginReturnPromise);
14
15
  CAP_PLUGIN_METHOD(getSupportedZoomLevels, CAPPluginReturnPromise);
@@ -120,6 +120,14 @@ public class CameraPreview: CAPPlugin {
120
120
  call.reject("failed to flip camera")
121
121
  }
122
122
  }
123
+ @objc func changeOrientation(_ call: CAPPluginCall) {
124
+ do {
125
+ try self.cameraController.changeOrientation()
126
+ call.resolve()
127
+ } catch {
128
+ call.reject("failed to change orientation")
129
+ }
130
+ }
123
131
 
124
132
  @objc func stop(_ call: CAPPluginCall) {
125
133
  DispatchQueue.main.async {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "capacitor-community-multilens-camerapreview",
3
- "version": "0.0.8",
4
- "description": "fork of capacitor community camera preview with support for switchting lenses",
3
+ "version": "0.0.9a",
4
+ "description": "fork of capacitor community camera preview with support for switchting lenses and changing orientation",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/esm/index.d.ts",