Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Add support for flash Light #129

Closed
stefanodias opened this issue Oct 19, 2020 · 15 comments
Closed

[Feature request] Add support for flash Light #129

stefanodias opened this issue Oct 19, 2020 · 15 comments

Comments

@stefanodias
Copy link

Hello, in many cases we need Flash Light to reading QrCode, it's possible?

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@sondreb
Copy link

sondreb commented Jul 4, 2022

Anything happening with the "flashlight" branch/feature? Would love to have that feature available, and I see there is a branch that was worked on for it in 2021.

@ROBERT-MCDOWELL
Copy link

you could try to work on it and create a PR?

@ROBERT-MCDOWELL
Copy link

ROBERT-MCDOWELL commented Jul 4, 2022

it seems to be ready for version 3
lafriks-fork@23c8e76
a PR must be created by the forker or contact them to speed up things.

@sondreb
Copy link

sondreb commented Jul 5, 2022

@lafriks @mebjas ... any chance getting this merged?

@nexorianus
Copy link

giving this a push!
would also love to see this in the repo

@mebjas mebjas self-assigned this Oct 29, 2022
@mebjas
Copy link
Owner

mebjas commented Oct 29, 2022

This is already possible with Html5Qrcode using applyVideoConstraints(..) API. I suppose I need to expose the current settings of the video track to make it full fledged.

Working on this right now for version 2.2.5. Here's what I plan to do:

  1. Add support for torch button in Html5QrcodeScanner with a configuration (default false) as UI is not that good.
  2. Expose getRunningTrackSettings(..) in both Html5Qrcode and Html5QrcodeScanner.
  3. Make getRunningTrackCapabilities(..), applyVideoConstraints(..) along with the new getRunningTrackSettings(..) non beta and add documentation for all these APIs.
  4. After publishing add blog posts explaining how to enable torch as is with Html5Qrcode.

mebjas added a commit that referenced this issue Oct 29, 2022
### Version 2.2.5

#### Added support for turning `torch` On and Off in `Html5QrcodeScanner`.
On supported devices + browsers.

This new feature will implement the feature request - [Issue#129](#129) and add support for torch (also called flash) on supported devices and browsers.

So far I have confirmed functionality on Samsung Flip 4 Chrome and Internet (Samsung's default browser).

This is only supported on `Html5QrcodeScanner` and can be enabled using the config like this.

```ts
let html5QrcodeScanner = new Html5QrcodeScanner(
    "reader",
    {
        fps: 10,
        qrbox: qrboxFunction,
        // Important notice: this is experimental feature, use it at your
        // own risk. See documentation in
        // mebjas@/html5-qrcode/src/experimental-features.ts
        experimentalFeatures: {
            useBarCodeDetectorIfSupported: true
        },
        rememberLastUsedCamera: true,
        aspectRatio: 1.7777778,
        showTorchButtonIfSupported: true
    });
```

The `showTorchButtonIfSupported: true` part is the crucial one. It's off by default for now as I don't like the UI very much.

#### Added support for `getRunningTrackSettings()`.

Added a new API to get settings (type: [MediaTrackSettings](https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings)) for running video streams while QR code is being scanned.

```ts
/**
 * Returns the supported settings of the running video track.
 *
 * @returns the supported settings of the running video track.
 * @throws error if the scanning is not in running state.
 */
public getRunningTrackSettings(): MediaTrackSettings {}
```

This API can be used to check the currently applied settings on the running video stream like weather torch is on or not.

#### `getRunningTrackCapabilities(..)` and `applyVideoConstraints(..)` out of beta.

Both `Html5Qrcode` and `Html5QrcodeScanner` classes had support for following APIs.

```ts
/**
 * Returns the capabilities of the running video track.
 *
 * Note: Should only be called if {@code Html5QrcodeScanner#getState()}
 *   returns {@code Html5QrcodeScannerState#SCANNING} or
 *   {@code Html5QrcodeScannerState#PAUSED}.
 *
 * @returns the capabilities of a running video track.
 * @throws error if the scanning is not in running state.
 */
public getRunningTrackCapabilities(): MediaTrackCapabilities {}

 /**
 * Apply a video constraints on running video track from camera.
 *
 * Note: Should only be called if {@code Html5QrcodeScanner#getState()}
 *   returns {@code Html5QrcodeScannerState#SCANNING} or
 *   {@code Html5QrcodeScannerState#PAUSED}.
 *
 * @param {MediaTrackConstraints} specifies a variety of video or camera
 *  controls as defined in
 *  https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints
 * @returns a Promise which succeeds if the passed constraints are applied,
 *  fails otherwise.
 * @throws error if the scanning is not in running state.
 */
public applyVideoConstraints(videoConstaints: MediaTrackConstraints)
    : Promise<any> {}
```

These have now been taken out of beta and publicly documented. More blog articles to be published for these.
@mebjas
Copy link
Owner

mebjas commented Oct 29, 2022

The support is now in PR: #570

Also, latest implementation has been deployed to https://scanapp.org (in case any one want to test and share more insights).

So far I have tested and verified it to work on:

  • Pixel 6 Pro: Chrome
  • Samsung Flip 4: Chrome and Internet (default samsung browser).

Pixel 6 Pro seems to have another layout issue that I need to fix urgently, so will do that first.

Next steps:

  • Fix issues in PR and submit.
  • Make a new release on Github and NPM
  • Add blog posts with documentation.

mebjas added a commit that referenced this issue Oct 30, 2022
* Add support for torch and make beta APIs non beta.

### Version 2.2.5

#### Added support for turning `torch` On and Off in `Html5QrcodeScanner`.
On supported devices + browsers.

This new feature will implement the feature request - [Issue#129](#129) and add support for torch (also called flash) on supported devices and browsers.

So far I have confirmed functionality on Samsung Flip 4 Chrome and Internet (Samsung's default browser).

This is only supported on `Html5QrcodeScanner` and can be enabled using the config like this.

```ts
let html5QrcodeScanner = new Html5QrcodeScanner(
    "reader",
    {
        fps: 10,
        qrbox: qrboxFunction,
        // Important notice: this is experimental feature, use it at your
        // own risk. See documentation in
        // mebjas@/html5-qrcode/src/experimental-features.ts
        experimentalFeatures: {
            useBarCodeDetectorIfSupported: true
        },
        rememberLastUsedCamera: true,
        aspectRatio: 1.7777778,
        showTorchButtonIfSupported: true
    });
```

The `showTorchButtonIfSupported: true` part is the crucial one. It's off by default for now as I don't like the UI very much.

#### Added support for `getRunningTrackSettings()`.

Added a new API to get settings (type: [MediaTrackSettings](https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings)) for running video streams while QR code is being scanned.

```ts
/**
 * Returns the supported settings of the running video track.
 *
 * @returns the supported settings of the running video track.
 * @throws error if the scanning is not in running state.
 */
public getRunningTrackSettings(): MediaTrackSettings {}
```

This API can be used to check the currently applied settings on the running video stream like weather torch is on or not.

#### `getRunningTrackCapabilities(..)` and `applyVideoConstraints(..)` out of beta.

Both `Html5Qrcode` and `Html5QrcodeScanner` classes had support for following APIs.

```ts
/**
 * Returns the capabilities of the running video track.
 *
 * Note: Should only be called if {@code Html5QrcodeScanner#getState()}
 *   returns {@code Html5QrcodeScannerState#SCANNING} or
 *   {@code Html5QrcodeScannerState#PAUSED}.
 *
 * @returns the capabilities of a running video track.
 * @throws error if the scanning is not in running state.
 */
public getRunningTrackCapabilities(): MediaTrackCapabilities {}

 /**
 * Apply a video constraints on running video track from camera.
 *
 * Note: Should only be called if {@code Html5QrcodeScanner#getState()}
 *   returns {@code Html5QrcodeScannerState#SCANNING} or
 *   {@code Html5QrcodeScannerState#PAUSED}.
 *
 * @param {MediaTrackConstraints} specifies a variety of video or camera
 *  controls as defined in
 *  https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints
 * @returns a Promise which succeeds if the passed constraints are applied,
 *  fails otherwise.
 * @throws error if the scanning is not in running state.
 */
public applyVideoConstraints(videoConstaints: MediaTrackConstraints)
    : Promise<any> {}
```

These have now been taken out of beta and publicly documented. More blog articles to be published for these.

* Fix stateful error in torch UI

If we start() --> enable torch --> stop()

And then start() again, the UI was showing `Set torch off` and clicking wouldn't do anything.

This is now fixed.

* Code review fixed + codacy related fixes.

* Update torch-button.ts

replace console.error with error callback.

* Update torch-button.ts
@mebjas
Copy link
Owner

mebjas commented Oct 30, 2022

Feature now submitted and published with version 2.2.6

You can checkout the demo on Android devices (Chrome) on https://scanapp.org or https://qrcode.minhazav.dev.

This is only supported for Html5QrcodeScanner, here's how to use it

let html5QrcodeScanner = new Html5QrcodeScanner(
    "reader",
    {
        fps: 10,
        qrbox: qrboxFunction,
        // Important notice: this is experimental feature, use it at your
        // own risk. See documentation in
        // mebjas@/html5-qrcode/src/experimental-features.ts
        experimentalFeatures: {
            useBarCodeDetectorIfSupported: true
        },
        rememberLastUsedCamera: true,
        aspectRatio: 1.7777778,
        showTorchButtonIfSupported: true
    });

The showTorchButtonIfSupported: true part is the crucial one. It's off by default for now as I don't like the UI very much.

I'll write a blog post on how to use it for Html5Qrcode soon.

@mebjas mebjas closed this as completed Oct 30, 2022
@mebjas
Copy link
Owner

mebjas commented Oct 30, 2022

The article

@diegomariani
Copy link

How can I change the language of the buttons and others library information?

@nexorianus
Copy link

nexorianus commented Nov 2, 2022

@mebjas when can we expect NPM release of 2.2.6?

@mebjas
Copy link
Owner

mebjas commented Nov 2, 2022 via email

@nexorianus
Copy link

It's released. Please check the change logs.

here on Github, yes.
but NPM still has v2.2.5 as its latest version.

✗ yarn add [email protected]
yarn add v1.22.19
[1/5] 🔍  Validating package.json...
[2/5] 🔍  Resolving packages...
Couldn't find any versions for "html5-qrcode" that matches "2.2.6"
? Please choose a version of "html5-qrcode" from this list: (Use arrow keys)
❯ 2.2.5 
  2.2.4 
  2.2.3
  ...

@mebjas
Copy link
Owner

mebjas commented Nov 2, 2022 via email

@mebjas
Copy link
Owner

mebjas commented Nov 2, 2022

Published: https://www.npmjs.com/package/html5-qrcode/v/2.2.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants