-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add support for detecting and turning on/off flash light #241
Conversation
@@ -5,7 +5,7 @@ | |||
"sourceMap": true, | |||
"moduleResolution": "classic", | |||
"lib": [ | |||
"es7", | |||
"es2018", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was already needed for:
html5-qrcode/src/html5-qrcode.ts
Line 1033 in a14ca5e
.finally(() => { |
Thanks @lafriks for this, super helpful! Would you mind sending this PR to https://github.com/mebjas/html5-qrcode/tree/flashlight instead, so I can tweak things to taste a bit after trying out and merge to master later & publish? |
I'll review that PR directly. |
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request, it already looks good. Added some minor comments.
@@ -237,6 +237,7 @@ export class Html5Qrcode { | |||
private qrRegion: QrcodeRegionBounds | null = null; | |||
private context: CanvasRenderingContext2D | null = null; | |||
private lastScanImageFile: string | null = null; | |||
private flashOn: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, rename to isFlashOn
for easier reading.
return Promise.resolve(false); | ||
} | ||
|
||
const track = this.videoElement?.srcObject ? (<MediaStream>this.videoElement.srcObject).getVideoTracks()[0] : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, split into two lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment 2: could this lead to null ptr exception if ...getVideoTracks()
returns undefined or empty array? we should do a length
check first.
* | ||
* @returns Current flash state. | ||
*/ | ||
public isFlashOn(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why expose this state via a public method?
* @param on if true flash will be turned on otherwise turned off. | ||
* @returns Promise that flash state has changed. | ||
*/ | ||
public setFlash(on: boolean): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional, rename to more readable shouldSetFlashOn
or something more relevant.
@@ -767,6 +833,7 @@ export class Html5Qrcode { | |||
const tracks = stream.getVideoTracks(); | |||
for (const track of tracks) { | |||
track.enabled = false; | |||
// This will also stop flash light |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit, add a "." after the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ditto elsewhere)
Not sure if I'm posting this in the correct place. I am using the Html5Qrcode source successfully and was wondering how I would insert code to add a toggle to access on/off for the flashlight in my code. I read above you have to call it after the camera is accessed?
|
@rodneystover |
@mebjas |
Some comments need to be addressed here. I can alternatively add this feature in a separate PR. |
@mebjas Any update on flashlight support? |
I am working on this now! - follow #129 for progress. |
Add support for flash light in
Html5QrcodeScanner
andHtml5Qrcode
#129