npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-flashlight2

v4.0.1

Published

This plugin allows you switch the Flashlight / Torch of your device on or off.

Downloads

3

Readme

Cordova Flashlight / Torch plugin

  1. Description
  2. Installation
  3. Usage
  4. Credits

1. Description

This is a fork of EddyVerbruggen/Flashlight-PhoneGap-Plugin

This plugin allows you to switch the flashlight / torch of the device on and off.

  • Works on iOS 5+
  • Works on Android 2+
  • Android 6+ runtime permissions are handled automatically
  • Works on WP8
  • Depends on capabilities of the device, so you can test it with an API call
  • Compatible with Cordova Plugman
  • Pending review at PhoneGap Build

2. Installation

$ cordova plugin add cordova-plugin-flashlight2

or

$ cordova plugin add https://github.com/derodero24/Cordova-Plugin-Flashlight2

PhoneGap Build

Flashlight works with PhoneGap build too! Compatible with PhoneGap 3.0.0 and up. Just add the following xml to your config.xml to always use the latest version of this plugin:

<gap:plugin name="cordova-plugin-flashlight2" source="npm" />

3. Usage

Since version 3.2.0 of this plugin you can pass in an intensity property which needs to be anywhere between 0.0 and 1.0. Only on iOS this will affect the brightness of the torch.

const flashlightPlugin = window.plugins.flashlight;

flashlightPlugin.available().then(result => {
  if (result) {
    // If available, switch the light on.
    flashlightPlugin
      .switchOn({ intensity: 0.3 }) // optional as well
      .then(() => {
        // If successful, switch off after 3 seconds.
        setTimeout(() => {
          flashlightPlugin.switchOff();
        }, 3000);
      })
      .catch(() => {
        // If it fails, show alert.
        alert('Cannot switch the light on.');
      });
  } else {
    alert('Flashlight not available on this device.');
  }
});

As an alternative to switchOn and switchOff, you can use the toggle function

window.plugins.flashlight
  .toggle(
    { intensity: 0.3 } // optional as well, used on iOS when switching on
  )
  .then(() => {}) // optional success callback
  .catch(() => {}); // optional error callback

To know if the flashlight is on or off you can call isSwitchedOn

window.plugins.flashlight.isSwitchedOn(); // returns true/false

A hint for Android developers: you'll want to make sure the torch is switched off when the app is exited via the backbutton. Otherwise, the camera may be locked so it can't be used by other apps:

document.addEventListener(
  'backbutton',
  // pass exitApp as callbacks to the switchOff method
  () => window.plugins.flashlight.switchOff().finally(exitApp),
  false
);

function exitApp() {
  navigator.app.exitApp();
}

4. CREDITS