easyproctor-hml 2.5.1 → 2.5.2
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 +6 -1
- package/index.js +6 -1
- package/package.json +1 -1
- package/unpkg/easyproctor.min.js +2 -2
package/esm/index.js
CHANGED
|
@@ -10163,6 +10163,10 @@ var CameraRecorder = class {
|
|
|
10163
10163
|
this.recordingStart();
|
|
10164
10164
|
const tracks = this.cameraStream.getVideoTracks();
|
|
10165
10165
|
const settings = tracks[0].getSettings();
|
|
10166
|
+
console.log("settings -> ", settings.width, settings.height);
|
|
10167
|
+
console.log("videoOptions -> ", this.videoOptions.width, this.videoOptions.height);
|
|
10168
|
+
console.log("minWidth -> ", this.videoOptions.minWidth);
|
|
10169
|
+
console.log("minHeight -> ", this.videoOptions.minHeight);
|
|
10166
10170
|
if (this.videoOptions.minWidth > settings.width || this.videoOptions.minHeight > settings.height) {
|
|
10167
10171
|
throw STREAM_UNDER_MINIMUM_PERMITTED;
|
|
10168
10172
|
} else if (this.videoOptions.width !== settings.width || this.videoOptions.height !== settings.height) {
|
|
@@ -18953,7 +18957,8 @@ Upload Services: ${uploaderServices}`,
|
|
|
18953
18957
|
});
|
|
18954
18958
|
if (this.appChecker) {
|
|
18955
18959
|
const externalSessionId = this.appChecker.getExternalCameraSessionId();
|
|
18956
|
-
|
|
18960
|
+
console.log("externalSessionId -> ", externalSessionId);
|
|
18961
|
+
if (externalSessionId != "null") {
|
|
18957
18962
|
await this.backend.externalCameraFinish(externalSessionId);
|
|
18958
18963
|
}
|
|
18959
18964
|
}
|
package/index.js
CHANGED
|
@@ -28260,6 +28260,10 @@ var CameraRecorder = class {
|
|
|
28260
28260
|
this.recordingStart();
|
|
28261
28261
|
const tracks = this.cameraStream.getVideoTracks();
|
|
28262
28262
|
const settings = tracks[0].getSettings();
|
|
28263
|
+
console.log("settings -> ", settings.width, settings.height);
|
|
28264
|
+
console.log("videoOptions -> ", this.videoOptions.width, this.videoOptions.height);
|
|
28265
|
+
console.log("minWidth -> ", this.videoOptions.minWidth);
|
|
28266
|
+
console.log("minHeight -> ", this.videoOptions.minHeight);
|
|
28263
28267
|
if (this.videoOptions.minWidth > settings.width || this.videoOptions.minHeight > settings.height) {
|
|
28264
28268
|
throw STREAM_UNDER_MINIMUM_PERMITTED;
|
|
28265
28269
|
} else if (this.videoOptions.width !== settings.width || this.videoOptions.height !== settings.height) {
|
|
@@ -34202,7 +34206,8 @@ Upload Services: ${uploaderServices}`,
|
|
|
34202
34206
|
});
|
|
34203
34207
|
if (this.appChecker) {
|
|
34204
34208
|
const externalSessionId = this.appChecker.getExternalCameraSessionId();
|
|
34205
|
-
|
|
34209
|
+
console.log("externalSessionId -> ", externalSessionId);
|
|
34210
|
+
if (externalSessionId != "null") {
|
|
34206
34211
|
await this.backend.externalCameraFinish(externalSessionId);
|
|
34207
34212
|
}
|
|
34208
34213
|
}
|
package/package.json
CHANGED
package/unpkg/easyproctor.min.js
CHANGED
|
@@ -73,7 +73,7 @@ Minimum version required to store current data is: `+i+`.
|
|
|
73
73
|
File size: ${o.size}`),new Error("Failed to upload to AWS")}}async upload(t,r,n){let{file:o,onProgress:i}=t;try{let s=l=>{let h=l.loadedBytes/o.size*100;i&&i(Math.round(h))},a;if(n){if(this.imageBatchNum===this.contImages){let l=[];for(let d=this.imageBatchNum;d<this.imageBatchNum+20;d++)l.push({objectName:`${this.proctoringId}/${this.proctoringId}_${d+1}.jpg`,contentType:"image/jpeg"});(await this.backend.getSignedUrlImage(r,l)).map(d=>{this.imageUrlPackage.push(d)}),this.imageBatchNum+=20}}else a=await this.backend.getSignedUrl(r,o,this.proctoringId);let c=!1;return n?c=await $t.request({url:this.imageUrlPackage[this.contImages],method:"PUT",headers:{"Content-Type":o.type,"x-ms-blob-type":"BlockBlob"},data:o,onUploadProgress:l=>{s({loadedBytes:l.loaded})}}).then(()=>!0).catch(()=>!1).finally(()=>{this.contImages++}):c=await $t.request({url:a,method:"PUT",headers:{"Content-Type":o.type,"x-ms-blob-type":"BlockBlob"},data:o,onUploadProgress:l=>{s({loadedBytes:l.loaded})}}).then(()=>!0).catch(()=>!1),{storage:"upload",url:a,uploaded:c}}catch{throw L.registerError(this.proctoringId,`Failed to upload to AWS
|
|
74
74
|
File name: ${o.name}
|
|
75
75
|
File type: ${o.type}
|
|
76
|
-
File size: ${o.size}`),new Error("Failed to upload to AWS")}}};var Ig="not_shared_first_screen",Pg="not_shared_screen",la="multiple_monitors_detected",Rg="proctoring_already_started",ha="proctoring_not_started";var Dg="another_stream_active",Og="stream_under_minimum_permitted",Bg="browser_not_supported",Mg="token_missing",Lg="credentials_missing";var Ug="spy_scan_api_not_found";var Fg="external_camera_not_started";var da=class extends qn{constructor(t,r,n="videoPreviewFrameDetection",o="liveViewFrameDetection"){super("ObjectDetector","https://storage.googleapis.com/mediapipe-models/object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite",t,r,n,o)}displayVideoDetections(t){for(let r of this.children)this.liveView.removeChild(r);this.children.splice(0);for(let r of t.detections){let n=window.innerWidth,o=window.innerHeight,i=this.video.offsetWidth,s=this.video.offsetHeight,a=i/n,c=s/o,l=i-r.boundingBox.width*a-r.boundingBox.originX*a,h=r.boundingBox.originY*c,d=(r.boundingBox.width-10)*a,p=r.boundingBox.height*c,b=document.createElement("p");b.innerText=r.categories[0].categoryName+" - with "+Math.round(parseFloat(r.categories[0].score)*100)+"% confidence.",b.style.right=l-20+"px",b.style.top=h+"px",b.style.width=d+"px";let m={zIndex:"2",position:"absolute",border:"1px dashed #fff"};Object.assign(b.style,{...m,margin:"0",fontSize:"9px",paddingBottom:"5px",paddingTop:"5px",color:"#fff",backgroundColor:"#007f8b"});let f=document.createElement("div");f.setAttribute("class","highlighter"),f.style.right=l-20+"px",f.style.top=h+"px",f.style.width=d+"px",f.style.height=p-20+"px",Object.assign(f.style,{...m,zIndex:"1",background:"rgba(0, 255, 0, 0.25)"}),this.liveView.appendChild(f),this.liveView.appendChild(b),this.children.push(f),this.children.push(b)}}verify(t){let r=t.detections.filter(o=>o.categories.some(i=>i.categoryName==="person")).length,n=t.detections.filter(o=>o.categories.some(i=>i.categoryName==="cell phone")).length;this.paramsConfig.videoBehaviourParameters?.detectPerson&&r!==this.numPersonsSent&&(r===0?(this.handleAlert("no_person_detected","person_detection_on_stream"),this.numPersonsSent=r):r>1?(this.handleAlert("multiple_persons_detected","person_detection_on_stream"),this.numPersonsSent=r):(this.handleOk("person_ok","person_detection_on_stream"),this.numPersonsSent=r)),this.paramsConfig.videoBehaviourParameters?.detectCellPhone&&n!==this.numCellphoneSent&&(n>0?(this.handleAlert("cellphone_detected","mobile_detection_on_stream"),this.numCellphoneSent=n):(this.handleOk("cellphone_ok","mobile_detection_on_stream"),this.numCellphoneSent=n))}};var Cr=class{constructor(t){this.volume=null;this.animationFrameId=null;this.stream=t}async start(t={}){return new Promise((r,n)=>{try{let o=new AudioContext;this.analyser=o.createAnalyser();let i=o.createMediaStreamSource(this.stream);this.analyser.smoothingTimeConstant=.8,this.analyser.fftSize=1024,i.connect(this.analyser);let s=()=>{let a=new Uint8Array(this.analyser.frequencyBinCount);this.analyser.getByteFrequencyData(a);let l=a.reduce((h,d)=>h+d,0)/a.length;this.setVolume(l),t.setVolume&&t.setVolume(l),this.animationFrameId=requestAnimationFrame(s)};this.animationFrameId=requestAnimationFrame(s),r(!0)}catch(o){this.stop(),n(`Error: ${o}`)}})}stop(){this.animationFrameId!==null&&cancelAnimationFrame(this.animationFrameId)}getVolume(){return this.volume}setVolume(t){this.volume=t}};var sr=class{constructor(t,r,n,o,i){this.blobs=[];this.paramsConfig={audioBehaviourParameters:{recordingBitrate:128,noiseLimit:40},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:t=>{},proctoringType:"IMAGE",onChangeDevicesCallback:t=>{},onRealtimeAlertsCallback:t=>{}};this.videoOptions={width:640,height:480,minWidth:0,minHeight:0};this.blobsRTC=[];this.imageCount=0;this.filesToUpload=[];this.currentRetries=0;this.noiseWait=20;this.options=t,this.videoOptions=r,this.backend=o,this.backendToken=i,n&&(this.paramsConfig=n)}setProctoringId(t){this.proctoringId=t,this.proctoringId&&this.backend&&(this.upload=new ir(this.proctoringId,this.backend)),ca(t)}async initializeDetectors(){Hm(),(this.paramsConfig.videoBehaviourParameters?.detectPerson||this.paramsConfig.videoBehaviourParameters?.detectCellPhone)&&(this.objectDetection=new da({onRealtimeAlertsCallback:t=>this.options.onRealtimeAlertsCallback(t)},this.paramsConfig),await this.objectDetection.initializeDetector()),this.paramsConfig.videoBehaviourParameters?.detectFace&&(this.faceDetection=new Gn({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 bufferError(t){console.log("buffer error Camera Recorder params "+this.paramsConfig.videoBehaviourParameters);let r=this.paramsConfig.videoBehaviourParameters?.retryEnabled||!1,n=this.paramsConfig.videoBehaviourParameters?.maxRetries||3;r&&this.currentRetries<n?(await this.recordingStop(),await this.startRecording({retry:!0}),this.currentRetries++,this.options.onBufferSizeErrorCallback&&this.options.onBufferSizeErrorCallback(this.cameraStream)):this.options.onBufferSizeErrorCallback&&this.options.onBufferSizeErrorCallback()}async startRecording(t){(this.paramsConfig.videoBehaviourParameters?.detectPerson||this.paramsConfig.videoBehaviourParameters?.detectCellPhone||this.paramsConfig.videoBehaviourParameters?.detectFace)&&!t?.retry&&await this.initializeDetectors();let{cameraId:r,microphoneId:n,onBufferSizeErrorCallback:o}=this.options,i={audio:{deviceId:n},video:{deviceId:r,width:this.videoOptions.width,height:this.videoOptions.height,frameRate:15}};try{this.cameraStream=await navigator.mediaDevices.getUserMedia(i)}catch(m){throw m.toString()=="NotReadableError: Could not start video source"?"N\xE3o foi poss\xEDvel conectar a camera, ela pode estar sendo utilizada por outro programa":m}let{startRecording:s,stopRecording:a,pauseRecording:c,resumeRecording:l,recorderOptions:h,getBufferSize:d}=Yr(this.cameraStream,this.blobs,this.options.onBufferSizeError,m=>this.bufferError(m),!1);this.recordingStart=s,this.recordingStop=a,this.recordingPause=c,this.recordingResume=l,this.recorderOptions=h,this.getBufferSize=d,this.recordingStart();let b=this.cameraStream.getVideoTracks()[0].getSettings();if(this.videoOptions.minWidth>b.width||this.videoOptions.minHeight>b.height)throw Og;if(this.videoOptions.width!==b.width||this.videoOptions.height!==b.height)throw L.registerAnotherStream(this.proctoringId,`Maybe have another stream active
|
|
76
|
+
File size: ${o.size}`),new Error("Failed to upload to AWS")}}};var Ig="not_shared_first_screen",Pg="not_shared_screen",la="multiple_monitors_detected",Rg="proctoring_already_started",ha="proctoring_not_started";var Dg="another_stream_active",Og="stream_under_minimum_permitted",Bg="browser_not_supported",Mg="token_missing",Lg="credentials_missing";var Ug="spy_scan_api_not_found";var Fg="external_camera_not_started";var da=class extends qn{constructor(t,r,n="videoPreviewFrameDetection",o="liveViewFrameDetection"){super("ObjectDetector","https://storage.googleapis.com/mediapipe-models/object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite",t,r,n,o)}displayVideoDetections(t){for(let r of this.children)this.liveView.removeChild(r);this.children.splice(0);for(let r of t.detections){let n=window.innerWidth,o=window.innerHeight,i=this.video.offsetWidth,s=this.video.offsetHeight,a=i/n,c=s/o,l=i-r.boundingBox.width*a-r.boundingBox.originX*a,h=r.boundingBox.originY*c,d=(r.boundingBox.width-10)*a,p=r.boundingBox.height*c,b=document.createElement("p");b.innerText=r.categories[0].categoryName+" - with "+Math.round(parseFloat(r.categories[0].score)*100)+"% confidence.",b.style.right=l-20+"px",b.style.top=h+"px",b.style.width=d+"px";let m={zIndex:"2",position:"absolute",border:"1px dashed #fff"};Object.assign(b.style,{...m,margin:"0",fontSize:"9px",paddingBottom:"5px",paddingTop:"5px",color:"#fff",backgroundColor:"#007f8b"});let f=document.createElement("div");f.setAttribute("class","highlighter"),f.style.right=l-20+"px",f.style.top=h+"px",f.style.width=d+"px",f.style.height=p-20+"px",Object.assign(f.style,{...m,zIndex:"1",background:"rgba(0, 255, 0, 0.25)"}),this.liveView.appendChild(f),this.liveView.appendChild(b),this.children.push(f),this.children.push(b)}}verify(t){let r=t.detections.filter(o=>o.categories.some(i=>i.categoryName==="person")).length,n=t.detections.filter(o=>o.categories.some(i=>i.categoryName==="cell phone")).length;this.paramsConfig.videoBehaviourParameters?.detectPerson&&r!==this.numPersonsSent&&(r===0?(this.handleAlert("no_person_detected","person_detection_on_stream"),this.numPersonsSent=r):r>1?(this.handleAlert("multiple_persons_detected","person_detection_on_stream"),this.numPersonsSent=r):(this.handleOk("person_ok","person_detection_on_stream"),this.numPersonsSent=r)),this.paramsConfig.videoBehaviourParameters?.detectCellPhone&&n!==this.numCellphoneSent&&(n>0?(this.handleAlert("cellphone_detected","mobile_detection_on_stream"),this.numCellphoneSent=n):(this.handleOk("cellphone_ok","mobile_detection_on_stream"),this.numCellphoneSent=n))}};var Cr=class{constructor(t){this.volume=null;this.animationFrameId=null;this.stream=t}async start(t={}){return new Promise((r,n)=>{try{let o=new AudioContext;this.analyser=o.createAnalyser();let i=o.createMediaStreamSource(this.stream);this.analyser.smoothingTimeConstant=.8,this.analyser.fftSize=1024,i.connect(this.analyser);let s=()=>{let a=new Uint8Array(this.analyser.frequencyBinCount);this.analyser.getByteFrequencyData(a);let l=a.reduce((h,d)=>h+d,0)/a.length;this.setVolume(l),t.setVolume&&t.setVolume(l),this.animationFrameId=requestAnimationFrame(s)};this.animationFrameId=requestAnimationFrame(s),r(!0)}catch(o){this.stop(),n(`Error: ${o}`)}})}stop(){this.animationFrameId!==null&&cancelAnimationFrame(this.animationFrameId)}getVolume(){return this.volume}setVolume(t){this.volume=t}};var sr=class{constructor(t,r,n,o,i){this.blobs=[];this.paramsConfig={audioBehaviourParameters:{recordingBitrate:128,noiseLimit:40},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:t=>{},proctoringType:"IMAGE",onChangeDevicesCallback:t=>{},onRealtimeAlertsCallback:t=>{}};this.videoOptions={width:640,height:480,minWidth:0,minHeight:0};this.blobsRTC=[];this.imageCount=0;this.filesToUpload=[];this.currentRetries=0;this.noiseWait=20;this.options=t,this.videoOptions=r,this.backend=o,this.backendToken=i,n&&(this.paramsConfig=n)}setProctoringId(t){this.proctoringId=t,this.proctoringId&&this.backend&&(this.upload=new ir(this.proctoringId,this.backend)),ca(t)}async initializeDetectors(){Hm(),(this.paramsConfig.videoBehaviourParameters?.detectPerson||this.paramsConfig.videoBehaviourParameters?.detectCellPhone)&&(this.objectDetection=new da({onRealtimeAlertsCallback:t=>this.options.onRealtimeAlertsCallback(t)},this.paramsConfig),await this.objectDetection.initializeDetector()),this.paramsConfig.videoBehaviourParameters?.detectFace&&(this.faceDetection=new Gn({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 bufferError(t){console.log("buffer error Camera Recorder params "+this.paramsConfig.videoBehaviourParameters);let r=this.paramsConfig.videoBehaviourParameters?.retryEnabled||!1,n=this.paramsConfig.videoBehaviourParameters?.maxRetries||3;r&&this.currentRetries<n?(await this.recordingStop(),await this.startRecording({retry:!0}),this.currentRetries++,this.options.onBufferSizeErrorCallback&&this.options.onBufferSizeErrorCallback(this.cameraStream)):this.options.onBufferSizeErrorCallback&&this.options.onBufferSizeErrorCallback()}async startRecording(t){(this.paramsConfig.videoBehaviourParameters?.detectPerson||this.paramsConfig.videoBehaviourParameters?.detectCellPhone||this.paramsConfig.videoBehaviourParameters?.detectFace)&&!t?.retry&&await this.initializeDetectors();let{cameraId:r,microphoneId:n,onBufferSizeErrorCallback:o}=this.options,i={audio:{deviceId:n},video:{deviceId:r,width:this.videoOptions.width,height:this.videoOptions.height,frameRate:15}};try{this.cameraStream=await navigator.mediaDevices.getUserMedia(i)}catch(m){throw m.toString()=="NotReadableError: Could not start video source"?"N\xE3o foi poss\xEDvel conectar a camera, ela pode estar sendo utilizada por outro programa":m}let{startRecording:s,stopRecording:a,pauseRecording:c,resumeRecording:l,recorderOptions:h,getBufferSize:d}=Yr(this.cameraStream,this.blobs,this.options.onBufferSizeError,m=>this.bufferError(m),!1);this.recordingStart=s,this.recordingStop=a,this.recordingPause=c,this.recordingResume=l,this.recorderOptions=h,this.getBufferSize=d,this.recordingStart();let b=this.cameraStream.getVideoTracks()[0].getSettings();if(console.log("settings -> ",b.width,b.height),console.log("videoOptions -> ",this.videoOptions.width,this.videoOptions.height),console.log("minWidth -> ",this.videoOptions.minWidth),console.log("minHeight -> ",this.videoOptions.minHeight),this.videoOptions.minWidth>b.width||this.videoOptions.minHeight>b.height)throw Og;if(this.videoOptions.width!==b.width||this.videoOptions.height!==b.height)throw L.registerAnotherStream(this.proctoringId,`Maybe have another stream active
|
|
77
77
|
Video Options: ${JSON.stringify(this.videoOptions,null,2)}
|
|
78
78
|
Setting: ${JSON.stringify(b,null,2)}`),Dg;this.paramsConfig.imageBehaviourParameters?.useUploadImage&&this.options.proctoringType=="IMAGE"&&this.photoShotsCycle(),this.paramsConfig.videoBehaviourParameters?.detectFace&&await this.faceDetection.enableCam(this.cameraStream),(this.paramsConfig.videoBehaviourParameters?.detectPerson||this.paramsConfig.videoBehaviourParameters?.detectCellPhone)&&await this.objectDetection.enableCam(this.cameraStream),this.filesToUpload=[],this.options.proctoringType=="REALTIME"&&this.captureFrame()}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 n=0;n<t;n++){if(n==t-1&&this.filesToUpload[0]){let o=this.filesToUpload[0].name.replace(".jpg","_realtime.jpg"),i=new File([this.filesToUpload[0]],o,{type:"image/jpeg"});this.filesToUpload[0]=i}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,n=!1;this.imageInterval=setInterval(async()=>{this.canvas.getContext("2d").drawImage(this.video,0,0,this.canvas.width,this.canvas.height);let o=this.canvas.toDataURL("image/jpeg");if(this.proctoringId==null)return;n==!1&&r>0&&(n=!0,this.sendFrame());let i=`${this.proctoringId}_${this.imageCount+1}.jpg`;(this.imageCount+1)%r==0&&(i=`${this.proctoringId}_${this.imageCount+1}_realtime.jpg`),t=await this.getFile(o,i,"image/jpeg"),t&&t.size>10&&r>0&&(this.filesToUpload.push(t),this.imageCount++)},1e3)}sendFrame(){let t=this.paramsConfig.imageBehaviourParameters.uploadInterval,r=!1,n=0;this.sendFrameInterval=setInterval(async()=>{if(this.upload&&this.backendToken&&!r){n=0;let o=0,i=this.filesToUpload.length;for(;o<i&&(r=!0,this.filesToUpload.length!=0);)(await this.upload.uploadImages({file:this.filesToUpload[0]},this.backendToken,t)).uploaded==!0?(await this.filesToUpload.shift(),o++):console.log("erro no upload: "+this.filesToUpload[0].name);r=!1}else if(r&&(n++,n==3)){n=0;let o=this.videoOptions.width/2,i=this.videoOptions.height/2;o<320&&(o=320),i<180&&(i=180),this.canvas.width=o,this.canvas.height=i}},t*1e3)}download(t){let r=URL.createObjectURL(t),n=document.createElement("a");document.body.appendChild(n),n.style.display="none",n.href=r,n.download=t.name,n.click(),window.URL.revokeObjectURL(r)}async saveOnSession(t){this.blobs!=null&&L.registerSaveOnSession(this.proctoringId,`Blobs Length: ${this.blobs.length} Buffer Size: ${this.getBufferSize()} `);let r=this.cameraStream.getVideoTracks()[0].getSettings(),n=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
|
|
79
79
|
Sample Rate: ${n.sampleRate}
|
|
@@ -322,6 +322,6 @@ Upload Services: ${n}`,this.serviceType),bi()!=="1.0.0.0"&&(r=new no(this.procto
|
|
|
322
322
|
Upload Services: ${n}
|
|
323
323
|
Upload backup for Safe Browser`,this.serviceType)}))}),L.registerUpload(this.proctoringSession.id,!0,`upload success
|
|
324
324
|
|
|
325
|
-
Upload Services: ${n}`,this.serviceType)),this.proctoringSession.alerts.length>0&&await this.backend.saveAlerts(this.context,this.proctoringSession).catch(i=>{L.registerFinish(this.proctoringSession.id,!1,"save-screen error: "+i)}),await this.backend.finishAndSendUrls(this.context,this.sessionOptions).then(()=>{L.registerFinish(this.proctoringSession.id,!0,"")}).catch(i=>{L.registerFinish(this.proctoringSession.id,!1,"finish error: "+i)}),this.appChecker){let i=this.appChecker.getExternalCameraSessionId();i!=null&&await this.backend.externalCameraFinish(i)}this.state="Stop"}catch(r){throw await this.cancel(),L.registerFinish(this.proctoringId,!1,`Token: ${this.context.token}
|
|
325
|
+
Upload Services: ${n}`,this.serviceType)),this.proctoringSession.alerts.length>0&&await this.backend.saveAlerts(this.context,this.proctoringSession).catch(i=>{L.registerFinish(this.proctoringSession.id,!1,"save-screen error: "+i)}),await this.backend.finishAndSendUrls(this.context,this.sessionOptions).then(()=>{L.registerFinish(this.proctoringSession.id,!0,"")}).catch(i=>{L.registerFinish(this.proctoringSession.id,!1,"finish error: "+i)}),this.appChecker){let i=this.appChecker.getExternalCameraSessionId();console.log("externalSessionId -> ",i),i!="null"&&await this.backend.externalCameraFinish(i)}this.state="Stop"}catch(r){throw await this.cancel(),L.registerFinish(this.proctoringId,!1,`Token: ${this.context.token}
|
|
326
326
|
Error: `+r),this.state="Stop",r}}async verifyMultipleMonitors(t){if(!t.allowMultipleMonitors&&await Gi())throw L.registerError(this.proctoringId,"Multiplas telas detectadas!"),la}async verifyBrowser(){let t=await q0();if(t!=="chrome"&&t!=="firefox")throw L.registerBrowserNotSupported(this.proctoringId,`Browser n\xE3o suportado:
|
|
327
327
|
Tentativa utilizando o browser ${t}`),Bg}async initConfig(t){try{let r=await this.backend.getParamsConfig(this.context);this.paramsConfig={...this.paramsConfig,...r,audioBehaviourParameters:{...this.paramsConfig.audioBehaviourParameters,...r.audioBehaviourParameters},imageBehaviourParameters:{...this.paramsConfig.imageBehaviourParameters,...r.imageBehaviourParameters},videoBehaviourParameters:{...this.paramsConfig.videoBehaviourParameters,...r.videoBehaviourParameters}},t&&(this.geolocation=await G0().then(n=>n).catch(n=>{throw n.message})),Tg(this.backend),this.sessionOptions?.useSpyScan&&(this.spyCam=new eo(this.context,{onRealtimeAlertsCallback:n=>this.onRealtimeAlertsCallback(n)}))}catch(r){throw this.proctoringId&&L.registerError(this.proctoringId,"Erro no initConfig!"),await this.cancel(),r}}async getServerDate(){let t=await this.backend.getServerHour(this.context.token).catch(n=>{L.registerError(this.proctoringId,"N\xE3o foi poss\xEDvel requisitar a data do servidor!")});return t?new Date(t.toString()):new Date}async pause(){if(this.state!=="Recording")throw L.registerError(this.proctoringId,"Proctoring n\xE3o iniciado!"),ha;await this.recorder.stopAll(),await this.recorder.saveAllOnSession(),await this.repository.save(this.proctoringSession),this.state="Paused"}async resume(){if(this.state!="Paused")throw ha;return await this.verifyBrowser(),await this.verifyMultipleMonitors(this.sessionOptions),await this.recorder.startAll(),this.proctoringSession.recordings=[],await this.repository.save(this.proctoringSession),this.state="Recording",{cameraStream:this.allRecorders.cameraRecorder.cameraStream,_screenStream:this.allRecorders.screenRecorder?.screenStream}}async startChallenge(t){if(!this.sessionOptions.useChallenge)throw new Error("useChallenge is set as false on start method");await this.extensionEasycatcher.checkExtensionInstalled().catch(n=>{throw new Error("EasyCatcher Extension is not installed")}),this.extensionEasycatcher.start();let r=Date.now()-this.sessionStartTime;await this.backend.startChallenge({proctoringId:this.proctoringId,templateId:t,start:r}).then(n=>{console.log(n),this.challengeId=n.id}).catch(n=>{throw L.registerError(this.proctoringId,"N\xE3o foi poss\xEDvel iniciar desafio!"),n}),this.isChallengeRunning=!0}async stopChallenge(){if(!this.isChallengeRunning)throw new Error("Challenge not started");try{let t=await this.extensionEasycatcher.getSessionData(),r=Date.now()-this.sessionStartTime;await this.backend.stopChallenge(this.challengeId,{end:r,data:t}).catch(n=>{L.registerError(this.proctoringId,"N\xE3o foi poss\xEDvel finalizar o desafio no backend!")}),this.isChallengeRunning=!1}catch(t){L.registerError(this.proctoringId,"Erro ao recuperar dados da extens\xE3o: "+t.message)}}};var Lc=class e{static{this.isModalOpen=!1}constructor(t){this.backend=new ft({type:t?.type||"prod",token:t.token})}async signInTerms(){if(e.isModalOpen)return Promise.reject();e.isModalOpen=!0;try{let t=await this.openModal();return new Promise(r=>{r(t)})}catch(t){return this.closeModal(),Promise.reject(t)}}openModal(){return new Promise((t,r)=>{let n=document.createElement("div");n.setAttribute("id","signTermModal");let o={backgroundColor:"rgba(0,0,0,0.4)",zIndex:"1000",position:"fixed",top:"0",left:"0",height:"100vh",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"};this.applyStyles(n,o);let i=document.createElement("div"),s={backgroundColor:"#fff",zIndex:"1001",width:"850px",maxHeight:"95%",borderRadius:"10px",display:"flex",flexDirection:"column",alignItems:"center"};this.applyStyles(i,s);let a=document.createElement("h3");a.innerText="Termo de consentimento para coleta e uso de dados";let c={color:"rgba(0, 0, 0, .7)",fontWeight:"bold",fontSize:"20px",marginBottom:"15px",padding:"20px 0px",borderBottom:"2px solid rgba(0, 0, 0, .1)",width:"100%",textAlign:"center"};this.applyStyles(a,c),i.appendChild(a);let l=document.createElement("iframe"),h="https://docs.google.com/document/u/3/d/e/2PACX-1vRMgrLhDLyDP8BHmotfPDpwAFaDHqK-mA4eBJ0Cy1mDdvHcWLsx47H4otII_4qi4rhtSf6B0OO97e9c/pub";this.backend.signTermUrl().then(se=>{if(!se)throw new Error("N\xE3o foi poss\xEDvel obter o termo de consentimento");l.setAttribute("src",se)}).catch(()=>{l.setAttribute("src",h)});let d={width:"100%",height:"500px",border:"1px solid rgba(0, 0, 0, .1)",margin:"20px",borderRadius:"5px"};this.applyStyles(l,d),i.appendChild(l);let p=document.createElement("div"),b=document.createElement("input");b.setAttribute("type","checkbox"),b.setAttribute("id","termsCheckbox");let m=document.createElement("label");m.setAttribute("for","termsCheckbox"),m.innerText="Li e aceito os termos e condi\xE7\xF5es";let f={display:"flex",alignItems:"center",gap:"10px",margin:"20px",width:"100%",paddingLeft:"20px"};this.applyStyles(p,f),p.appendChild(b),p.appendChild(m),i.appendChild(p);let y=document.createElement("div"),w={width:"100%",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"2px solid rgba(0, 0, 0, .1)"};this.applyStyles(y,w);let _=document.createElement("button");_.innerText="Cancelar";let x={width:"100%",height:"70px",backgroundColor:"#FFF",border:"none",color:"rgba(0, 0, 0, .7)",fontWeight:"bold",borderRadius:"10px",paddingTop:"5px",paddingBottom:"5px"};this.applyStyles(_,x),_.addEventListener("click",()=>{this.closeModal(),t(!1)});let B=document.createElement("span"),O={width:"3px",height:"70px",margin:"0px 2px",background:"rgba(0, 0, 0, .1)"};this.applyStyles(B,O);let R=document.createElement("button");R.innerText="Continuar",R.setAttribute("id","confirmBtn");let ue={width:"100%",height:"70px",backgroundColor:"#FFF",border:"none",color:"rgba(0, 0, 0, .7)",fontWeight:"bold",borderRadius:"10px",paddingTop:"5px",paddingBottom:"5px",disabled:!0,cursor:"not-allowed"};this.applyStyles(R,ue),R.disabled=!0,R.addEventListener("click",()=>{this.closeModal(),this.backend.signTerm().then(()=>{t(!0)})}),b.addEventListener("change",se=>{R.disabled=!se.target.checked,se.target.checked?(R.style.color="#007bff",R.style.cursor="pointer"):(R.style.color="rgba(0, 0, 0, .7)",R.style.cursor="not-allowed")}),y.appendChild(_),y.appendChild(B),y.appendChild(R),i.appendChild(y),n.appendChild(i),document.body.appendChild(n)})}async closeModal(){e.isModalOpen=!1,document.querySelector("#signTermModal")?.remove()}applyStyles(t,r){for(let[n,o]of Object.entries(r))t.style[n]=o}};function Eu(e,t="prod"){e.showConsole||(console.log=()=>{},console.warn=()=>{},console.error=()=>{});let r={type:t,clientId:e.clientId,examId:e.examId,token:e.token,credentials:e.credentials,showConsole:e.showConsole},n=new Mc(r),o=new pa(r),i=new Lc(r),s=new to,a=n.login.bind(n),c=n.start.bind(n),l=async Oi=>{let hr=o.getDeviceCheckResult();return hr&&n.setDeviceCheckData(hr),c(Oi)},h=n.finish.bind(n),d=n.startChallenge.bind(n),p=n.stopChallenge.bind(n),b=n.pause.bind(n),m=n.resume.bind(n),f=n.setOnFocusCallback.bind(n),y=n.setOnLostFocusCallback.bind(n),w=n.onChangeDevices.bind(n),_=n.setOnBufferSizeErrorCallback.bind(n),x=n.setOnStopSharingScreenCallback.bind(n),B=n.onRealtimeAlerts.bind(n),O=i.signInTerms.bind(i),R=o.checkDevices.bind(o),ue=n.appChecker.checkExternalCamera.bind(n.appChecker),se=n.appChecker.startSession.bind(n.appChecker),jr=n.appChecker.takePicture.bind(n.appChecker),Ri=n.appChecker.goToPositionGuide.bind(n.appChecker),Vr=n.appChecker.startTransmission.bind(n.appChecker),pn=o.runCheckDevicesFlow.bind(o),fn=o.changeSelectedDevice.bind(o),Di=s.takePicture.bind(s);return{login:a,start:l,finish:h,startChallenge:d,stopChallenge:p,onFocus:f,onLostFocus:y,onChangeDevices:w,onBufferSizeError:_,onRealtimeAlerts:B,checkDevices:R,runCheckDevicesFlow:pn,changeSelectedDevice:fn,capturePhoto:Di,enumarateDevices:St,checkPermissions:qi,checkIfhasMultipleMonitors:Gi,onStopSharingScreen:x,signInTerms:O,checkExternalCamera:ue,startExternalCameraSession:se,takeExternalCameraPicture:jr,goToExternalCameraPositionStep:Ri,startExternalCameraTransmission:Vr}}typeof window<"u"&&(window.useProctoring=Eu);})();
|