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

No typescript support for focusMode in videoConstraints #453

Closed
coooo77 opened this issue Mar 25, 2022 · 5 comments
Closed

No typescript support for focusMode in videoConstraints #453

coooo77 opened this issue Mar 25, 2022 · 5 comments

Comments

@coooo77
Copy link

coooo77 commented Mar 25, 2022

Describe the bug
Have problem with autofocus and found issues relative to.
But can not apply videoConstraints for focusMode

image
image
image
image

Expected behavior
Can use focusMode properties define in MediaTrackConstraints - Web APIs | MDN

Additional context
html5-qrcode version: "2.2.0"

@ROBERT-MCDOWELL
Copy link

this is a camera or OS limitation I think

@juanpablocerdarodriguez

Same problem here, any progress @coooo77 ?

@coooo77
Copy link
Author

coooo77 commented Jul 31, 2022

Same problem here, any progress @coooo77 ?

no, you can use @ts-ignore or make a PR to fix it instead.

@mebjas
Copy link
Owner

mebjas commented Nov 17, 2022

I have observed similar issues. This is Microsoft’s limitation around typescript I believe.

Here’s how I had to hack it: https://github.com/mebjas/html5-qrcode/blob/master/src/html5-qrcode.ts#L1183

(Closing this as a stack overflow type of question - please ask on SO for quicker resolution and benefit of other readers)

@mebjas mebjas closed this as completed Nov 17, 2022
@webia1
Copy link

webia1 commented Oct 11, 2024

you can extend them and use then the extended Type Defs:

interface AdvancedMediaTrackConstraintSet extends MediaTrackConstraintSet {
  zoom?: ConstrainDouble;
  focusMode?: ConstrainDOMString;
  focusDistance?: ConstrainDouble;
}

export interface ExtendedMediaTrackConstraintSet
  extends MediaTrackConstraintSet {
  zoom?: ConstrainDouble;
  advanced?: Array<AdvancedMediaTrackConstraintSet>;
}

use case (assumed you've already detected your video track)

const autoFocusConstraint: ExtendedMediaTrackConstraintSet = {
  advanced: [{ focusMode: 'auto' }],
};

await this.videoTrack.applyConstraints(autoFocusConstraint);

To detect the video track (Example within a method in Angular):

// replace the scanner with yours

const videoElement = this.scanner?.nativeElement?.querySelector('video');

if (!videoElement) {
  console.error('Video element not found');
  return;
}

const stream = videoElement.srcObject as MediaStream;
if (!stream) {
  console.error('No media stream found');
  return;
}

this.videoTrack = stream.getVideoTracks()[0];
if (!this.videoTrack) {
  console.error('No video track found');
  return;
}

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

No branches or pull requests

5 participants