-
-
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
No typescript support for focusMode in videoConstraints #453
Comments
this is a camera or OS limitation I think |
Same problem here, any progress @coooo77 ? |
no, you can use @ts-ignore or make a PR to fix it instead. |
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) |
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;
} |
Describe the bug
Have problem with autofocus and found issues relative to.
But can not apply videoConstraints for focusMode
Expected behavior
Can use focusMode properties define in MediaTrackConstraints - Web APIs | MDN
Additional context
html5-qrcode version: "2.2.0"
The text was updated successfully, but these errors were encountered: