capacitor-camera-view 1.1.1 → 1.2.0

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.
@@ -29,6 +29,10 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
29
29
  /// Currently selected flash mode.
30
30
  private var flashMode: AVCaptureDevice.FlashMode = .auto
31
31
 
32
+ /// Currently selected torch mode and level.
33
+ private var torchEnabled: Bool = false
34
+ private var torchLevel: Float = 1.0
35
+
32
36
  /// Reference to the blur overlay view that is shown when switching to the triple camera in order to have a smooth transition
33
37
  private var blurOverlayView: UIVisualEffectView?
34
38
 
@@ -232,6 +236,48 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
232
236
  return [.off]
233
237
  }
234
238
 
239
+ /// Checks if torch is available on the current camera device.
240
+ ///
241
+ /// - Returns: True if torch is available, false otherwise
242
+ public func isTorchAvailable() -> Bool {
243
+ guard let camera = currentCameraDevice else { return false }
244
+ return camera.hasTorch
245
+ }
246
+
247
+ /// Gets the current torch mode and level.
248
+ ///
249
+ /// - Returns: A tuple containing the torch enabled state and level
250
+ public func getTorchMode() -> (enabled: Bool, level: Float) {
251
+ return (torchEnabled, torchLevel)
252
+ }
253
+
254
+ /// Sets the torch mode and level for the currently active camera device.
255
+ ///
256
+ /// - Parameters:
257
+ /// - enabled: Whether to enable or disable the torch
258
+ /// - level: The torch intensity level (0.0 to 1.0)
259
+ /// - Throws: An error if the torch mode cannot be set or is not supported.
260
+ public func setTorchMode(enabled: Bool, level: Float = 1.0) throws {
261
+ guard let camera = currentCameraDevice else { throw CameraError.cameraUnavailable }
262
+ guard camera.hasTorch else { throw CameraError.torchUnavailable }
263
+
264
+ do {
265
+ try camera.lockForConfiguration()
266
+ defer { camera.unlockForConfiguration() }
267
+
268
+ if enabled && level > 0.0 {
269
+ try camera.setTorchModeOn(level: level)
270
+ } else {
271
+ camera.torchMode = .off
272
+ }
273
+
274
+ torchEnabled = enabled && level > 0.0
275
+ torchLevel = level
276
+ } catch {
277
+ throw CameraError.configurationFailed(error)
278
+ }
279
+ }
280
+
235
281
  /// Gets the minimum, maximum, and current zoom factors supported by the current camera device.
236
282
  /// The maximum zoom factor is limited to a reasonable value of 10x to prevent excessive zooming
237
283
  /// because some devices report very high zoom factors that aren't useful.
@@ -36,6 +36,9 @@ public class CameraViewPlugin: CAPPlugin, CAPBridgedPlugin {
36
36
  CAPPluginMethod(name: "getFlashMode", returnType: CAPPluginReturnPromise),
37
37
  CAPPluginMethod(name: "getSupportedFlashModes", returnType: CAPPluginReturnPromise),
38
38
  CAPPluginMethod(name: "setFlashMode", returnType: CAPPluginReturnPromise),
39
+ CAPPluginMethod(name: "isTorchAvailable", returnType: CAPPluginReturnPromise),
40
+ CAPPluginMethod(name: "getTorchMode", returnType: CAPPluginReturnPromise),
41
+ CAPPluginMethod(name: "setTorchMode", returnType: CAPPluginReturnPromise),
39
42
  CAPPluginMethod(name: "checkPermissions", returnType: CAPPluginReturnPromise),
40
43
  CAPPluginMethod(name: "requestPermissions", returnType: CAPPluginReturnPromise)
41
44
  ]
@@ -259,7 +262,7 @@ public class CameraViewPlugin: CAPPlugin, CAPBridgedPlugin {
259
262
  let flashMode = implementation.getFlashMode()
260
263
 
261
264
  call.resolve([
262
- "flashMode": flashMode
265
+ "flashMode": flashModeToStrMap[flashMode] ?? "off"
263
266
  ])
264
267
  }
265
268
 
@@ -291,6 +294,42 @@ public class CameraViewPlugin: CAPPlugin, CAPBridgedPlugin {
291
294
  }
292
295
  }
293
296
 
297
+ @objc func isTorchAvailable(_ call: CAPPluginCall) {
298
+ let available = implementation.isTorchAvailable()
299
+ call.resolve([
300
+ "available": available
301
+ ])
302
+ }
303
+
304
+ @objc func getTorchMode(_ call: CAPPluginCall) {
305
+ let torchState = implementation.getTorchMode()
306
+ call.resolve([
307
+ "enabled": torchState.enabled,
308
+ "level": torchState.level
309
+ ])
310
+ }
311
+
312
+ @objc func setTorchMode(_ call: CAPPluginCall) {
313
+ guard let enabled = call.getBool("enabled") else {
314
+ call.reject("Enabled parameter is required")
315
+ return
316
+ }
317
+
318
+ let level = call.getFloat("level") ?? 1.0
319
+
320
+ guard level >= 0.0 && level <= 1.0 else {
321
+ call.reject("Level must be between 0.0 and 1.0")
322
+ return
323
+ }
324
+
325
+ do {
326
+ try implementation.setTorchMode(enabled: enabled, level: level)
327
+ call.resolve()
328
+ } catch {
329
+ call.reject("Failed to set torch mode", nil, error)
330
+ }
331
+ }
332
+
294
333
  @objc override public func checkPermissions(_ call: CAPPluginCall) {
295
334
  let cameraState: String
296
335
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-camera-view",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "A Capacitor plugin for embedding a live camera feed directly into your app.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",