this._sourceRect,this._qrWorker,this.$canvas,true).then(this._onDecode,(error)=>{if(error!=="QR code not found.")console.error(error)}).then(()=>this._scanFrame())})}_getCameraStream(facingMode,exact=false){constconstraintsToTry=[{width:{min:1024}},{width:{min:768}},{}];if(facingMode){if(exact)facingMode={exact:facingMode};constraintsToTry.forEach((constraint)=>constraint.facingMode=facingMode)}returnthis._getMatchingCameraStream(constraintsToTry)}_getMatchingCameraStream(constraintsToTry){if(constraintsToTry.length===
0)returnPromise.reject("Camera not found.");returnnavigator.mediaDevices.getUserMedia({video:constraintsToTry.shift()}).catch(()=>this._getMatchingCameraStream(constraintsToTry))}start(){if(this._active)returnPromise.resolve();this._active=true;clearTimeout(this._offTimeout);letfacingMode="environment";returnthis._getCameraStream("environment",true).catch(()=>{facingMode="user";returnthis._getCameraStream()}).then((stream)=>{this.$video.srcObject=stream;this._setVideoMirror(facingMode)}).catch((e)=>
null,canvas=null,fixedCanvasSize=false,alsoTryWithoutSourceRect=false){constpromise=newPromise((resolve,reject)=>{worker=worker||newWorker(QrScanner.WORKER_PATH);lettimeout,onMessage,onError;onMessage=(event)=>{if(event.data.type!=="qrResult")return;worker.removeEventListener("message",onMessage);worker.removeEventListener("error",onError);clearTimeout(timeout);if(event.data.data!==null)resolve(event.data.data);elsereject("QR code not found.")};onError=()=>{worker.removeEventListener("message",