Ready for usage in PWA, SPA (Angular, React, Vue, etc).
Compliled size: 5kB.
3rd party dependency: jsqr (https://github.com/cozmo/jsQR), size: 254Kb.
isMediaStreamAPISupported(): boolean
getVideoInputDevices(): Promise<MediaDeviceInfo[]>
startCapture(video: HTMLElement, captureInterval?: number): Promise<string>
stopCapture(): void
stopAndSwitchCamera(): void
// import
import QRReader from 'QRReader';
// init
const qrCodeReader = new QRReader();
const videoElement = document.getElementById('video');
// start Capture
start() {
qrCodeReader.startCapture(videoElement)
.then(decodedData => {
console.log(decodedData);
})
.catch(console.log);
}
// cancel Capture
onCancelClick() {
qrCodeReader.stopCapture();
}
// switch input device
switchCamera() {
qrCodeReader.stopAndSwitchCamera();
}