@capgo/camera-preview 7.2.6 → 7.2.8

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.
@@ -428,7 +428,32 @@ extension CameraController {
428
428
  } catch {
429
429
  throw CameraControllerError.invalidOperation
430
430
  }
431
+ }
432
+
433
+ func cleanup() {
434
+ if let captureSession = self.captureSession {
435
+ captureSession.stopRunning()
436
+ captureSession.inputs.forEach { captureSession.removeInput($0) }
437
+ captureSession.outputs.forEach { captureSession.removeOutput($0) }
438
+ }
439
+
440
+ self.previewLayer?.removeFromSuperlayer()
441
+ self.previewLayer = nil
442
+
443
+ self.frontCameraInput = nil
444
+ self.rearCameraInput = nil
445
+ self.audioInput = nil
446
+
447
+ self.frontCamera = nil
448
+ self.rearCamera = nil
449
+ self.audioDevice = nil
450
+
451
+ self.dataOutput = nil
452
+ self.photoOutput = nil
453
+ self.fileVideoOutput = nil
431
454
 
455
+ self.captureSession = nil
456
+ self.currentCameraPosition = nil
432
457
  }
433
458
 
434
459
  func captureVideo() throws {
@@ -281,17 +281,19 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin {
281
281
  call.reject("camera not initialized")
282
282
  return
283
283
  }
284
- if self.cameraController.captureSession?.isRunning ?? false {
285
- self.cameraController.captureSession?.stopRunning()
286
- if let previewView = self.previewView {
287
- previewView.removeFromSuperview()
288
- }
289
- self.webView?.isOpaque = true
290
- self.isInitialized = false
291
- call.resolve()
292
- } else {
293
- call.reject("camera already stopped")
284
+
285
+ // Always attempt to stop and clean up, regardless of captureSession state
286
+ if let previewView = self.previewView {
287
+ previewView.removeFromSuperview()
288
+ self.previewView = nil
294
289
  }
290
+
291
+ self.webView?.isOpaque = true
292
+ self.isInitialized = false
293
+ self.isInitializing = false
294
+ self.cameraController.cleanup()
295
+
296
+ call.resolve()
295
297
  }
296
298
  }
297
299
  // Get user's cache directory path
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "7.2.6",
3
+ "version": "7.2.8",
4
4
  "description": "Camera preview",
5
5
  "license": "MIT",
6
6
  "repository": {