@capgo/camera-preview 6.5.27 → 6.5.28
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.
- package/ios/Plugin/Plugin.swift +28 -2
- package/package.json +1 -1
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -33,7 +33,10 @@ extension UIWindow {
|
|
|
33
33
|
*/
|
|
34
34
|
@objc(CameraPreview)
|
|
35
35
|
public class CameraPreview: CAPPlugin {
|
|
36
|
-
|
|
36
|
+
// Camera state tracking
|
|
37
|
+
private var isInitializing: Bool = false
|
|
38
|
+
private var isInitialized: Bool = false
|
|
39
|
+
|
|
37
40
|
var previewView: UIView!
|
|
38
41
|
var cameraPosition = String()
|
|
39
42
|
let cameraController = CameraController()
|
|
@@ -161,6 +164,16 @@ public class CameraPreview: CAPPlugin {
|
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
@objc func start(_ call: CAPPluginCall) {
|
|
167
|
+
if self.isInitializing {
|
|
168
|
+
call.reject("camera initialization in progress")
|
|
169
|
+
return
|
|
170
|
+
}
|
|
171
|
+
if self.isInitialized {
|
|
172
|
+
call.reject("camera already started")
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
self.isInitializing = true
|
|
176
|
+
|
|
164
177
|
self.cameraPosition = call.getString("position") ?? "rear"
|
|
165
178
|
let cameraMode = call.getBool("cameraMode") ?? false
|
|
166
179
|
self.highResolutionOutput = call.getBool("enableHighResolution") ?? false
|
|
@@ -222,6 +235,8 @@ public class CameraPreview: CAPPlugin {
|
|
|
222
235
|
NotificationCenter.default.addObserver(self, selector: #selector(CameraPreview.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
|
|
223
236
|
}
|
|
224
237
|
|
|
238
|
+
self.isInitializing = false
|
|
239
|
+
self.isInitialized = true
|
|
225
240
|
call.resolve()
|
|
226
241
|
|
|
227
242
|
}
|
|
@@ -242,10 +257,21 @@ public class CameraPreview: CAPPlugin {
|
|
|
242
257
|
|
|
243
258
|
@objc func stop(_ call: CAPPluginCall) {
|
|
244
259
|
DispatchQueue.main.async {
|
|
260
|
+
if self.isInitializing {
|
|
261
|
+
call.reject("cannot stop camera while initialization is in progress")
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
if !self.isInitialized {
|
|
265
|
+
call.reject("camera not initialized")
|
|
266
|
+
return
|
|
267
|
+
}
|
|
245
268
|
if self.cameraController.captureSession?.isRunning ?? false {
|
|
246
269
|
self.cameraController.captureSession?.stopRunning()
|
|
247
|
-
self.previewView
|
|
270
|
+
if let previewView = self.previewView {
|
|
271
|
+
previewView.removeFromSuperview()
|
|
272
|
+
}
|
|
248
273
|
self.webView?.isOpaque = true
|
|
274
|
+
self.isInitialized = false
|
|
249
275
|
call.resolve()
|
|
250
276
|
} else {
|
|
251
277
|
call.reject("camera already stopped")
|