easyproctor-hml 2.5.36 → 2.5.37
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 +17 -13
- package/index.js +17 -13
- package/package.json +1 -1
- package/proctoring/proctoring.d.ts +1 -0
- package/unpkg/easyproctor.min.js +1 -1
package/esm/index.js
CHANGED
|
@@ -22386,7 +22386,8 @@ var Proctoring = class {
|
|
|
22386
22386
|
this.onChangeDevicesCallback = (devices) => {
|
|
22387
22387
|
return;
|
|
22388
22388
|
};
|
|
22389
|
-
this.onRealtimeAlertsCallback = (response) => {
|
|
22389
|
+
this.onRealtimeAlertsCallback = async (response) => {
|
|
22390
|
+
await this.internalOnRealtimeAlerts(response);
|
|
22390
22391
|
return;
|
|
22391
22392
|
};
|
|
22392
22393
|
this.onBufferSizeErrorCallback = (cameraStream) => {
|
|
@@ -22524,23 +22525,26 @@ var Proctoring = class {
|
|
|
22524
22525
|
};
|
|
22525
22526
|
await verifyFace(1);
|
|
22526
22527
|
}
|
|
22528
|
+
async internalOnRealtimeAlerts(response) {
|
|
22529
|
+
if (this.sessionOptions.proctoringType === "REALTIME" && (response.type === "face_detection_on_stream" || response.type === "person_detection_on_stream" || response.type === "lost_focus" || response.type === "focus")) {
|
|
22530
|
+
if (response.status === "ALERT") {
|
|
22531
|
+
await this.backend.startRealtimeAlert({
|
|
22532
|
+
proctoringId: this.proctoringId,
|
|
22533
|
+
begin: response.begin,
|
|
22534
|
+
end: response.end,
|
|
22535
|
+
alert: this.convertRealtimeCategoryToAlertCategory(response.category)
|
|
22536
|
+
});
|
|
22537
|
+
} else if (response.status === "OK") {
|
|
22538
|
+
await this.stopRealtimeAlert(response);
|
|
22539
|
+
}
|
|
22540
|
+
}
|
|
22541
|
+
}
|
|
22527
22542
|
async onRealtimeAlerts(options = {}) {
|
|
22528
22543
|
this.setOnLostFocusAlertRecorderCallback();
|
|
22529
22544
|
this.setOnFocusAlertRecorderCallback();
|
|
22530
22545
|
this.onRealtimeAlertsCallback = async (response) => {
|
|
22546
|
+
await this.internalOnRealtimeAlerts(response);
|
|
22531
22547
|
options.data && options.data(response);
|
|
22532
|
-
if (this.sessionOptions.proctoringType === "REALTIME" && (response.type === "face_detection_on_stream" || response.type === "person_detection_on_stream" || response.type === "lost_focus" || response.type === "focus")) {
|
|
22533
|
-
if (response.status === "ALERT") {
|
|
22534
|
-
await this.backend.startRealtimeAlert({
|
|
22535
|
-
proctoringId: this.proctoringId,
|
|
22536
|
-
begin: response.begin,
|
|
22537
|
-
end: response.end,
|
|
22538
|
-
alert: this.convertRealtimeCategoryToAlertCategory(response.category)
|
|
22539
|
-
});
|
|
22540
|
-
} else if (response.status === "OK") {
|
|
22541
|
-
await this.stopRealtimeAlert(response);
|
|
22542
|
-
}
|
|
22543
|
-
}
|
|
22544
22548
|
};
|
|
22545
22549
|
}
|
|
22546
22550
|
setOnBufferSizeErrorCallback(cb) {
|
package/index.js
CHANGED
|
@@ -37635,7 +37635,8 @@ var Proctoring = class {
|
|
|
37635
37635
|
this.onChangeDevicesCallback = (devices) => {
|
|
37636
37636
|
return;
|
|
37637
37637
|
};
|
|
37638
|
-
this.onRealtimeAlertsCallback = (response) => {
|
|
37638
|
+
this.onRealtimeAlertsCallback = async (response) => {
|
|
37639
|
+
await this.internalOnRealtimeAlerts(response);
|
|
37639
37640
|
return;
|
|
37640
37641
|
};
|
|
37641
37642
|
this.onBufferSizeErrorCallback = (cameraStream) => {
|
|
@@ -37773,23 +37774,26 @@ var Proctoring = class {
|
|
|
37773
37774
|
};
|
|
37774
37775
|
await verifyFace(1);
|
|
37775
37776
|
}
|
|
37777
|
+
async internalOnRealtimeAlerts(response) {
|
|
37778
|
+
if (this.sessionOptions.proctoringType === "REALTIME" && (response.type === "face_detection_on_stream" || response.type === "person_detection_on_stream" || response.type === "lost_focus" || response.type === "focus")) {
|
|
37779
|
+
if (response.status === "ALERT") {
|
|
37780
|
+
await this.backend.startRealtimeAlert({
|
|
37781
|
+
proctoringId: this.proctoringId,
|
|
37782
|
+
begin: response.begin,
|
|
37783
|
+
end: response.end,
|
|
37784
|
+
alert: this.convertRealtimeCategoryToAlertCategory(response.category)
|
|
37785
|
+
});
|
|
37786
|
+
} else if (response.status === "OK") {
|
|
37787
|
+
await this.stopRealtimeAlert(response);
|
|
37788
|
+
}
|
|
37789
|
+
}
|
|
37790
|
+
}
|
|
37776
37791
|
async onRealtimeAlerts(options = {}) {
|
|
37777
37792
|
this.setOnLostFocusAlertRecorderCallback();
|
|
37778
37793
|
this.setOnFocusAlertRecorderCallback();
|
|
37779
37794
|
this.onRealtimeAlertsCallback = async (response) => {
|
|
37795
|
+
await this.internalOnRealtimeAlerts(response);
|
|
37780
37796
|
options.data && options.data(response);
|
|
37781
|
-
if (this.sessionOptions.proctoringType === "REALTIME" && (response.type === "face_detection_on_stream" || response.type === "person_detection_on_stream" || response.type === "lost_focus" || response.type === "focus")) {
|
|
37782
|
-
if (response.status === "ALERT") {
|
|
37783
|
-
await this.backend.startRealtimeAlert({
|
|
37784
|
-
proctoringId: this.proctoringId,
|
|
37785
|
-
begin: response.begin,
|
|
37786
|
-
end: response.end,
|
|
37787
|
-
alert: this.convertRealtimeCategoryToAlertCategory(response.category)
|
|
37788
|
-
});
|
|
37789
|
-
} else if (response.status === "OK") {
|
|
37790
|
-
await this.stopRealtimeAlert(response);
|
|
37791
|
-
}
|
|
37792
|
-
}
|
|
37793
37797
|
};
|
|
37794
37798
|
}
|
|
37795
37799
|
setOnBufferSizeErrorCallback(cb) {
|
package/package.json
CHANGED
|
@@ -73,6 +73,7 @@ export declare class Proctoring {
|
|
|
73
73
|
private convertRealtimeTypeToWarningType;
|
|
74
74
|
private stopRealtimeAlert;
|
|
75
75
|
private onRealtimeAlertsCallback;
|
|
76
|
+
private internalOnRealtimeAlerts;
|
|
76
77
|
onRealtimeAlerts(options?: ProctoringRealtimeAlertsOptions): Promise<void>;
|
|
77
78
|
private onBufferSizeErrorCallback;
|
|
78
79
|
setOnBufferSizeErrorCallback(cb: (cameraStream?: any) => void): void;
|
package/unpkg/easyproctor.min.js
CHANGED
|
@@ -503,7 +503,7 @@ registerProcessor("audio-processor", AudioProcessor);
|
|
|
503
503
|
<circle cx="10" cy="10" r="9" stroke="#16A34A" stroke-width="2" fill="none"/>
|
|
504
504
|
<path d="M6 10L9 13L14 7" stroke="#16A34A" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
505
505
|
</svg>
|
|
506
|
-
`,this.applyStyles(_,{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",flexShrink:"0"});let E=document.createElement("span");E.innerText=f,b.appendChild(_),b.appendChild(E),c.appendChild(b)}),s.appendChild(c);let h=document.createElement("button");h.innerText="Capturar foto",h.id="position-capture-button",this.applyStyles(h,{marginTop:"10px",padding:"12px 24px",fontSize:"14px",fontWeight:"bold",color:"white",backgroundColor:"#16A34A",border:"none",borderRadius:"6px",cursor:"pointer",transition:"background-color 0.2s",alignSelf:"flex-start"}),h.onclick=()=>{if(this.connection){let f=document.getElementById("photo-message");f&&(f.innerText="N\xE3o saia da posi\xE7\xE3o atual, estamos validando o ambiente..."),n.style.display="none",this.takePicture(!0,()=>{}),h.disabled=!0,this.applyStyles(h,{backgroundColor:"#9CA3AF",cursor:"not-allowed"})}},s.appendChild(h),i.appendChild(s),t.appendChild(i);let d=document.createElement("div");this.applyStyles(d,{marginTop:"10px",fontSize:"13px",color:"#666"});let m=document.createElement("span");m.innerText="Dica: ",m.style.fontWeight="bold";let p=document.createElement("span");p.innerText="mantenha o celular est\xE1vel durante todo o processo.",d.appendChild(m),d.appendChild(p),t.appendChild(d);let g=document.getElementById("external-camera-continue");g.disabled=!0,this.applyStyles(g,{color:"#ccc",cursor:"not-allowed"})}renderImageStep(t){t.innerHTML="";let r=document.createElement("img");r.src="data:image/jpeg;base64,"+this.capturePhotoUrl,this.applyStyles(r,{maxWidth:"100%",maxHeight:"300px",borderRadius:"8px"}),t.appendChild(r);let n=document.createElement("photo-message");n.id="photo-message",n.innerText="Verifica\xE7\xE3o finalizada com sucesso.",this.applyStyles(n,{textAlign:"center",color:"#555",marginTop:"20px"}),t.appendChild(n);let i=document.getElementById("external-camera-continue");i.disabled=!1,i.innerText="Concluir",this.applyStyles(i,{width:"100%",height:"70px",backgroundColor:"#FFF",border:"none",color:"rgba(0, 0, 0, .7)",fontWeight:"bold",borderRadius:"0 0 10px 0",cursor:"pointer",borderLeft:"2px solid rgba(0, 0, 0, .1)"}),i.onclick=()=>{this.closeCheckExternalCamera(),this.resolvePromise({result:!0})}}nextState(){this.renderCurrentStep()}async initializeWebSocketConnection(){let t=this.backend.getSocketUrl();this.connection=new as().withUrl(t,{accessTokenFactory:()=>this.context.token,transport:Ve.WebSockets,withCredentials:!1,skipNegotiation:!0}).withAutomaticReconnect().configureLogging(U.Information).build(),this.connection.on("ReceiveMessage",(r,n)=>{if(r!==this.externalSessionId){console.warn("Sess\xE3o diferente!");return}try{let o=wy[n];this.handleWebSocketMessage(o)}catch(i){console.error("Erro ao processar mensagem do WebSocket:",i)}}),this.connection.on("ReceiveAction",(r,n)=>{if(r!==this.externalSessionId){console.warn("Sess\xE3o diferente!");return}try{this.handleWebSocketAction(n)}catch(i){console.error("Erro ao processar mensagem do WebSocket:",i)}});try{await this.connection.start()}catch(r){throw console.error("Falha ao conectar ou entrar no grupo do SignalR: ",r),new Error("N\xE3o foi poss\xEDvel conectar ao servi\xE7o em tempo real.")}}handleWebSocketAction(t){let r=document.getElementById("position-capture-button"),n=document.getElementById("photo-message"),i=document.getElementById("photo-error-banner");switch(t.command){case"Capture_Error":r&&(this.applyStyles(r,{marginTop:"30px",padding:"12px 20px",fontSize:"16px",fontWeight:"bold",color:"white",backgroundColor:"#16A34A",border:"none",borderRadius:"8px",cursor:"pointer",transition:"background-color 0.2s"}),r.disabled=!1),n&&(n.innerText=""+t.message),i&&(i.style.display="flex"),this.waitingPositionValidation==!0&&this.onTakePictureCallback({photo:this.capturePhotoUrl,errorMessage:t.message,success:!1});break;case"CapturePhoto":this.capturePhotoUrl=""+t.message;let o=document.getElementById("photo-icon-container");if(o&&this.capturePhotoUrl&&this.capturePhotoUrl.trim()!==""){let s=document.getElementById("img-photo");s||(o.innerHTML="",s=document.createElement("img"),s.id="img-photo",this.applyStyles(s,{width:"100%",height:"100%",objectFit:"contain",objectPosition:"center",borderRadius:"8px",display:"block"}),o.appendChild(s));let a=this.capturePhotoUrl.startsWith("data:")?this.capturePhotoUrl:"data:image/jpeg;base64,"+this.capturePhotoUrl;s.src=a,s.onload=()=>{console.log("Image loaded successfully in icon container")},s.onerror=c=>{console.error("Error loading image:",c)}}this.waitingPositionValidation==!1&&this.onTakePictureCallback({photo:this.capturePhotoUrl});break;case"Check_Transmission":t.message=="Transmission_OK"&&(this.transmissionOk=!0);break;case"Cancel":this.closeCheckExternalCamera();break;case"EnvironmentAlert":this.onRealtimeAlertsCallback({status:"ALERT",description:t.message,type:"environment_alert"});break}}handleWebSocketMessage(t){switch(this.currentStep=t,t){case 1:this.currentStep===1&&(this.nextState(),this.onQrCodeReadedCallback(!0));break;case 2:this.nextState(),this.waitingPositionValidation==!0&&this.onTakePictureCallback({photo:this.capturePhotoUrl,success:!0});break;case 3:this.closeCheckExternalCamera();break;case 9:console.error("Erro recebido do processo de c\xE2mera externa."),this.closeCheckExternalCamera(),this.resolvePromise({result:!1});break}}async disconnectWebSocket(){if(this.connection)try{await this.connection.stop()}catch(t){console.error("Erro ao desconectar do SignalR:",t)}finally{this.connection=null}}closeCheckExternalCamera(){e.isModalOpen=!1,this.disconnectWebSocket(),document.querySelector("#externalCameraCheck")?.remove()}applyStyles(t,r){for(let n in r)t.style[n]=r[n]}};var cl=class{constructor(t){this.context=t;this.deviceData=null;this.paramsConfig={audioBehaviourParameters:{recordingBitrate:128,noiseLimit:40},imageBehaviourParameters:{useUploadImage:!0,uploadInterval:20,saveVideo:!0},videoBehaviourParameters:{detectFace:!1,detectPerson:!1,detectCellPhone:!1,detectNoise:!1,detectSpeech:!1,realtimePackageSize:10,realtimeCaptureInterval:2}};this.proctoringId="";this.insights=void 0;this.state="Stop";this.serviceType="Upload";this.onStopSharingScreenCallback=()=>{};this.onLostFocusCallback=()=>{};this.onLostFocusAlertRecorderCallback=t=>{};this.onFocusCallback=()=>{};this.onFocusAlertRecorderCallback=t=>{};this.onChangeDevicesCallback=t=>{};this.onRealtimeAlertsCallback=t=>{};this.onBufferSizeErrorCallback=t=>{};this.backend=new nr({type:t.type||"prod",token:t.token}),this.repository=new rs("EasyProctorDb","exams2"),this.repositoryDevices=new rs("EasyProctorDbDevices","devices"),this.context.credentials?.cpf&&(this.auth=new Ic(this.context.credentials.cpf,this.backend)),this.appChecker=new al(this.context,r=>this.onRealtimeAlertsCallback(r))}setOnStopSharingScreenCallback(t){this.onStopSharingScreenCallback=async()=>{me.registerStopSharingScreen(this.proctoringId,"Stop sharing screen"),this.allRecorders?.alertRecorder?.addAlert({alert:34,type:3}),this.allRecorders?.screenRecorder?.stopRecording(),t()}}setOnLostFocusAlertRecorderCallback(){this.onLostFocusAlertRecorderCallback=async t=>{this.onLostFocusCallback&&this.onLostFocusCallback(),this.sessionOptions.proctoringType==="REALTIME"&&await this.onRealtimeAlertsCallback({type:"lost_focus",category:"lost_focus",description:"Perda de foco no exame",begin:t.begin,end:t.end,alert:25,status:"ALERT"})}}setOnFocusAlertRecorderCallback(){this.onFocusAlertRecorderCallback=async t=>{this.onFocusCallback&&this.onFocusCallback(),this.sessionOptions.proctoringType==="REALTIME"&&await this.onRealtimeAlertsCallback({type:"focus",category:"focus",description:"Retorno de foco no exame",begin:t.begin,end:t.end,alert:25,status:"OK"})}}async setOnLostFocusCallback(t){this.onLostFocusCallback=async()=>await t(),this.setOnLostFocusAlertRecorderCallback()}async setOnFocusCallback(t){this.onFocusCallback=async()=>await t(),this.setOnFocusAlertRecorderCallback()}async onChangeDevices(t={}){new Wa(this.repositoryDevices,this.proctoringId,this.sessionOptions,this.allRecorders).startRecording(t),this.onChangeDevicesCallback=n=>t.status&&t.status(n)}convertRealtimeCategoryToAlertCategory(t){switch(t){case"no_face_detected":return 1;case"multiple_faces_detected":return 2;case"multiple_persons_detected":return 28;case"no_person_detected":return 29;case"lost_focus":return 25;case"focus":return 25;default:return null}}convertRealtimeTypeToWarningType(t){switch(t){case"face_detection_on_stream":return 0;case"person_detection_on_stream":return 1;case"lost_focus":return 2;case"focus":return 2;default:return null}}async stopRealtimeAlert(t){let n=async i=>{if(!(i>3))try{var o=await this.backend.stopRealtimeAlert({proctoringId:this.proctoringId,begin:t.begin,end:t.end,warningCategoryEnum:this.convertRealtimeTypeToWarningType(t.type),alertImageBase64:t.description!=="face_stop"?await this.allRecorders.cameraRecorder.getCurrentImageBase64():"",retry:i<2});return o}catch(s){return console.log("error stopRealtimeAlert",s),n(i+1)}};await n(1)}async onRealtimeAlerts(t={}){this.setOnLostFocusAlertRecorderCallback(),this.setOnFocusAlertRecorderCallback(),this.onRealtimeAlertsCallback=async r=>{t.data&&t.data(r),this.sessionOptions.proctoringType==="REALTIME"&&(r.type==="face_detection_on_stream"||r.type==="person_detection_on_stream"||r.type==="lost_focus"||r.type==="focus")&&(r.status==="ALERT"?await this.backend.startRealtimeAlert({proctoringId:this.proctoringId,begin:r.begin,end:r.end,alert:this.convertRealtimeCategoryToAlertCategory(r.category)}):r.status==="OK"&&await this.stopRealtimeAlert(r))}}setOnBufferSizeErrorCallback(t){this.onBufferSizeErrorCallback=r=>t(r)}setDeviceCheckData(t){this.deviceData=t}async createRecorders(t=ir){this.onChangeDevices(),console.log("Creating recorders"),await this.recorder?.stopAll();let r=new Zr({cameraId:this.sessionOptions.cameraId,microphoneId:this.sessionOptions.microphoneId,onBufferSizeError:this.sessionOptions.onBufferSizeError,onBufferSizeErrorCallback:a=>this.onBufferSizeErrorCallback(a),proctoringType:this.sessionOptions.proctoringType,onChangeDevicesCallback:a=>this.onChangeDevicesCallback(a),onRealtimeAlertsCallback:a=>this.onRealtimeAlertsCallback(a)},{width:this.videoOptions.width,height:this.videoOptions.height,minWidth:this.videoOptions.minWidth,minHeight:this.videoOptions.minHeight},this.paramsConfig,this.backend,this.context.token),n=this.sessionOptions.captureScreen?new Tc({allowOnlyFirstMonitor:this.sessionOptions.allowOnlyFirstMonitor??!0,allowMultipleMonitors:this.sessionOptions.allowMultipleMonitors??!0,screenRecorderOptions:this.sessionOptions.screenRecorderOptions,onStopSharingScreenCallback:()=>this.onStopSharingScreenCallback(),onBufferSizeError:this.sessionOptions.onBufferSizeError,onBufferSizeErrorCallback:()=>this.onBufferSizeErrorCallback()}):void 0,i=new Ga({onFocusCallback:a=>this.onFocusAlertRecorderCallback(a),onLostFocusCallback:a=>this.onLostFocusAlertRecorderCallback(a),onRealtimeAlertCallback:a=>this.onRealtimeAlertsCallback(a)},t),o=new Ac(t,this.proctoringSession,this.paramsConfig,r,a=>this.onRealtimeAlertsCallback(a),this.backend,this.context.token),s=[r,o,i].filter(Boolean);return this.sessionOptions.proctoringType!="REALTIME"&&n&&s.push(n),this.recorder=new $a(this.proctoringSession,s),{cameraRecorder:r,screenRecorder:n,alertRecorder:i,noiseRecorder:o}}async login(){if(!this.context.credentials?.cpf)throw e0;this.context.token=await this.auth.login()}async start(t=ir,r={}){try{if(this.context.token===void 0)throw Qg;t.useChallenge&&(this.extensionEasycatcher=new Ha),this.extension=new Va,this.extension.addEventListener();let n=this.backend.selectBaseUrl(this.context.type),i=await ur();await this.repositoryDevices.save({...i,id:"devices"}),this.sessionOptions={...ir,...t},this.videoOptions=Ba(r),await this.initConfig(t.useGeolocation),await this.verifyBrowser(),this.sessionOptions.captureScreen&&await this.verifyMultipleMonitors(this.sessionOptions);try{t?.useSpyScan&&await this.spyCam.isAlive()}catch{throw t0}if(this.state!="Stop")throw Xg;this.state="Starting",await this.repository.hasSessions()&&await this.repository.clear(),this.proctoringSession=new Hn,this.allRecorders=await this.createRecorders(this.sessionOptions);let o=await this.backend.confirmStart({clientId:this.context.clientId,examId:this.context.examId,token:this.context.token},this.sessionOptions,this.geolocation?this.geolocation.coords.latitude:void 0,this.geolocation?this.geolocation.coords.longitude:void 0);this.proctoringId=o.id,me.registerDevicesChecked(this.proctoringId,!!this.deviceData,`Devices checked: ${JSON.stringify(this.deviceData)} | Devices List: ${JSON.stringify(i)}`);try{t?.useExternalCamera&&await this.appChecker.startTransmission(this.proctoringId)}catch{throw r0}this.allRecorders.cameraRecorder.setProctoringId(this.proctoringId),this.allRecorders.noiseRecorder.setProctoringId(this.proctoringId),this.proctoringSession.setProctoringId(this.proctoringId);try{console.log("Starting recorders"),await this.recorder.startAll()}catch(l){throw console.log("Starting recorders error:",l),l}t?.useSpyScan&&(this.spyCam.setProctoringId(this.proctoringId),this.spyCam.startCheckSpyCam(this.paramsConfig.spyScanInterval??5,{deviceType:3})),await this.repository.save(this.proctoringSession);let s={};for(let l in navigator)s[l]=navigator[l];me.registerStart(this.proctoringId,!0,`Version: ${ns()}
|
|
506
|
+
`,this.applyStyles(_,{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",flexShrink:"0"});let E=document.createElement("span");E.innerText=f,b.appendChild(_),b.appendChild(E),c.appendChild(b)}),s.appendChild(c);let h=document.createElement("button");h.innerText="Capturar foto",h.id="position-capture-button",this.applyStyles(h,{marginTop:"10px",padding:"12px 24px",fontSize:"14px",fontWeight:"bold",color:"white",backgroundColor:"#16A34A",border:"none",borderRadius:"6px",cursor:"pointer",transition:"background-color 0.2s",alignSelf:"flex-start"}),h.onclick=()=>{if(this.connection){let f=document.getElementById("photo-message");f&&(f.innerText="N\xE3o saia da posi\xE7\xE3o atual, estamos validando o ambiente..."),n.style.display="none",this.takePicture(!0,()=>{}),h.disabled=!0,this.applyStyles(h,{backgroundColor:"#9CA3AF",cursor:"not-allowed"})}},s.appendChild(h),i.appendChild(s),t.appendChild(i);let d=document.createElement("div");this.applyStyles(d,{marginTop:"10px",fontSize:"13px",color:"#666"});let m=document.createElement("span");m.innerText="Dica: ",m.style.fontWeight="bold";let p=document.createElement("span");p.innerText="mantenha o celular est\xE1vel durante todo o processo.",d.appendChild(m),d.appendChild(p),t.appendChild(d);let g=document.getElementById("external-camera-continue");g.disabled=!0,this.applyStyles(g,{color:"#ccc",cursor:"not-allowed"})}renderImageStep(t){t.innerHTML="";let r=document.createElement("img");r.src="data:image/jpeg;base64,"+this.capturePhotoUrl,this.applyStyles(r,{maxWidth:"100%",maxHeight:"300px",borderRadius:"8px"}),t.appendChild(r);let n=document.createElement("photo-message");n.id="photo-message",n.innerText="Verifica\xE7\xE3o finalizada com sucesso.",this.applyStyles(n,{textAlign:"center",color:"#555",marginTop:"20px"}),t.appendChild(n);let i=document.getElementById("external-camera-continue");i.disabled=!1,i.innerText="Concluir",this.applyStyles(i,{width:"100%",height:"70px",backgroundColor:"#FFF",border:"none",color:"rgba(0, 0, 0, .7)",fontWeight:"bold",borderRadius:"0 0 10px 0",cursor:"pointer",borderLeft:"2px solid rgba(0, 0, 0, .1)"}),i.onclick=()=>{this.closeCheckExternalCamera(),this.resolvePromise({result:!0})}}nextState(){this.renderCurrentStep()}async initializeWebSocketConnection(){let t=this.backend.getSocketUrl();this.connection=new as().withUrl(t,{accessTokenFactory:()=>this.context.token,transport:Ve.WebSockets,withCredentials:!1,skipNegotiation:!0}).withAutomaticReconnect().configureLogging(U.Information).build(),this.connection.on("ReceiveMessage",(r,n)=>{if(r!==this.externalSessionId){console.warn("Sess\xE3o diferente!");return}try{let o=wy[n];this.handleWebSocketMessage(o)}catch(i){console.error("Erro ao processar mensagem do WebSocket:",i)}}),this.connection.on("ReceiveAction",(r,n)=>{if(r!==this.externalSessionId){console.warn("Sess\xE3o diferente!");return}try{this.handleWebSocketAction(n)}catch(i){console.error("Erro ao processar mensagem do WebSocket:",i)}});try{await this.connection.start()}catch(r){throw console.error("Falha ao conectar ou entrar no grupo do SignalR: ",r),new Error("N\xE3o foi poss\xEDvel conectar ao servi\xE7o em tempo real.")}}handleWebSocketAction(t){let r=document.getElementById("position-capture-button"),n=document.getElementById("photo-message"),i=document.getElementById("photo-error-banner");switch(t.command){case"Capture_Error":r&&(this.applyStyles(r,{marginTop:"30px",padding:"12px 20px",fontSize:"16px",fontWeight:"bold",color:"white",backgroundColor:"#16A34A",border:"none",borderRadius:"8px",cursor:"pointer",transition:"background-color 0.2s"}),r.disabled=!1),n&&(n.innerText=""+t.message),i&&(i.style.display="flex"),this.waitingPositionValidation==!0&&this.onTakePictureCallback({photo:this.capturePhotoUrl,errorMessage:t.message,success:!1});break;case"CapturePhoto":this.capturePhotoUrl=""+t.message;let o=document.getElementById("photo-icon-container");if(o&&this.capturePhotoUrl&&this.capturePhotoUrl.trim()!==""){let s=document.getElementById("img-photo");s||(o.innerHTML="",s=document.createElement("img"),s.id="img-photo",this.applyStyles(s,{width:"100%",height:"100%",objectFit:"contain",objectPosition:"center",borderRadius:"8px",display:"block"}),o.appendChild(s));let a=this.capturePhotoUrl.startsWith("data:")?this.capturePhotoUrl:"data:image/jpeg;base64,"+this.capturePhotoUrl;s.src=a,s.onload=()=>{console.log("Image loaded successfully in icon container")},s.onerror=c=>{console.error("Error loading image:",c)}}this.waitingPositionValidation==!1&&this.onTakePictureCallback({photo:this.capturePhotoUrl});break;case"Check_Transmission":t.message=="Transmission_OK"&&(this.transmissionOk=!0);break;case"Cancel":this.closeCheckExternalCamera();break;case"EnvironmentAlert":this.onRealtimeAlertsCallback({status:"ALERT",description:t.message,type:"environment_alert"});break}}handleWebSocketMessage(t){switch(this.currentStep=t,t){case 1:this.currentStep===1&&(this.nextState(),this.onQrCodeReadedCallback(!0));break;case 2:this.nextState(),this.waitingPositionValidation==!0&&this.onTakePictureCallback({photo:this.capturePhotoUrl,success:!0});break;case 3:this.closeCheckExternalCamera();break;case 9:console.error("Erro recebido do processo de c\xE2mera externa."),this.closeCheckExternalCamera(),this.resolvePromise({result:!1});break}}async disconnectWebSocket(){if(this.connection)try{await this.connection.stop()}catch(t){console.error("Erro ao desconectar do SignalR:",t)}finally{this.connection=null}}closeCheckExternalCamera(){e.isModalOpen=!1,this.disconnectWebSocket(),document.querySelector("#externalCameraCheck")?.remove()}applyStyles(t,r){for(let n in r)t.style[n]=r[n]}};var cl=class{constructor(t){this.context=t;this.deviceData=null;this.paramsConfig={audioBehaviourParameters:{recordingBitrate:128,noiseLimit:40},imageBehaviourParameters:{useUploadImage:!0,uploadInterval:20,saveVideo:!0},videoBehaviourParameters:{detectFace:!1,detectPerson:!1,detectCellPhone:!1,detectNoise:!1,detectSpeech:!1,realtimePackageSize:10,realtimeCaptureInterval:2}};this.proctoringId="";this.insights=void 0;this.state="Stop";this.serviceType="Upload";this.onStopSharingScreenCallback=()=>{};this.onLostFocusCallback=()=>{};this.onLostFocusAlertRecorderCallback=t=>{};this.onFocusCallback=()=>{};this.onFocusAlertRecorderCallback=t=>{};this.onChangeDevicesCallback=t=>{};this.onRealtimeAlertsCallback=async t=>{await this.internalOnRealtimeAlerts(t)};this.onBufferSizeErrorCallback=t=>{};this.backend=new nr({type:t.type||"prod",token:t.token}),this.repository=new rs("EasyProctorDb","exams2"),this.repositoryDevices=new rs("EasyProctorDbDevices","devices"),this.context.credentials?.cpf&&(this.auth=new Ic(this.context.credentials.cpf,this.backend)),this.appChecker=new al(this.context,r=>this.onRealtimeAlertsCallback(r))}setOnStopSharingScreenCallback(t){this.onStopSharingScreenCallback=async()=>{me.registerStopSharingScreen(this.proctoringId,"Stop sharing screen"),this.allRecorders?.alertRecorder?.addAlert({alert:34,type:3}),this.allRecorders?.screenRecorder?.stopRecording(),t()}}setOnLostFocusAlertRecorderCallback(){this.onLostFocusAlertRecorderCallback=async t=>{this.onLostFocusCallback&&this.onLostFocusCallback(),this.sessionOptions.proctoringType==="REALTIME"&&await this.onRealtimeAlertsCallback({type:"lost_focus",category:"lost_focus",description:"Perda de foco no exame",begin:t.begin,end:t.end,alert:25,status:"ALERT"})}}setOnFocusAlertRecorderCallback(){this.onFocusAlertRecorderCallback=async t=>{this.onFocusCallback&&this.onFocusCallback(),this.sessionOptions.proctoringType==="REALTIME"&&await this.onRealtimeAlertsCallback({type:"focus",category:"focus",description:"Retorno de foco no exame",begin:t.begin,end:t.end,alert:25,status:"OK"})}}async setOnLostFocusCallback(t){this.onLostFocusCallback=async()=>await t(),this.setOnLostFocusAlertRecorderCallback()}async setOnFocusCallback(t){this.onFocusCallback=async()=>await t(),this.setOnFocusAlertRecorderCallback()}async onChangeDevices(t={}){new Wa(this.repositoryDevices,this.proctoringId,this.sessionOptions,this.allRecorders).startRecording(t),this.onChangeDevicesCallback=n=>t.status&&t.status(n)}convertRealtimeCategoryToAlertCategory(t){switch(t){case"no_face_detected":return 1;case"multiple_faces_detected":return 2;case"multiple_persons_detected":return 28;case"no_person_detected":return 29;case"lost_focus":return 25;case"focus":return 25;default:return null}}convertRealtimeTypeToWarningType(t){switch(t){case"face_detection_on_stream":return 0;case"person_detection_on_stream":return 1;case"lost_focus":return 2;case"focus":return 2;default:return null}}async stopRealtimeAlert(t){let n=async i=>{if(!(i>3))try{var o=await this.backend.stopRealtimeAlert({proctoringId:this.proctoringId,begin:t.begin,end:t.end,warningCategoryEnum:this.convertRealtimeTypeToWarningType(t.type),alertImageBase64:t.description!=="face_stop"?await this.allRecorders.cameraRecorder.getCurrentImageBase64():"",retry:i<2});return o}catch(s){return console.log("error stopRealtimeAlert",s),n(i+1)}};await n(1)}async internalOnRealtimeAlerts(t){this.sessionOptions.proctoringType==="REALTIME"&&(t.type==="face_detection_on_stream"||t.type==="person_detection_on_stream"||t.type==="lost_focus"||t.type==="focus")&&(t.status==="ALERT"?await this.backend.startRealtimeAlert({proctoringId:this.proctoringId,begin:t.begin,end:t.end,alert:this.convertRealtimeCategoryToAlertCategory(t.category)}):t.status==="OK"&&await this.stopRealtimeAlert(t))}async onRealtimeAlerts(t={}){this.setOnLostFocusAlertRecorderCallback(),this.setOnFocusAlertRecorderCallback(),this.onRealtimeAlertsCallback=async r=>{await this.internalOnRealtimeAlerts(r),t.data&&t.data(r)}}setOnBufferSizeErrorCallback(t){this.onBufferSizeErrorCallback=r=>t(r)}setDeviceCheckData(t){this.deviceData=t}async createRecorders(t=ir){this.onChangeDevices(),console.log("Creating recorders"),await this.recorder?.stopAll();let r=new Zr({cameraId:this.sessionOptions.cameraId,microphoneId:this.sessionOptions.microphoneId,onBufferSizeError:this.sessionOptions.onBufferSizeError,onBufferSizeErrorCallback:a=>this.onBufferSizeErrorCallback(a),proctoringType:this.sessionOptions.proctoringType,onChangeDevicesCallback:a=>this.onChangeDevicesCallback(a),onRealtimeAlertsCallback:a=>this.onRealtimeAlertsCallback(a)},{width:this.videoOptions.width,height:this.videoOptions.height,minWidth:this.videoOptions.minWidth,minHeight:this.videoOptions.minHeight},this.paramsConfig,this.backend,this.context.token),n=this.sessionOptions.captureScreen?new Tc({allowOnlyFirstMonitor:this.sessionOptions.allowOnlyFirstMonitor??!0,allowMultipleMonitors:this.sessionOptions.allowMultipleMonitors??!0,screenRecorderOptions:this.sessionOptions.screenRecorderOptions,onStopSharingScreenCallback:()=>this.onStopSharingScreenCallback(),onBufferSizeError:this.sessionOptions.onBufferSizeError,onBufferSizeErrorCallback:()=>this.onBufferSizeErrorCallback()}):void 0,i=new Ga({onFocusCallback:a=>this.onFocusAlertRecorderCallback(a),onLostFocusCallback:a=>this.onLostFocusAlertRecorderCallback(a),onRealtimeAlertCallback:a=>this.onRealtimeAlertsCallback(a)},t),o=new Ac(t,this.proctoringSession,this.paramsConfig,r,a=>this.onRealtimeAlertsCallback(a),this.backend,this.context.token),s=[r,o,i].filter(Boolean);return this.sessionOptions.proctoringType!="REALTIME"&&n&&s.push(n),this.recorder=new $a(this.proctoringSession,s),{cameraRecorder:r,screenRecorder:n,alertRecorder:i,noiseRecorder:o}}async login(){if(!this.context.credentials?.cpf)throw e0;this.context.token=await this.auth.login()}async start(t=ir,r={}){try{if(this.context.token===void 0)throw Qg;t.useChallenge&&(this.extensionEasycatcher=new Ha),this.extension=new Va,this.extension.addEventListener();let n=this.backend.selectBaseUrl(this.context.type),i=await ur();await this.repositoryDevices.save({...i,id:"devices"}),this.sessionOptions={...ir,...t},this.videoOptions=Ba(r),await this.initConfig(t.useGeolocation),await this.verifyBrowser(),this.sessionOptions.captureScreen&&await this.verifyMultipleMonitors(this.sessionOptions);try{t?.useSpyScan&&await this.spyCam.isAlive()}catch{throw t0}if(this.state!="Stop")throw Xg;this.state="Starting",await this.repository.hasSessions()&&await this.repository.clear(),this.proctoringSession=new Hn,this.allRecorders=await this.createRecorders(this.sessionOptions);let o=await this.backend.confirmStart({clientId:this.context.clientId,examId:this.context.examId,token:this.context.token},this.sessionOptions,this.geolocation?this.geolocation.coords.latitude:void 0,this.geolocation?this.geolocation.coords.longitude:void 0);this.proctoringId=o.id,me.registerDevicesChecked(this.proctoringId,!!this.deviceData,`Devices checked: ${JSON.stringify(this.deviceData)} | Devices List: ${JSON.stringify(i)}`);try{t?.useExternalCamera&&await this.appChecker.startTransmission(this.proctoringId)}catch{throw r0}this.allRecorders.cameraRecorder.setProctoringId(this.proctoringId),this.allRecorders.noiseRecorder.setProctoringId(this.proctoringId),this.proctoringSession.setProctoringId(this.proctoringId);try{console.log("Starting recorders"),await this.recorder.startAll()}catch(l){throw console.log("Starting recorders error:",l),l}t?.useSpyScan&&(this.spyCam.setProctoringId(this.proctoringId),this.spyCam.startCheckSpyCam(this.paramsConfig.spyScanInterval??5,{deviceType:3})),await this.repository.save(this.proctoringSession);let s={};for(let l in navigator)s[l]=navigator[l];me.registerStart(this.proctoringId,!0,`Version: ${ns()}
|
|
507
507
|
Navigator: ${JSON.stringify(s)}`),o.cameraStream=this.allRecorders.cameraRecorder.cameraStream,this.allRecorders.screenRecorder&&(o.screenStream=this.allRecorders.screenRecorder.screenStream),this.state="Recording";let a=0,c=!1;return this.verifyFirstFaceInterval=setInterval(async()=>{if(this.sessionOptions.proctoringType==="REALTIME"){if(c)return;c=!0,a++;try{var l=await this.backend.verifyFace(this.proctoringId,await this.allRecorders.cameraRecorder.getCurrentImageBase64(),!(a>2));c=!1,clearInterval(this.verifyFirstFaceInterval)}catch{c=!1;return}}},5e3),o}catch(n){throw console.log(n),await this.cancel(),this.proctoringId&&me.registerStart(this.proctoringId,!1,`Token: ${this.context.token}
|
|
508
508
|
Version: ${ns()}
|
|
509
509
|
Navigator: ${navigator}
|