easyproctor-hml 0.0.58 → 0.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.js CHANGED
@@ -21842,6 +21842,7 @@ var CameraRecorder = class {
21842
21842
  this.blobsRTC = [];
21843
21843
  this.imageCount = 0;
21844
21844
  this.filesToUpload = [];
21845
+ this.noiseWait = 20;
21845
21846
  this.options = options;
21846
21847
  this.videoOptions = videoOptions;
21847
21848
  this.backend = backend;
@@ -22058,12 +22059,16 @@ Setting: ${settings}`);
22058
22059
  });
22059
22060
  }
22060
22061
  if (((_a2 = this.volumeMeter) == null ? void 0 : _a2.getVolume()) >= (this.options.noiseLimit || 40)) {
22061
- this.options.onRealtimeAlertsCallback({
22062
- status: "ALERT",
22063
- description: "noise",
22064
- type: "audio_detection_on_stream"
22065
- });
22062
+ if (this.noiseWait >= 20) {
22063
+ this.options.onRealtimeAlertsCallback({
22064
+ status: "ALERT",
22065
+ description: "noise",
22066
+ type: "audio_detection_on_stream"
22067
+ });
22068
+ this.noiseWait = 0;
22069
+ }
22066
22070
  }
22071
+ this.noiseWait++;
22067
22072
  }
22068
22073
  };
22069
22074
 
package/index.js CHANGED
@@ -33390,6 +33390,7 @@ var CameraRecorder = class {
33390
33390
  this.blobsRTC = [];
33391
33391
  this.imageCount = 0;
33392
33392
  this.filesToUpload = [];
33393
+ this.noiseWait = 20;
33393
33394
  this.options = options;
33394
33395
  this.videoOptions = videoOptions;
33395
33396
  this.backend = backend;
@@ -33606,12 +33607,16 @@ Setting: ${settings}`);
33606
33607
  });
33607
33608
  }
33608
33609
  if (((_a2 = this.volumeMeter) == null ? void 0 : _a2.getVolume()) >= (this.options.noiseLimit || 40)) {
33609
- this.options.onRealtimeAlertsCallback({
33610
- status: "ALERT",
33611
- description: "noise",
33612
- type: "audio_detection_on_stream"
33613
- });
33610
+ if (this.noiseWait >= 20) {
33611
+ this.options.onRealtimeAlertsCallback({
33612
+ status: "ALERT",
33613
+ description: "noise",
33614
+ type: "audio_detection_on_stream"
33615
+ });
33616
+ this.noiseWait = 0;
33617
+ }
33614
33618
  }
33619
+ this.noiseWait++;
33615
33620
  }
33616
33621
  };
33617
33622
 
@@ -59,5 +59,6 @@ export declare class CameraRecorder implements IRecorder {
59
59
  download(file: File): void;
60
60
  saveOnSession(session: ProctoringSession): Promise<void>;
61
61
  getFile(file: string, name: string, type: string): Promise<File>;
62
+ noiseWait: number;
62
63
  private onNoiseDetected;
63
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easyproctor-hml",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
4
4
  "description": "Modulo web de gravação do EasyProctor",
5
5
  "main": "./index.js",
6
6
  "module": "./esm/index.js",
@@ -70,11 +70,11 @@ bitsperframe: %d
70
70
  border-radius: 50%;
71
71
  display: block;
72
72
  }
73
- `,document.getElementsByTagName("head")[0].appendChild(i)}async predictWebcam(){this.lastVideoTime===-1&&await this.detector.setOptions({runningMode:"VIDEO"});let t=Date.now();if(this.video.currentTime!==this.lastVideoTime){this.lastVideoTime=this.video.currentTime;let r=this.detector.detectForVideo(this.video,t);this.verify(r)}this.animationFrameId=window.requestAnimationFrame(()=>this.predictWebcam())}handleAlert(t,r){this.options.onRealtimeAlertsCallback&&this.options.onRealtimeAlertsCallback({status:"ALERT",description:this.alertTranslate(t),type:r}),this.error&&(this.error.innerText=t)}handleOk(t){this.options.onRealtimeAlertsCallback&&this.options.onRealtimeAlertsCallback({status:"OK",type:t}),this.error&&(this.error.innerText="")}displayVideoDetections(t){}verify(t){}alertTranslate(t){switch(t){case"multiple_faces_detected":return"M\xFAltiplas faces detectadas";case"no_face_detected":return"Nenhuma face encontrada";case"multiple_persons_detected":return"M\xFAltiplas pessoas detectadas";case"no_person_detected":return"Nenhuma pessoa encontrada";case"cellphone_detected":return"Celular detectado";case"wrong_position_face_detected":return"Face na posi\xE7\xE3o errada";default:return t}}};function s4(){let e=document.createElement("div");e.setAttribute("id","liveViewFrameDetection");let t=document.createElement("erro");t.setAttribute("id","errorFrameDetection");let r=document.createElement("video");r.setAttribute("id","videoPreviewFrameDetection"),r.muted=!0,e.style.width="320px",e.style.height="180px",e.style.position="fixed",e.style.bottom="30px",e.style.right="30px",e.style.display="none",r.style.width="100%",r.style.height="100%",r.style.background="#000",e.appendChild(t),e.appendChild(r),document.body.appendChild(e)}var aa=class extends Z0{constructor(r,i,n="videoPreviewFrameDetection",s="liveViewFrameDetection"){super("FaceDetector","https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/1/blaze_face_short_range.tflite",r,i,n,s);this.emmitedPositionAlert=!1}displayVideoDetections(r){for(let i of this.children)this.liveView.removeChild(i);this.children.splice(0);for(let i of r.detections){let n=window.innerWidth,s=window.innerHeight,a=this.video.offsetWidth,m=this.video.offsetHeight,p=a/n,T=m/s,Z=a-i.boundingBox.width*p-i.boundingBox.originX*p,G=i.boundingBox.originY*T,fe=(i.boundingBox.width-10)*p,Ae=i.boundingBox.height*T,ne=document.createElement("p");ne.innerText="Confidence: "+Math.round(parseFloat(i.categories[0].score)*100)+"% .",ne.style.right=Z+"px",ne.style.top=G-50+"px",ne.style.width=fe+"px";let pe={zIndex:"2",position:"absolute",border:"1px dashed #fff"};Object.assign(ne.style,{...pe,margin:"0",fontSize:"9px",paddingBottom:"5px",paddingTop:"5px",color:"#fff",backgroundColor:"#007f8b"});let J=document.createElement("div");J.setAttribute("class","highlighter"),J.style.right=Z+"px",J.style.top=G+"px",J.style.width=fe+"px",J.style.height=Ae-10+"px",Object.assign(J.style,{...pe,zIndex:"1",background:"rgba(0, 255, 0, 0.25)"}),this.liveView.appendChild(J),this.liveView.appendChild(ne),this.children.push(J),this.children.push(ne);for(let Ue of i.keypoints){let Pe=document.createElement("spam");Pe.className="key-point",Pe.style.top=`${Ue.y*this.video.offsetHeight-3}px`,Pe.style.right=`${this.video.offsetWidth-Ue.x*this.video.offsetWidth-3}px`,this.liveView.appendChild(Pe),this.children.push(Pe)}}}verify(r){this.paramsConfig.videoBehaviourParameters?.detectFace&&r.detections.length!==this.numFacesSent&&(this.numFacesSent=r.detections.length,r.detections.length===0?this.handleAlert("no_face_detected","face_detection_on_stream"):r.detections.length>1?this.handleAlert("multiple_faces_detected","face_detection_on_stream"):this.handleOk("face_detection_on_stream")),r.detections[0]?.keypoints[4].x<.2||r.detections[0]?.keypoints[5].x>.8?(!this.emmitedPositionAlert&&this.handleAlert("wrong_position_face_detected","position_detection_on_stream"),this.emmitedPositionAlert=!0):(this.emmitedPositionAlert&&this.handleOk("position_detection_on_stream"),this.emmitedPositionAlert=!1)}};var Un=class{constructor(t){this.stream=t}start(t={}){return new Promise((r,i)=>{try{let n=new AudioContext,s=n.createAnalyser(),a=n.createMediaStreamSource(this.stream);this.scriptProcessor=n.createScriptProcessor(2048,1,1),s.smoothingTimeConstant=.8,s.fftSize=1024,a.connect(s),s.connect(this.scriptProcessor),this.scriptProcessor.connect(n.destination);let m=this;this.scriptProcessor.onaudioprocess=function(){let p=new Uint8Array(s.frequencyBinCount);s.getByteFrequencyData(p);let Z=p.reduce((G,fe)=>G+fe,0)/p.length;m.setVolume(Z),t.setVolume&&t.setVolume(Z)},r(!0)}catch(n){this.stop(),i(`Error: ${n}`)}})}stop(){this.scriptProcessor&&this.scriptProcessor.disconnect()}getVolume(){return this.volume}setVolume(t){this.volume=t}};var $i=class{constructor(t,r,i,n,s){this.blobs=[];this.paramsConfig={audioBehaviourParameters:{recordingBitrate:128},imageBehaviourParameters:{frames:40,useUploadImage:!0,uploadInterval:20,saveVideo:!0},videoBehaviourParameters:{detectPerson:!1,detectFace:!1,detectCellPhone:!1}};this.options={cameraId:void 0,microphoneId:void 0,onBufferSizeError:!1,onBufferSizeErrorCallback:()=>{},proctoringType:"IMAGE",onChangeDevicesCallback:t=>{},onRealtimeAlertsCallback:t=>{}};this.videoOptions={width:640,height:480,minWidth:0,minHeight:0};this.blobsRTC=[];this.imageCount=0;this.filesToUpload=[];this.options=t,this.videoOptions=r,this.backend=n,this.backendToken=s,i&&(this.paramsConfig=i)}setProctoringId(t){this.proctoringId=t,this.proctoringId&&this.backend&&(this.upload=new cn(this.proctoringId,this.backend))}async initializeDetectors(){s4(),this.paramsConfig.videoBehaviourParameters?.detectFace&&(this.faceDetection=new aa({onRealtimeAlertsCallback:t=>this.options.onRealtimeAlertsCallback(t)},this.paramsConfig),await this.faceDetection.initializeDetector())}configImageCapture(){this.video=document.createElement("video"),this.canvas=document.createElement("canvas"),this.video.srcObject=this.cameraStream,this.video.play(),this.video.muted=!0,this.canvas.width=this.videoOptions.width,this.canvas.height=this.videoOptions.height}async startRecording(){(this.paramsConfig.videoBehaviourParameters?.detectPerson||this.paramsConfig.videoBehaviourParameters?.detectCellPhone||this.paramsConfig.videoBehaviourParameters?.detectFace)&&await this.initializeDetectors();let{cameraId:t,microphoneId:r,onBufferSizeErrorCallback:i}=this.options,n={audio:{deviceId:r},video:{deviceId:t,width:this.videoOptions.width,height:this.videoOptions.height,frameRate:15}};try{this.cameraStream=await navigator.mediaDevices.getUserMedia(n)}catch(G){throw G.toString()=="NotReadableError: Could not start video source"?"N\xE3o foi poss\xEDvel conectar a camera, ela pode estar sendo utilizada por outro programa":G}let{startRecording:s,stopRecording:a,pauseRecording:m,resumeRecording:p}=Oa(this.cameraStream,this.blobs,this.proctoringId,this.options.onBufferSizeError,i);this.recordingStart=s,this.recordingStop=a,this.recordingPause=m,this.recordingResume=p,this.recordingStart();let Z=this.cameraStream.getVideoTracks()[0].getSettings();if(this.videoOptions.minWidth>Z.width||this.videoOptions.minHeight>Z.height)throw zu;if(this.videoOptions.width!==Z.width||this.videoOptions.height!==Z.height)throw ot.registerAnotherStream(this.proctoringId,`Maybe have another stream active
73
+ `,document.getElementsByTagName("head")[0].appendChild(i)}async predictWebcam(){this.lastVideoTime===-1&&await this.detector.setOptions({runningMode:"VIDEO"});let t=Date.now();if(this.video.currentTime!==this.lastVideoTime){this.lastVideoTime=this.video.currentTime;let r=this.detector.detectForVideo(this.video,t);this.verify(r)}this.animationFrameId=window.requestAnimationFrame(()=>this.predictWebcam())}handleAlert(t,r){this.options.onRealtimeAlertsCallback&&this.options.onRealtimeAlertsCallback({status:"ALERT",description:this.alertTranslate(t),type:r}),this.error&&(this.error.innerText=t)}handleOk(t){this.options.onRealtimeAlertsCallback&&this.options.onRealtimeAlertsCallback({status:"OK",type:t}),this.error&&(this.error.innerText="")}displayVideoDetections(t){}verify(t){}alertTranslate(t){switch(t){case"multiple_faces_detected":return"M\xFAltiplas faces detectadas";case"no_face_detected":return"Nenhuma face encontrada";case"multiple_persons_detected":return"M\xFAltiplas pessoas detectadas";case"no_person_detected":return"Nenhuma pessoa encontrada";case"cellphone_detected":return"Celular detectado";case"wrong_position_face_detected":return"Face na posi\xE7\xE3o errada";default:return t}}};function s4(){let e=document.createElement("div");e.setAttribute("id","liveViewFrameDetection");let t=document.createElement("erro");t.setAttribute("id","errorFrameDetection");let r=document.createElement("video");r.setAttribute("id","videoPreviewFrameDetection"),r.muted=!0,e.style.width="320px",e.style.height="180px",e.style.position="fixed",e.style.bottom="30px",e.style.right="30px",e.style.display="none",r.style.width="100%",r.style.height="100%",r.style.background="#000",e.appendChild(t),e.appendChild(r),document.body.appendChild(e)}var aa=class extends Z0{constructor(r,i,n="videoPreviewFrameDetection",s="liveViewFrameDetection"){super("FaceDetector","https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/1/blaze_face_short_range.tflite",r,i,n,s);this.emmitedPositionAlert=!1}displayVideoDetections(r){for(let i of this.children)this.liveView.removeChild(i);this.children.splice(0);for(let i of r.detections){let n=window.innerWidth,s=window.innerHeight,a=this.video.offsetWidth,m=this.video.offsetHeight,p=a/n,T=m/s,Z=a-i.boundingBox.width*p-i.boundingBox.originX*p,G=i.boundingBox.originY*T,fe=(i.boundingBox.width-10)*p,Ae=i.boundingBox.height*T,ne=document.createElement("p");ne.innerText="Confidence: "+Math.round(parseFloat(i.categories[0].score)*100)+"% .",ne.style.right=Z+"px",ne.style.top=G-50+"px",ne.style.width=fe+"px";let pe={zIndex:"2",position:"absolute",border:"1px dashed #fff"};Object.assign(ne.style,{...pe,margin:"0",fontSize:"9px",paddingBottom:"5px",paddingTop:"5px",color:"#fff",backgroundColor:"#007f8b"});let J=document.createElement("div");J.setAttribute("class","highlighter"),J.style.right=Z+"px",J.style.top=G+"px",J.style.width=fe+"px",J.style.height=Ae-10+"px",Object.assign(J.style,{...pe,zIndex:"1",background:"rgba(0, 255, 0, 0.25)"}),this.liveView.appendChild(J),this.liveView.appendChild(ne),this.children.push(J),this.children.push(ne);for(let Ue of i.keypoints){let Pe=document.createElement("spam");Pe.className="key-point",Pe.style.top=`${Ue.y*this.video.offsetHeight-3}px`,Pe.style.right=`${this.video.offsetWidth-Ue.x*this.video.offsetWidth-3}px`,this.liveView.appendChild(Pe),this.children.push(Pe)}}}verify(r){this.paramsConfig.videoBehaviourParameters?.detectFace&&r.detections.length!==this.numFacesSent&&(this.numFacesSent=r.detections.length,r.detections.length===0?this.handleAlert("no_face_detected","face_detection_on_stream"):r.detections.length>1?this.handleAlert("multiple_faces_detected","face_detection_on_stream"):this.handleOk("face_detection_on_stream")),r.detections[0]?.keypoints[4].x<.2||r.detections[0]?.keypoints[5].x>.8?(!this.emmitedPositionAlert&&this.handleAlert("wrong_position_face_detected","position_detection_on_stream"),this.emmitedPositionAlert=!0):(this.emmitedPositionAlert&&this.handleOk("position_detection_on_stream"),this.emmitedPositionAlert=!1)}};var Un=class{constructor(t){this.stream=t}start(t={}){return new Promise((r,i)=>{try{let n=new AudioContext,s=n.createAnalyser(),a=n.createMediaStreamSource(this.stream);this.scriptProcessor=n.createScriptProcessor(2048,1,1),s.smoothingTimeConstant=.8,s.fftSize=1024,a.connect(s),s.connect(this.scriptProcessor),this.scriptProcessor.connect(n.destination);let m=this;this.scriptProcessor.onaudioprocess=function(){let p=new Uint8Array(s.frequencyBinCount);s.getByteFrequencyData(p);let Z=p.reduce((G,fe)=>G+fe,0)/p.length;m.setVolume(Z),t.setVolume&&t.setVolume(Z)},r(!0)}catch(n){this.stop(),i(`Error: ${n}`)}})}stop(){this.scriptProcessor&&this.scriptProcessor.disconnect()}getVolume(){return this.volume}setVolume(t){this.volume=t}};var $i=class{constructor(t,r,i,n,s){this.blobs=[];this.paramsConfig={audioBehaviourParameters:{recordingBitrate:128},imageBehaviourParameters:{frames:40,useUploadImage:!0,uploadInterval:20,saveVideo:!0},videoBehaviourParameters:{detectPerson:!1,detectFace:!1,detectCellPhone:!1}};this.options={cameraId:void 0,microphoneId:void 0,onBufferSizeError:!1,onBufferSizeErrorCallback:()=>{},proctoringType:"IMAGE",onChangeDevicesCallback:t=>{},onRealtimeAlertsCallback:t=>{}};this.videoOptions={width:640,height:480,minWidth:0,minHeight:0};this.blobsRTC=[];this.imageCount=0;this.filesToUpload=[];this.noiseWait=20;this.options=t,this.videoOptions=r,this.backend=n,this.backendToken=s,i&&(this.paramsConfig=i)}setProctoringId(t){this.proctoringId=t,this.proctoringId&&this.backend&&(this.upload=new cn(this.proctoringId,this.backend))}async initializeDetectors(){s4(),this.paramsConfig.videoBehaviourParameters?.detectFace&&(this.faceDetection=new aa({onRealtimeAlertsCallback:t=>this.options.onRealtimeAlertsCallback(t)},this.paramsConfig),await this.faceDetection.initializeDetector())}configImageCapture(){this.video=document.createElement("video"),this.canvas=document.createElement("canvas"),this.video.srcObject=this.cameraStream,this.video.play(),this.video.muted=!0,this.canvas.width=this.videoOptions.width,this.canvas.height=this.videoOptions.height}async startRecording(){(this.paramsConfig.videoBehaviourParameters?.detectPerson||this.paramsConfig.videoBehaviourParameters?.detectCellPhone||this.paramsConfig.videoBehaviourParameters?.detectFace)&&await this.initializeDetectors();let{cameraId:t,microphoneId:r,onBufferSizeErrorCallback:i}=this.options,n={audio:{deviceId:r},video:{deviceId:t,width:this.videoOptions.width,height:this.videoOptions.height,frameRate:15}};try{this.cameraStream=await navigator.mediaDevices.getUserMedia(n)}catch(G){throw G.toString()=="NotReadableError: Could not start video source"?"N\xE3o foi poss\xEDvel conectar a camera, ela pode estar sendo utilizada por outro programa":G}let{startRecording:s,stopRecording:a,pauseRecording:m,resumeRecording:p}=Oa(this.cameraStream,this.blobs,this.proctoringId,this.options.onBufferSizeError,i);this.recordingStart=s,this.recordingStop=a,this.recordingPause=m,this.recordingResume=p,this.recordingStart();let Z=this.cameraStream.getVideoTracks()[0].getSettings();if(this.videoOptions.minWidth>Z.width||this.videoOptions.minHeight>Z.height)throw zu;if(this.videoOptions.width!==Z.width||this.videoOptions.height!==Z.height)throw ot.registerAnotherStream(this.proctoringId,`Maybe have another stream active
74
74
  Video Options: ${this.videoOptions}
75
75
  Setting: ${Z}`),Xu;this.paramsConfig.imageBehaviourParameters?.useUploadImage&&this.options.proctoringType=="IMAGE"&&this.photoShotsCycle(),this.paramsConfig.videoBehaviourParameters?.detectFace&&await this.faceDetection.enableCam(this.cameraStream),this.filesToUpload=[],this.options.proctoringType=="REALTIME"&&this.captureFrame(),this.paramsConfig.videoBehaviourParameters?.detectNoise&&(this.intervalNoiseDetection=setInterval(()=>this.onNoiseDetected(),500))}async stopRecording(){if(this.recordingStop&&await this.recordingStop(),this.faceDetection&&this.faceDetection.detecting&&this.faceDetection.stopDetection(),this.objectDetection&&this.objectDetection.detecting&&this.objectDetection.stopDetection(),clearInterval(this.imageInterval),clearInterval(this.sendFrameInterval),this.options.proctoringType=="REALTIME"&&this.upload&&this.backendToken){let t=this.filesToUpload.length,r=this.paramsConfig.imageBehaviourParameters.uploadInterval;for(let i=0;i<t;i++){if(i==t-1){let n=this.filesToUpload[0].name.replace(".jpg","_realtime.jpg"),s=new File([this.filesToUpload[0]],n,{type:"image/jpeg"});this.filesToUpload[0]=s}this.filesToUpload[0]&&await this.upload.uploadImages({file:this.filesToUpload[0]},this.backendToken,r),this.filesToUpload.shift()}}this.volumeMeter&&this.volumeMeter.stop(),this.intervalNoiseDetection&&clearInterval(this.intervalNoiseDetection)}async pauseRecording(){await this.recordingPause()}async resumeRecording(){await this.recordingResume()}photoShotsCycle(){let t;this.configImageCapture(),this.imageInterval=setInterval(async()=>{this.canvas.getContext("2d").drawImage(this.video,0,0,this.videoOptions.width,this.videoOptions.height);let r=this.canvas.toDataURL("image/jpeg");t=await this.getFile(r,`${this.proctoringId}_${this.imageCount+1}.jpg`,"image/jpeg"),t&&this.upload&&this.backendToken&&(this.upload.upload({file:t},this.backendToken,!0),this.imageCount++)},this.paramsConfig.imageBehaviourParameters.uploadInterval*1e3)}captureFrame(){let t;this.configImageCapture();let r=this.paramsConfig.imageBehaviourParameters.uploadInterval,i=!1;this.imageInterval=setInterval(async()=>{this.canvas.getContext("2d").drawImage(this.video,0,0,this.videoOptions.width,this.videoOptions.height);let n=this.canvas.toDataURL("image/jpeg");if(this.proctoringId==null)return;i==!1&&(i=!0,this.sendFrame());let s=`${this.proctoringId}_${this.imageCount+1}.jpg`;(this.imageCount+1)%r==0&&(s=`${this.proctoringId}_${this.imageCount+1}_realtime.jpg`),t=await this.getFile(n,s,"image/jpeg"),t&&(this.filesToUpload.push(t),this.imageCount++)},1e3)}sendFrame(){let t=this.paramsConfig.imageBehaviourParameters.uploadInterval;this.sendFrameInterval=setInterval(async()=>{if(this.upload&&this.backendToken)for(let r=0;r<t&&this.filesToUpload.length!=0;r++)await this.upload.uploadImages({file:this.filesToUpload[0]},this.backendToken,t),await this.filesToUpload.shift()},t*1e3)}download(t){let r=URL.createObjectURL(t),i=document.createElement("a");document.body.appendChild(i),i.style.display="none",i.href=r,i.download=t.name,i.click(),window.URL.revokeObjectURL(r)}async saveOnSession(t){let r=this.cameraStream.getVideoTracks()[0].getSettings(),i=this.cameraStream.getAudioTracks()[0].getSettings();(this.options.proctoringType=="VIDEO"||this.options.proctoringType=="REALTIME"||this.options.proctoringType=="IMAGE"&&this.paramsConfig.imageBehaviourParameters?.saveVideo)&&t.addRecording({device:`Audio
76
76
  Sample Rate: ${i.sampleRate}
77
- Sample Size: ${i.sampleSize}`,file:new File(this.blobs,`EP_${t.id}_camera_0.webm`,{type:"video/webm"}),origin:"Camera"})}async getFile(t,r,i){return new Promise((n,s)=>{t.length>5&&fetch(t).then(a=>a.blob()).then(a=>{let m=new File([a],r,{type:i});n(m)}).catch(a=>{s(a)})})}onNoiseDetected(){!this.volumeMeter&&this.cameraStream&&(this.volumeMeter=new Un(this.cameraStream),this.volumeMeter.start().catch(t=>{console.log(t),this.volumeMeter=void 0})),this.volumeMeter?.getVolume()>=(this.options.noiseLimit||40)&&this.options.onRealtimeAlertsCallback({status:"ALERT",description:"noise",type:"audio_detection_on_stream"})}};var oa=class{constructor(){}async takePicture(t,r,i={width:1080,height:720}){return this.resolution=i,await this.takePictureInterface(t,r)}async startCapture(t="default"){let r=document.querySelector("#cameraStream"),i={audio:!1,video:{facingMode:"user",aspectRatio:1.777777778,width:{min:640,ideal:640,max:1920},height:{min:400,ideal:480},deviceId:t}};this.cameraRecorder=new $i({cameraId:t,onBufferSizeErrorCallback:()=>{}},{...this.resolution}),await this.cameraRecorder.startRecording(),r.srcObject=this.cameraRecorder.cameraStream,r.play()}shot(){let t=document.querySelector("#cameraStream"),r=document.querySelector("#canvas"),i=document.querySelector("#image");r.width=t.videoWidth,r.height=t.videoHeight,r.getContext("2d").drawImage(t,0,0,t.videoWidth,t.videoHeight),i.src=r.toDataURL("image/jpg"),this.base64=r.toDataURL("image/jpg")}takePictureInterface(t,r){return new Promise(i=>{let n=document.createElement("div");n.setAttribute("id","authPhoto"),n.style.backgroundColor="rgba(0,0,0,0.4)",n.style.zIndex="1000",n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.height="100vh",n.style.width="100%",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center";let s=document.createElement("div");s.style.backgroundColor="#fff",s.style.zIndex="1001",s.style.position="fixed",s.style.top="0",s.style.left="0",s.style.height="100vh",s.style.width="100%",s.style.borderRadius="10px",s.style.display="flex",s.style.flexDirection="column",s.style.alignItems="center",s.style.boxSizing="border-box";let a=document.createElement("h3");a.innerText=t||"Biometria Facial",a.style.color="rgba(0, 0, 0, .7)",a.style.fontWeight="bold",a.style.fontSize="20px",a.style.marginTop="0px",a.style.marginBottom="15px",a.style.padding="20px 0px 0px",a.style.width="100%",a.style.textAlign="center",a.style.position="fixed",a.style.top="0",a.style.left="0",a.style.zIndex="1010",s.appendChild(a);let m=document.createElement("p");m.innerText=r||"Encaixe seu rosto no formato e clique no bot\xE3o abaixo",m.style.color="rgba(0, 0, 0, .7)",m.style.fontWeight="normal",m.style.fontSize="16px",m.style.marginBottom="15px",m.style.padding="0px 0px 20px",m.style.width="100%",m.style.textAlign="center",m.style.position="fixed",m.style.top="55px",m.style.left="0",m.style.zIndex="1011",s.appendChild(m);let p=document.createElement("div"),T=document.createElement("h3"),Z=document.createElement("select");Z.setAttribute("id","cameraSelect"),p.style.padding="0 20px",p.style.width="100%",p.style.display="flex",p.style.justifyContent="space-between",p.style.marginBottom="15px",T.innerText="C\xE2mera",T.style.color="rgba(0, 0, 0, .75)",T.style.fontWeight="bold",T.style.fontSize="16px",p.appendChild(T),p.appendChild(Z);let G=document.createElement("div"),fe=document.createElement("video");fe.setAttribute("id","cameraStream"),fe.muted=!0,G.style.position="fixed",G.style.top="0",G.style.left="0",G.style.height="100vh",G.style.width="100%",G.style.display="flex",G.style.justifyContent="center",fe.style.backgroundColor="#000",fe.style.borderRadius="10px",fe.style.width="auto",fe.style.height="auto",fe.style.minHeight="100%",G.appendChild(fe);let Ae=document.createElement("canvas");Ae.setAttribute("id","canvas"),Ae.style.display="none",Ae.style.width="100%",Ae.style.height="100%";let ne=document.createElement("img");ne.setAttribute("id","image"),ne.style.objectFit="contain",ne.style.display="none",ne.style.borderRadius="8px",G.appendChild(Ae),G.appendChild(ne);let pe=document.createElement("div");pe.setAttribute("class","facial-biometry__mask"),pe.style.width="100%",pe.style.height="100%",pe.style.position="absolute",pe.style.top="0px",pe.style.left="0px",pe.style.backgroundColor="#fff",pe.style.opacity="0.8";let J=document.createElement("div");J.setAttribute("class","biometry__frame"),J.style.width="100%",J.style.height="100%",J.style.position="absolute",J.style.top="0px",J.style.left="0px",J.style.zIndex="10",G.appendChild(pe),G.appendChild(J),s.appendChild(G),this.addStyleMask();let Ue=document.createElement("button"),Pe=document.createElement("div");Ue.setAttribute("id","confirmBtn"),Pe.style.position="fixed",Pe.style.bottom="0",Pe.style.left="0",Pe.style.width="100%",Pe.style.display="flex",Pe.style.alignItems="center",Pe.style.justifyContent="center",Ue.style.background="url('https://iarisprod.blob.core.windows.net/imagens/camera.svg') no-repeat center",Ue.style.width="70px",Ue.style.height="70px",Ue.style.borderRadius="70px",Ue.style.border="none",Ue.style.backgroundColor="#16a34a",Ue.style.margin="20px 0",Pe.appendChild(Ue),s.appendChild(Pe);let wt=document.createElement("button");wt.style.background="url('https://iarisprod.blob.core.windows.net/imagens/close.svg') no-repeat center",wt.style.width="70px",wt.style.height="70px",wt.style.borderRadius="70px",wt.style.border="none",wt.style.backgroundColor="#e74141",wt.style.margin="20px 20px";let er=document.createElement("button");er.style.background="url('https://iarisprod.blob.core.windows.net/imagens/check.svg') no-repeat center",er.style.width="70px",er.style.height="70px",er.style.borderRadius="70px",er.style.border="none",er.style.backgroundColor="#16a34a",er.style.margin="20px 20px",n.appendChild(s),document.body.appendChild(n),this.setSelectOption(),this.startCapture(),Ue.addEventListener("click",()=>{Pe.removeChild(Ue),Pe.appendChild(wt),Pe.appendChild(er),this.shot(),fe.style.display="none",ne.style.display="block"}),wt.addEventListener("click",()=>{Pe.appendChild(Ue),Pe.removeChild(wt),Pe.removeChild(er),fe.style.display="block",ne.style.display="none"}),er.addEventListener("click",()=>{this.closeInterface(),i({base64:this.base64})})})}async setSelectOption(){let t=document.querySelector("#cameraSelect"),r=await gi();t&&(t.value="default");let i=(n,s)=>{let a=document.createElement("option");return a.setAttribute("value",s),a.innerHTML=n,a};r.cameras.forEach(n=>{let s=i(n.label,n.id);t?.appendChild(s)}),this.onSelectOptionChange()}async onSelectOptionChange(){let t=document.querySelector("#cameraSelect");t?.addEventListener("change",async()=>{this.startCapture(t?.value)})}async closeInterface(){await this.cameraRecorder.stopRecording(),document.querySelector("#authPhoto")?.remove()}async addStyleMask(){let t=`
77
+ Sample Size: ${i.sampleSize}`,file:new File(this.blobs,`EP_${t.id}_camera_0.webm`,{type:"video/webm"}),origin:"Camera"})}async getFile(t,r,i){return new Promise((n,s)=>{t.length>5&&fetch(t).then(a=>a.blob()).then(a=>{let m=new File([a],r,{type:i});n(m)}).catch(a=>{s(a)})})}onNoiseDetected(){!this.volumeMeter&&this.cameraStream&&(this.volumeMeter=new Un(this.cameraStream),this.volumeMeter.start().catch(t=>{console.log(t),this.volumeMeter=void 0})),this.volumeMeter?.getVolume()>=(this.options.noiseLimit||40)&&this.noiseWait>=20&&(this.options.onRealtimeAlertsCallback({status:"ALERT",description:"noise",type:"audio_detection_on_stream"}),this.noiseWait=0),this.noiseWait++}};var oa=class{constructor(){}async takePicture(t,r,i={width:1080,height:720}){return this.resolution=i,await this.takePictureInterface(t,r)}async startCapture(t="default"){let r=document.querySelector("#cameraStream"),i={audio:!1,video:{facingMode:"user",aspectRatio:1.777777778,width:{min:640,ideal:640,max:1920},height:{min:400,ideal:480},deviceId:t}};this.cameraRecorder=new $i({cameraId:t,onBufferSizeErrorCallback:()=>{}},{...this.resolution}),await this.cameraRecorder.startRecording(),r.srcObject=this.cameraRecorder.cameraStream,r.play()}shot(){let t=document.querySelector("#cameraStream"),r=document.querySelector("#canvas"),i=document.querySelector("#image");r.width=t.videoWidth,r.height=t.videoHeight,r.getContext("2d").drawImage(t,0,0,t.videoWidth,t.videoHeight),i.src=r.toDataURL("image/jpg"),this.base64=r.toDataURL("image/jpg")}takePictureInterface(t,r){return new Promise(i=>{let n=document.createElement("div");n.setAttribute("id","authPhoto"),n.style.backgroundColor="rgba(0,0,0,0.4)",n.style.zIndex="1000",n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.height="100vh",n.style.width="100%",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center";let s=document.createElement("div");s.style.backgroundColor="#fff",s.style.zIndex="1001",s.style.position="fixed",s.style.top="0",s.style.left="0",s.style.height="100vh",s.style.width="100%",s.style.borderRadius="10px",s.style.display="flex",s.style.flexDirection="column",s.style.alignItems="center",s.style.boxSizing="border-box";let a=document.createElement("h3");a.innerText=t||"Biometria Facial",a.style.color="rgba(0, 0, 0, .7)",a.style.fontWeight="bold",a.style.fontSize="20px",a.style.marginTop="0px",a.style.marginBottom="15px",a.style.padding="20px 0px 0px",a.style.width="100%",a.style.textAlign="center",a.style.position="fixed",a.style.top="0",a.style.left="0",a.style.zIndex="1010",s.appendChild(a);let m=document.createElement("p");m.innerText=r||"Encaixe seu rosto no formato e clique no bot\xE3o abaixo",m.style.color="rgba(0, 0, 0, .7)",m.style.fontWeight="normal",m.style.fontSize="16px",m.style.marginBottom="15px",m.style.padding="0px 0px 20px",m.style.width="100%",m.style.textAlign="center",m.style.position="fixed",m.style.top="55px",m.style.left="0",m.style.zIndex="1011",s.appendChild(m);let p=document.createElement("div"),T=document.createElement("h3"),Z=document.createElement("select");Z.setAttribute("id","cameraSelect"),p.style.padding="0 20px",p.style.width="100%",p.style.display="flex",p.style.justifyContent="space-between",p.style.marginBottom="15px",T.innerText="C\xE2mera",T.style.color="rgba(0, 0, 0, .75)",T.style.fontWeight="bold",T.style.fontSize="16px",p.appendChild(T),p.appendChild(Z);let G=document.createElement("div"),fe=document.createElement("video");fe.setAttribute("id","cameraStream"),fe.muted=!0,G.style.position="fixed",G.style.top="0",G.style.left="0",G.style.height="100vh",G.style.width="100%",G.style.display="flex",G.style.justifyContent="center",fe.style.backgroundColor="#000",fe.style.borderRadius="10px",fe.style.width="auto",fe.style.height="auto",fe.style.minHeight="100%",G.appendChild(fe);let Ae=document.createElement("canvas");Ae.setAttribute("id","canvas"),Ae.style.display="none",Ae.style.width="100%",Ae.style.height="100%";let ne=document.createElement("img");ne.setAttribute("id","image"),ne.style.objectFit="contain",ne.style.display="none",ne.style.borderRadius="8px",G.appendChild(Ae),G.appendChild(ne);let pe=document.createElement("div");pe.setAttribute("class","facial-biometry__mask"),pe.style.width="100%",pe.style.height="100%",pe.style.position="absolute",pe.style.top="0px",pe.style.left="0px",pe.style.backgroundColor="#fff",pe.style.opacity="0.8";let J=document.createElement("div");J.setAttribute("class","biometry__frame"),J.style.width="100%",J.style.height="100%",J.style.position="absolute",J.style.top="0px",J.style.left="0px",J.style.zIndex="10",G.appendChild(pe),G.appendChild(J),s.appendChild(G),this.addStyleMask();let Ue=document.createElement("button"),Pe=document.createElement("div");Ue.setAttribute("id","confirmBtn"),Pe.style.position="fixed",Pe.style.bottom="0",Pe.style.left="0",Pe.style.width="100%",Pe.style.display="flex",Pe.style.alignItems="center",Pe.style.justifyContent="center",Ue.style.background="url('https://iarisprod.blob.core.windows.net/imagens/camera.svg') no-repeat center",Ue.style.width="70px",Ue.style.height="70px",Ue.style.borderRadius="70px",Ue.style.border="none",Ue.style.backgroundColor="#16a34a",Ue.style.margin="20px 0",Pe.appendChild(Ue),s.appendChild(Pe);let wt=document.createElement("button");wt.style.background="url('https://iarisprod.blob.core.windows.net/imagens/close.svg') no-repeat center",wt.style.width="70px",wt.style.height="70px",wt.style.borderRadius="70px",wt.style.border="none",wt.style.backgroundColor="#e74141",wt.style.margin="20px 20px";let er=document.createElement("button");er.style.background="url('https://iarisprod.blob.core.windows.net/imagens/check.svg') no-repeat center",er.style.width="70px",er.style.height="70px",er.style.borderRadius="70px",er.style.border="none",er.style.backgroundColor="#16a34a",er.style.margin="20px 20px",n.appendChild(s),document.body.appendChild(n),this.setSelectOption(),this.startCapture(),Ue.addEventListener("click",()=>{Pe.removeChild(Ue),Pe.appendChild(wt),Pe.appendChild(er),this.shot(),fe.style.display="none",ne.style.display="block"}),wt.addEventListener("click",()=>{Pe.appendChild(Ue),Pe.removeChild(wt),Pe.removeChild(er),fe.style.display="block",ne.style.display="none"}),er.addEventListener("click",()=>{this.closeInterface(),i({base64:this.base64})})})}async setSelectOption(){let t=document.querySelector("#cameraSelect"),r=await gi();t&&(t.value="default");let i=(n,s)=>{let a=document.createElement("option");return a.setAttribute("value",s),a.innerHTML=n,a};r.cameras.forEach(n=>{let s=i(n.label,n.id);t?.appendChild(s)}),this.onSelectOptionChange()}async onSelectOptionChange(){let t=document.querySelector("#cameraSelect");t?.addEventListener("change",async()=>{this.startCapture(t?.value)})}async closeInterface(){await this.cameraRecorder.stopRecording(),document.querySelector("#authPhoto")?.remove()}async addStyleMask(){let t=`
78
78
  .facial-biometry__mask {
79
79
  mask-image: url('https://iarisprod.blob.core.windows.net/imagens/square.svg'), url('https://iarisprod.blob.core.windows.net/imagens/face-mask.svg');
80
80
  mask-size: cover, auto 65%;