Capacitor plugin for switching the flashlight on and off.
npm install @capawesome/capacitor-torch
npx cap syncThis API requires the following permissions be added to your AndroidManifest.xml before the application tag:
<!-- To get access to the flashlight. -->
<uses-permission android:name="android.permission.FLASHLIGHT"/>If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:
$androidxCameraCoreVersionversion ofandroidx.camera:camera-core(default:1.1.0)
This can be useful if you encounter dependency conflicts with other plugins in your project.
No configuration required for this plugin.
A working example can be found here: robingenz/capacitor-plugin-demo
import { Torch } from '@capawesome/capacitor-torch';
const enable = async () => {
await Torch.enable();
};
const disable = async () => {
await Torch.disable();
};
const isAvailable = async () => {
const result = await Torch.isAvailable();
return result.available;
};
const isEnabled = async () => {
const result = await Torch.isEnabled();
return result.enabled;
};
const toggle = async () => {
await Torch.toggle();
};enable(options?: EnableOptions | undefined) => Promise<void>Enable the torch.
Only available on Android (SDK 23+), iOS and Web.
| Param | Type |
|---|---|
options |
EnableOptions |
Since: 6.0.0
disable(options?: DisableOptions | undefined) => Promise<void>Disable the torch.
Only available on Android (SDK 23+), iOS and Web.
| Param | Type |
|---|---|
options |
DisableOptions |
Since: 6.0.0
isAvailable() => Promise<IsAvailableResult>Check if the torch is available.
Only available on Android, iOS and Web.
Returns: Promise<IsAvailableResult>
Since: 6.0.0
isEnabled(options?: IsEnabledOptions | undefined) => Promise<IsEnabledResult>Check if the torch is enabled.
Only available on Android, iOS and Web.
| Param | Type |
|---|---|
options |
IsEnabledOptions |
Returns: Promise<IsEnabledResult>
Since: 6.0.0
toggle(options?: ToggleOptions | undefined) => Promise<void>Toggle the torch.
Only available on Android (SDK 23+), iOS and Web.
| Param | Type |
|---|---|
options |
ToggleOptions |
Since: 6.0.0
| Prop | Type | Description | Since |
|---|---|---|---|
stream |
MediaStream |
The stream of media to enable the torch on. Attention: The stream must have a video track. The facing mode of the video track must be the one that corresponds to the torch. Only available on Web. | 6.2.0 |
| Prop | Type | Description | Since |
|---|---|---|---|
stream |
MediaStream |
The stream of media to disable the torch on. Attention: The stream must have a video track. The facing mode of the video track must be the one that corresponds to the torch. Only available on Web. | 6.2.0 |
| Prop | Type | Description | Since |
|---|---|---|---|
available |
boolean |
Whether the torch is available or not. | 6.0.0 |
| Prop | Type | Description | Since |
|---|---|---|---|
enabled |
boolean |
Whether the torch is enabled or not. | 6.0.0 |
| Prop | Type | Description | Since |
|---|---|---|---|
stream |
MediaStream |
The stream of media to check if the torch is enabled on. Attention: The stream must have a video track. The facing mode of the video track must be the one that corresponds to the torch. Only available on Web. | 6.2.0 |
| Prop | Type | Description | Since |
|---|---|---|---|
stream |
MediaStream |
The stream of media to toggle the torch on. Attention: The stream must have a video track. The facing mode of the video track must be the one that corresponds to the torch. Only available on Web. | 6.2.0 |
See CHANGELOG.md.
See LICENSE.