barcode-reader-javascript
barcode-reader-javascript copied to clipboard
MediaTrackCapabilities should have a torch field in it's interface?
I had a piece of code that checks for the availability of the torch in the mobile device i'm using:
const capabilities = await cameraEnhancer.getCapabilities();
But by doing this I get a typescript error:
Property 'torch' does not exist on type 'MediaTrackCapabilities'.
By checking the lib.dom.d.ts I can actually see that said iterface (MediaTrackCapabilities) does not have a torch declaration:
interface MediaTrackCapabilities {
aspectRatio?: DoubleRange;
autoGainControl?: boolean[];
channelCount?: ULongRange;
deviceId?: string;
displaySurface?: string;
echoCancellation?: boolean[];
facingMode?: string[];
frameRate?: DoubleRange;
groupId?: string;
height?: ULongRange;
noiseSuppression?: boolean[];
sampleRate?: ULongRange;
sampleSize?: ULongRange;
width?: ULongRange;
}
Is the interface missing the "torch" specific or have I done something wrong in my code?
Sorry for reply late because of my vacation.
Camera related API in web world is still under continuous improving. It's common to find that some fields are not defined in typescript.
You can upgrade typescript version to see if it works.
Or just convert the variable to any.
if((capabilities as any).torch){
// do some thing torch available
await cameraEnhancer.turnOnTorch();
}