Git Product home page Git Product logo

use-torch-light's Introduction

UseTorchLight npm version License: MIT Known Vulnerabilities

🔦 useTorchLight is a hook to enable/disable camera flash. Check out the demo.

Install

You can install this library via NPM or YARN.

NPM

npm i @blackbox-vision/use-torch-light

YARN

yarn add @blackbox-vision/use-torch-light

Warning

useTorchLight relies on ImageCapture API whose spec isn't complete at all browsers currently. You can check the state of ImageCapture in browsers here.

We're currently trying to make the hook most consistent as possible by providing cross-browser checks and dispatching errors or alerts via success and error callbacks.

Usage

The usage is really simple:

import React, { useState, useRef } from 'react';
import { QrReader } from '@blackbox-vision/react-qr-reader';
import { useTorchLight } from '@blackbox-vision/use-torch-light';

const Test = (props) => {
  const streamRef = useRef(null);

  const [error, setError] = useState(null);
  const [data, setData] = useState('No result');

  const [on, toggle] = useTorchLight(streamRef.current);

  const setRef = ({ stream }) => {
    streamRef.current = stream;
  };

  return (
    <>
      <QrReader
        onLoad={setRef}
        onScan={setData}
        onError={setError}
        style={{ width: '100%' }}
      />
      <button onClick={toggle}>{on ? 'Disable Torch' : 'Enable Torch'}</button>
      <p>{JSON.stringify(data, null, 2)}</p>
      <p>{JSON.stringify(error, null, 2)}</p>
    </>
  );
};

Issues

Please, open an issue following one of the issues templates. We will do our best to fix them.

Contributing

If you want to contribute to this project see contributing for more information.

License

Distributed under the MIT license. See LICENSE for more information.

use-torch-light's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

use-torch-light's Issues

No disable

In my xiaomi or in Samsung SM-G532MT its only enable, not disabled the flash

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.