@capgo/capacitor-flash 7.1.21 → 7.1.23

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/README.md CHANGED
@@ -11,10 +11,10 @@ Switch the Flashlight / Torch of your device.
11
11
 
12
12
  A simple, **free**, and **lightweight** flashlight control plugin:
13
13
 
14
- - **Intensity control** - Adjust brightness levels (iOS with configurable intensity)
14
+ - **Intensity control** - Adjust brightness levels (iOS and Android 13+)
15
15
  - **Status checking** - Query flashlight availability and current state
16
16
  - **Toggle support** - Simple on/off switching with toggle method
17
- - **Universal compatibility** - Works across all iOS and Android devices with flash hardware
17
+ - **Universal compatibility** - Works across iOS, Android, and web (Chrome on mobile devices)
18
18
  - **Modern package management** - Supports both Swift Package Manager (SPM) and CocoaPods (SPM-ready for Capacitor 8)
19
19
  - **Zero dependencies** - Minimal footprint, no bloat
20
20
 
@@ -37,17 +37,18 @@ Works out of the box
37
37
 
38
38
  ## Android
39
39
 
40
- 1. Declare permissions in your app's `AndroidManifest.xml` file
40
+ Works out of the box. No permissions are required since the `CameraManager.setTorchMode()` API (introduced in Android 6.0) does not require camera permission.
41
41
 
42
- ```xml
43
- <!-- Permissions: Allows access to flashlight -->
44
- <uses-permission android:name="android.permission.CAMERA" android:maxSdkVersion="23" />
45
- <uses-permission android:name="android.permission.FLASHLIGHT" />
42
+ Optionally, you can declare the flash hardware feature in your `AndroidManifest.xml`:
46
43
 
47
- <!-- Actual Hardware Features Used-->
48
- <uses-feature android:name="android.hardware.camera.flash" android:required="true" />
44
+ ```xml
45
+ <uses-feature android:name="android.hardware.camera.flash" android:required="false" />
49
46
  ```
50
47
 
48
+ ## Web
49
+
50
+ Works in Chrome and Chromium-based browsers on mobile devices. Uses the MediaDevices API with torch constraint. Call `isAvailable()` first to check if torch control is supported on the current browser/device.
51
+
51
52
  ## API
52
53
 
53
54
  <docgen-index>
@@ -1,6 +1,5 @@
1
1
  package ee.forgr.plugin.capacitor_flash;
2
2
 
3
- import android.Manifest;
4
3
  import android.content.Context;
5
4
  import android.hardware.camera2.CameraAccessException;
6
5
  import android.hardware.camera2.CameraCharacteristics;
@@ -8,18 +7,15 @@ import android.hardware.camera2.CameraManager;
8
7
  import android.os.Build;
9
8
  import androidx.annotation.RequiresApi;
10
9
  import com.getcapacitor.JSObject;
11
- import com.getcapacitor.PermissionState;
12
10
  import com.getcapacitor.Plugin;
13
11
  import com.getcapacitor.PluginCall;
14
12
  import com.getcapacitor.PluginMethod;
15
13
  import com.getcapacitor.annotation.CapacitorPlugin;
16
- import com.getcapacitor.annotation.Permission;
17
- import com.getcapacitor.annotation.PermissionCallback;
18
14
 
19
- @CapacitorPlugin(name = "CapacitorFlash", permissions = { @Permission(alias = "camera", strings = { Manifest.permission.CAMERA }) })
15
+ @CapacitorPlugin(name = "CapacitorFlash")
20
16
  public class CapacitorFlashPlugin extends Plugin {
21
17
 
22
- private final String pluginVersion = "7.1.21";
18
+ private final String pluginVersion = "7.1.23";
23
19
 
24
20
  private String cameraId;
25
21
  boolean isFlashStateOn = false;
@@ -40,15 +36,6 @@ public class CapacitorFlashPlugin extends Plugin {
40
36
 
41
37
  @PluginMethod
42
38
  public void isAvailable(PluginCall call) {
43
- if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M && getPermissionState("camera") != PermissionState.GRANTED) {
44
- requestPermissionForAlias("camera", call, "cameraPermsCallback");
45
- } else {
46
- getAvailability(call);
47
- }
48
- }
49
-
50
- @PermissionCallback
51
- private void getAvailability(PluginCall call) {
52
39
  JSObject ret = new JSObject();
53
40
  if (cameraManager == null) {
54
41
  ret.put("value", false);
@@ -65,7 +52,6 @@ public class CapacitorFlashPlugin extends Plugin {
65
52
  call.resolve(ret);
66
53
  }
67
54
 
68
- @RequiresApi(api = Build.VERSION_CODES.M)
69
55
  @PluginMethod
70
56
  public void switchOn(PluginCall call) {
71
57
  Float intensity = call.getFloat("intensity", 1.0f);
@@ -119,7 +105,6 @@ public class CapacitorFlashPlugin extends Plugin {
119
105
  }
120
106
  }
121
107
 
122
- @RequiresApi(api = Build.VERSION_CODES.M)
123
108
  @PluginMethod
124
109
  public void switchOff(PluginCall call) {
125
110
  JSObject ret = new JSObject();
@@ -146,7 +131,6 @@ public class CapacitorFlashPlugin extends Plugin {
146
131
  call.resolve(ret);
147
132
  }
148
133
 
149
- @RequiresApi(api = Build.VERSION_CODES.M)
150
134
  @PluginMethod
151
135
  public void toggle(PluginCall call) {
152
136
  JSObject ret = new JSObject();
package/dist/esm/web.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  import type { CapacitorFlashPlugin } from './definitions';
3
3
  export declare class CapacitorFlashWeb extends WebPlugin implements CapacitorFlashPlugin {
4
+ private stream;
5
+ private track;
6
+ private torchOn;
4
7
  isAvailable(): Promise<{
5
8
  value: boolean;
6
9
  }>;
package/dist/esm/web.js CHANGED
@@ -1,20 +1,82 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  export class CapacitorFlashWeb extends WebPlugin {
3
- isAvailable() {
4
- return Promise.resolve({ value: false });
3
+ constructor() {
4
+ super(...arguments);
5
+ this.stream = null;
6
+ this.track = null;
7
+ this.torchOn = false;
5
8
  }
6
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
- switchOn(_options) {
8
- throw new Error('Method not implemented.');
9
+ async isAvailable() {
10
+ var _a, _b;
11
+ try {
12
+ if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {
13
+ return { value: false };
14
+ }
15
+ const stream = await navigator.mediaDevices.getUserMedia({
16
+ video: { facingMode: 'environment' },
17
+ });
18
+ const track = stream.getVideoTracks()[0];
19
+ const capabilities = (_b = track.getCapabilities) === null || _b === void 0 ? void 0 : _b.call(track);
20
+ const hasTorch = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.torch) === true;
21
+ // Stop the test stream
22
+ track.stop();
23
+ return { value: hasTorch };
24
+ }
25
+ catch (_c) {
26
+ return { value: false };
27
+ }
9
28
  }
10
- switchOff() {
11
- throw new Error('Method not implemented.');
29
+ async switchOn(_options) {
30
+ var _a;
31
+ try {
32
+ // If we already have a stream with torch on, just return
33
+ if (this.stream && this.torchOn) {
34
+ return;
35
+ }
36
+ // Get camera stream if we don't have one
37
+ if (!this.stream) {
38
+ this.stream = await navigator.mediaDevices.getUserMedia({
39
+ video: { facingMode: 'environment' },
40
+ });
41
+ this.track = this.stream.getVideoTracks()[0];
42
+ }
43
+ // Apply torch constraint
44
+ await ((_a = this.track) === null || _a === void 0 ? void 0 : _a.applyConstraints({
45
+ advanced: [{ torch: true }],
46
+ }));
47
+ this.torchOn = true;
48
+ }
49
+ catch (e) {
50
+ throw new Error(`Failed to switch on torch: ${e}`);
51
+ }
12
52
  }
13
- isSwitchedOn() {
14
- throw new Error('Method not implemented.');
53
+ async switchOff() {
54
+ try {
55
+ if (this.track) {
56
+ // Turn off torch by stopping the track
57
+ this.track.stop();
58
+ this.track = null;
59
+ }
60
+ if (this.stream) {
61
+ this.stream = null;
62
+ }
63
+ this.torchOn = false;
64
+ }
65
+ catch (e) {
66
+ throw new Error(`Failed to switch off torch: ${e}`);
67
+ }
15
68
  }
16
- toggle() {
17
- throw new Error('Method not implemented.');
69
+ async isSwitchedOn() {
70
+ return { value: this.torchOn };
71
+ }
72
+ async toggle() {
73
+ if (this.torchOn) {
74
+ await this.switchOff();
75
+ }
76
+ else {
77
+ await this.switchOn({});
78
+ }
79
+ return { value: this.torchOn };
18
80
  }
19
81
  async getPluginVersion() {
20
82
  return { version: 'web' };
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9C,WAAW;QACT,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;I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AI,CAAC,MAAM,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACrB,CAAC;YACD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACvB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,EAAE,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF"}
@@ -7,21 +7,83 @@ const CapacitorFlash = core.registerPlugin('CapacitorFlash', {
7
7
  });
8
8
 
9
9
  class CapacitorFlashWeb extends core.WebPlugin {
10
- isAvailable() {
11
- return Promise.resolve({ value: false });
10
+ constructor() {
11
+ super(...arguments);
12
+ this.stream = null;
13
+ this.track = null;
14
+ this.torchOn = false;
12
15
  }
13
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
- switchOn(_options) {
15
- throw new Error('Method not implemented.');
16
+ async isAvailable() {
17
+ var _a, _b;
18
+ try {
19
+ if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {
20
+ return { value: false };
21
+ }
22
+ const stream = await navigator.mediaDevices.getUserMedia({
23
+ video: { facingMode: 'environment' },
24
+ });
25
+ const track = stream.getVideoTracks()[0];
26
+ const capabilities = (_b = track.getCapabilities) === null || _b === void 0 ? void 0 : _b.call(track);
27
+ const hasTorch = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.torch) === true;
28
+ // Stop the test stream
29
+ track.stop();
30
+ return { value: hasTorch };
31
+ }
32
+ catch (_c) {
33
+ return { value: false };
34
+ }
16
35
  }
17
- switchOff() {
18
- throw new Error('Method not implemented.');
36
+ async switchOn(_options) {
37
+ var _a;
38
+ try {
39
+ // If we already have a stream with torch on, just return
40
+ if (this.stream && this.torchOn) {
41
+ return;
42
+ }
43
+ // Get camera stream if we don't have one
44
+ if (!this.stream) {
45
+ this.stream = await navigator.mediaDevices.getUserMedia({
46
+ video: { facingMode: 'environment' },
47
+ });
48
+ this.track = this.stream.getVideoTracks()[0];
49
+ }
50
+ // Apply torch constraint
51
+ await ((_a = this.track) === null || _a === void 0 ? void 0 : _a.applyConstraints({
52
+ advanced: [{ torch: true }],
53
+ }));
54
+ this.torchOn = true;
55
+ }
56
+ catch (e) {
57
+ throw new Error(`Failed to switch on torch: ${e}`);
58
+ }
19
59
  }
20
- isSwitchedOn() {
21
- throw new Error('Method not implemented.');
60
+ async switchOff() {
61
+ try {
62
+ if (this.track) {
63
+ // Turn off torch by stopping the track
64
+ this.track.stop();
65
+ this.track = null;
66
+ }
67
+ if (this.stream) {
68
+ this.stream = null;
69
+ }
70
+ this.torchOn = false;
71
+ }
72
+ catch (e) {
73
+ throw new Error(`Failed to switch off torch: ${e}`);
74
+ }
22
75
  }
23
- toggle() {
24
- throw new Error('Method not implemented.');
76
+ async isSwitchedOn() {
77
+ return { value: this.torchOn };
78
+ }
79
+ async toggle() {
80
+ if (this.torchOn) {
81
+ await this.switchOff();
82
+ }
83
+ else {
84
+ await this.switchOn({});
85
+ }
86
+ return { value: this.torchOn };
25
87
  }
26
88
  async getPluginVersion() {
27
89
  return { version: 'web' };
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorFlash = registerPlugin('CapacitorFlash', {\n web: () => import('./web').then((m) => new m.CapacitorFlashWeb()),\n});\nexport * from './definitions';\nexport { CapacitorFlash };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorFlashWeb extends WebPlugin {\n isAvailable() {\n return Promise.resolve({ value: false });\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n switchOn(_options) {\n throw new Error('Method not implemented.');\n }\n switchOff() {\n throw new Error('Method not implemented.');\n }\n isSwitchedOn() {\n throw new Error('Method not implemented.');\n }\n toggle() {\n throw new Error('Method not implemented.');\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;AACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACrE,CAAC;;ACFM,MAAM,iBAAiB,SAASC,cAAS,CAAC;AACjD,IAAI,WAAW,GAAG;AAClB,QAAQ,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAChD,IAAI;AACJ;AACA,IAAI,QAAQ,CAAC,QAAQ,EAAE;AACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;AAClD,IAAI;AACJ,IAAI,SAAS,GAAG;AAChB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;AAClD,IAAI;AACJ,IAAI,YAAY,GAAG;AACnB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;AAClD,IAAI;AACJ,IAAI,MAAM,GAAG;AACb,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;AAClD,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorFlash = registerPlugin('CapacitorFlash', {\n web: () => import('./web').then((m) => new m.CapacitorFlashWeb()),\n});\nexport * from './definitions';\nexport { CapacitorFlash };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorFlashWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.stream = null;\n this.track = null;\n this.torchOn = false;\n }\n async isAvailable() {\n var _a, _b;\n try {\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n return { value: false };\n }\n const stream = await navigator.mediaDevices.getUserMedia({\n video: { facingMode: 'environment' },\n });\n const track = stream.getVideoTracks()[0];\n const capabilities = (_b = track.getCapabilities) === null || _b === void 0 ? void 0 : _b.call(track);\n const hasTorch = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.torch) === true;\n // Stop the test stream\n track.stop();\n return { value: hasTorch };\n }\n catch (_c) {\n return { value: false };\n }\n }\n async switchOn(_options) {\n var _a;\n try {\n // If we already have a stream with torch on, just return\n if (this.stream && this.torchOn) {\n return;\n }\n // Get camera stream if we don't have one\n if (!this.stream) {\n this.stream = await navigator.mediaDevices.getUserMedia({\n video: { facingMode: 'environment' },\n });\n this.track = this.stream.getVideoTracks()[0];\n }\n // Apply torch constraint\n await ((_a = this.track) === null || _a === void 0 ? void 0 : _a.applyConstraints({\n advanced: [{ torch: true }],\n }));\n this.torchOn = true;\n }\n catch (e) {\n throw new Error(`Failed to switch on torch: ${e}`);\n }\n }\n async switchOff() {\n try {\n if (this.track) {\n // Turn off torch by stopping the track\n this.track.stop();\n this.track = null;\n }\n if (this.stream) {\n this.stream = null;\n }\n this.torchOn = false;\n }\n catch (e) {\n throw new Error(`Failed to switch off torch: ${e}`);\n }\n }\n async isSwitchedOn() {\n return { value: this.torchOn };\n }\n async toggle() {\n if (this.torchOn) {\n await this.switchOff();\n }\n else {\n await this.switchOn({});\n }\n return { value: this.torchOn };\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;AACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACrE,CAAC;;ACFM,MAAM,iBAAiB,SAASC,cAAS,CAAC;AACjD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAI;AAC1B,QAAQ,IAAI,CAAC,KAAK,GAAG,IAAI;AACzB,QAAQ,IAAI,CAAC,OAAO,GAAG,KAAK;AAC5B,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,IAAI,EAAE,EAAE,EAAE;AAClB,QAAQ,IAAI;AACZ,YAAY,IAAI,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,YAAY,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE;AACvG,gBAAgB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;AACvC,YAAY;AACZ,YAAY,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC;AACrE,gBAAgB,KAAK,EAAE,EAAE,UAAU,EAAE,aAAa,EAAE;AACpD,aAAa,CAAC;AACd,YAAY,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;AACpD,YAAY,MAAM,YAAY,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,eA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
7
7
 
8
8
  class CapacitorFlashWeb extends core.WebPlugin {
9
- isAvailable() {
10
- return Promise.resolve({ value: false });
9
+ constructor() {
10
+ super(...arguments);
11
+ this.stream = null;
12
+ this.track = null;
13
+ this.torchOn = false;
11
14
  }
12
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
- switchOn(_options) {
14
- throw new Error('Method not implemented.');
15
+ async isAvailable() {
16
+ var _a, _b;
17
+ try {
18
+ if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {
19
+ return { value: false };
20
+ }
21
+ const stream = await navigator.mediaDevices.getUserMedia({
22
+ video: { facingMode: 'environment' },
23
+ });
24
+ const track = stream.getVideoTracks()[0];
25
+ const capabilities = (_b = track.getCapabilities) === null || _b === void 0 ? void 0 : _b.call(track);
26
+ const hasTorch = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.torch) === true;
27
+ // Stop the test stream
28
+ track.stop();
29
+ return { value: hasTorch };
30
+ }
31
+ catch (_c) {
32
+ return { value: false };
33
+ }
15
34
  }
16
- switchOff() {
17
- throw new Error('Method not implemented.');
35
+ async switchOn(_options) {
36
+ var _a;
37
+ try {
38
+ // If we already have a stream with torch on, just return
39
+ if (this.stream && this.torchOn) {
40
+ return;
41
+ }
42
+ // Get camera stream if we don't have one
43
+ if (!this.stream) {
44
+ this.stream = await navigator.mediaDevices.getUserMedia({
45
+ video: { facingMode: 'environment' },
46
+ });
47
+ this.track = this.stream.getVideoTracks()[0];
48
+ }
49
+ // Apply torch constraint
50
+ await ((_a = this.track) === null || _a === void 0 ? void 0 : _a.applyConstraints({
51
+ advanced: [{ torch: true }],
52
+ }));
53
+ this.torchOn = true;
54
+ }
55
+ catch (e) {
56
+ throw new Error(`Failed to switch on torch: ${e}`);
57
+ }
18
58
  }
19
- isSwitchedOn() {
20
- throw new Error('Method not implemented.');
59
+ async switchOff() {
60
+ try {
61
+ if (this.track) {
62
+ // Turn off torch by stopping the track
63
+ this.track.stop();
64
+ this.track = null;
65
+ }
66
+ if (this.stream) {
67
+ this.stream = null;
68
+ }
69
+ this.torchOn = false;
70
+ }
71
+ catch (e) {
72
+ throw new Error(`Failed to switch off torch: ${e}`);
73
+ }
21
74
  }
22
- toggle() {
23
- throw new Error('Method not implemented.');
75
+ async isSwitchedOn() {
76
+ return { value: this.torchOn };
77
+ }
78
+ async toggle() {
79
+ if (this.torchOn) {
80
+ await this.switchOff();
81
+ }
82
+ else {
83
+ await this.switchOn({});
84
+ }
85
+ return { value: this.torchOn };
24
86
  }
25
87
  async getPluginVersion() {
26
88
  return { version: 'web' };
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorFlash = registerPlugin('CapacitorFlash', {\n web: () => import('./web').then((m) => new m.CapacitorFlashWeb()),\n});\nexport * from './definitions';\nexport { CapacitorFlash };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorFlashWeb extends WebPlugin {\n isAvailable() {\n return Promise.resolve({ value: false });\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n switchOn(_options) {\n throw new Error('Method not implemented.');\n }\n switchOff() {\n throw new Error('Method not implemented.');\n }\n isSwitchedOn() {\n throw new Error('Method not implemented.');\n }\n toggle() {\n throw new Error('Method not implemented.');\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;IACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;IACrE,CAAC;;ICFM,MAAM,iBAAiB,SAASC,cAAS,CAAC;IACjD,IAAI,WAAW,GAAG;IAClB,QAAQ,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAChD,IAAI;IACJ;IACA,IAAI,QAAQ,CAAC,QAAQ,EAAE;IACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;IAClD,IAAI;IACJ,IAAI,SAAS,GAAG;IAChB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;IAClD,IAAI;IACJ,IAAI,YAAY,GAAG;IACnB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;IAClD,IAAI;IACJ,IAAI,MAAM,GAAG;IACb,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;IAClD,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorFlash = registerPlugin('CapacitorFlash', {\n web: () => import('./web').then((m) => new m.CapacitorFlashWeb()),\n});\nexport * from './definitions';\nexport { CapacitorFlash };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorFlashWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.stream = null;\n this.track = null;\n this.torchOn = false;\n }\n async isAvailable() {\n var _a, _b;\n try {\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n return { value: false };\n }\n const stream = await navigator.mediaDevices.getUserMedia({\n video: { facingMode: 'environment' },\n });\n const track = stream.getVideoTracks()[0];\n const capabilities = (_b = track.getCapabilities) === null || _b === void 0 ? void 0 : _b.call(track);\n const hasTorch = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.torch) === true;\n // Stop the test stream\n track.stop();\n return { value: hasTorch };\n }\n catch (_c) {\n return { value: false };\n }\n }\n async switchOn(_options) {\n var _a;\n try {\n // If we already have a stream with torch on, just return\n if (this.stream && this.torchOn) {\n return;\n }\n // Get camera stream if we don't have one\n if (!this.stream) {\n this.stream = await navigator.mediaDevices.getUserMedia({\n video: { facingMode: 'environment' },\n });\n this.track = this.stream.getVideoTracks()[0];\n }\n // Apply torch constraint\n await ((_a = this.track) === null || _a === void 0 ? void 0 : _a.applyConstraints({\n advanced: [{ torch: true }],\n }));\n this.torchOn = true;\n }\n catch (e) {\n throw new Error(`Failed to switch on torch: ${e}`);\n }\n }\n async switchOff() {\n try {\n if (this.track) {\n // Turn off torch by stopping the track\n this.track.stop();\n this.track = null;\n }\n if (this.stream) {\n this.stream = null;\n }\n this.torchOn = false;\n }\n catch (e) {\n throw new Error(`Failed to switch off torch: ${e}`);\n }\n }\n async isSwitchedOn() {\n return { value: this.torchOn };\n }\n async toggle() {\n if (this.torchOn) {\n await this.switchOff();\n }\n else {\n await this.switchOn({});\n }\n return { value: this.torchOn };\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;IACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;IACrE,CAAC;;ICFM,MAAM,iBAAiB,SAASC,cAAS,CAAC;IACjD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAI;IAC1B,QAAQ,IAAI,CAAC,KAAK,GAAG,IAAI;IACzB,QAAQ,IAAI,CAAC,OAAO,GAAG,KAAK;IAC5B,IAAI;IACJ,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,IAAI,EAAE,EAAE,EAAE;IAClB,QAAQ,IAAI;IACZ,YAAY,IAAI,EAAE,CAAC,EAAE,GAAG,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MAAM,MAAM,GAAG;IACnB,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE;IAC1B,YAAY,MAAM,IAAI,CAAC,SAAS,EAAE;IAClC,QAAQ;IACR,aAAa;IACb,YAAY,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;IACnC,QAAQ;IACR,QAAQ,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE;IACtC,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -7,7 +7,7 @@ import Capacitor
7
7
  */
8
8
  @objc(CapacitorFlashPlugin)
9
9
  public class CapacitorFlashPlugin: CAPPlugin, CAPBridgedPlugin {
10
- private let pluginVersion: String = "7.1.21"
10
+ private let pluginVersion: String = "7.1.23"
11
11
  public let identifier = "CapacitorFlashPlugin"
12
12
  public let jsName = "CapacitorFlash"
13
13
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-flash",
3
- "version": "7.1.21",
3
+ "version": "7.1.23",
4
4
  "description": "Switch the Flashlight / Torch of your device.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",