easyproctor 2.5.5 → 2.5.6

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/index.js CHANGED
@@ -25978,7 +25978,6 @@ var BaseDetection = class {
25978
25978
  }
25979
25979
  cameraStream && !this.video.srcObject && (this.video.srcObject = cameraStream);
25980
25980
  this.video.play();
25981
- this.startTime = new Date(Date.now());
25982
25981
  const that = this;
25983
25982
  (_a2 = this.video) == null ? void 0 : _a2.addEventListener("loadeddata", () => that.predictWebcam());
25984
25983
  const style = document.createElement("style");
@@ -26021,8 +26020,8 @@ var BaseDetection = class {
26021
26020
  description: this.alertTranslate(description),
26022
26021
  type,
26023
26022
  category: description,
26024
- begin: Date.now() - this.startTime.getTime(),
26025
- end: Date.now() - this.startTime.getTime()
26023
+ begin: 0,
26024
+ end: 0
26026
26025
  });
26027
26026
  if (this.options.onRealtimeAlertsCallback == null)
26028
26027
  this.error && (this.error.innerText = description);
@@ -26033,8 +26032,8 @@ var BaseDetection = class {
26033
26032
  description: this.alertTranslate(description),
26034
26033
  type,
26035
26034
  category: description,
26036
- begin: Date.now() - this.startTime.getTime(),
26037
- end: Date.now() - this.startTime.getTime()
26035
+ begin: 0,
26036
+ end: 0
26038
26037
  });
26039
26038
  this.error && (this.error.innerText = "");
26040
26039
  }
@@ -30306,46 +30305,6 @@ function isMobileDevice() {
30306
30305
  return /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
30307
30306
  }
30308
30307
 
30309
- // src/plugins/insights.ts
30310
- var backendService;
30311
- var init = (backend) => {
30312
- backendService = backend;
30313
- return backendService;
30314
- };
30315
- var eventNames = {
30316
- DEVICES_CHECKED: "devices_checked",
30317
- START: "start",
30318
- FINISH: "finish",
30319
- ERROR: "error",
30320
- UPLOAD: "upload",
30321
- UPLOAD_FILE: "upload_file",
30322
- DOWNLOAD_VIDEO: "download_video",
30323
- BUFFER_SIZE: "buffer_size",
30324
- ANOTHER_STREAM: "another_stream",
30325
- CHANGE_DEVICE: "change_device",
30326
- STOP_SHARING_SCREEN: "stop_sharing_screen",
30327
- ERROR_RECORDER_RTC: "error_recorder_rtc",
30328
- BROWSER_NOT_SUPPORTED: "browser_not_supported",
30329
- SAVE_ON_SESSION: "save_on_session"
30330
- };
30331
- var log = (eventName, properties) => backendService && backendService.log(eventName, properties);
30332
- var trackers = {
30333
- registerDevicesChecked: (proctoringId2, success, description) => log(eventNames.DEVICES_CHECKED, { proctoringId: proctoringId2, success, description }),
30334
- registerStart: (proctoringId2, success, description) => log(eventNames.START, { proctoringId: proctoringId2, success, description }),
30335
- registerFinish: (proctoringId2, success, description) => log(eventNames.FINISH, { proctoringId: proctoringId2, success, description }),
30336
- registerError: (proctoringId2, description) => log(eventNames.ERROR, { proctoringId: proctoringId2, description }),
30337
- registerBrowserNotSupported: (proctoringId2, description) => log(eventNames.BROWSER_NOT_SUPPORTED, { proctoringId: proctoringId2, description }),
30338
- registerUpload: (proctoringId2, success, description, serviceType, uploadTime) => log(eventNames.UPLOAD, { proctoringId: proctoringId2, success, description, serviceType, uploadTime }),
30339
- registerUploadFile: (proctoringId2, description, fileType) => log(eventNames.UPLOAD_FILE, { proctoringId: proctoringId2, description, fileType }),
30340
- registerChangeDevice: (proctoringId2, inOrOut, description) => log(eventNames.CHANGE_DEVICE, { proctoringId: proctoringId2, inOrOut, description }),
30341
- registerStopSharingScreen: (proctoringId2, description) => log(eventNames.STOP_SHARING_SCREEN, { proctoringId: proctoringId2, description }),
30342
- registerErrorRecorderRTC: (proctoringId2, description) => log(eventNames.ERROR_RECORDER_RTC, { proctoringId: proctoringId2, description }),
30343
- registerDownloadFile: (proctoringId2, description) => log(eventNames.DOWNLOAD_VIDEO, { proctoringId: proctoringId2, description }),
30344
- registerOnBufferSizeError: (proctoringId2, description) => log(eventNames.BUFFER_SIZE, { proctoringId: proctoringId2, description }),
30345
- registerAnotherStream: (proctoringId2, description) => log(eventNames.ANOTHER_STREAM, { proctoringId: proctoringId2, description }),
30346
- registerSaveOnSession: (proctoringId2, description) => log(eventNames.SAVE_ON_SESSION, { proctoringId: proctoringId2, description })
30347
- };
30348
-
30349
30308
  // src/plugins/recorder.ts
30350
30309
  var proctoringId;
30351
30310
  function setRecorderProctoringId(id) {
@@ -30358,6 +30317,7 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30358
30317
  let lastEvent;
30359
30318
  let bufferSize;
30360
30319
  bufferSize = 0;
30320
+ let startTime;
30361
30321
  let recorderOptions = {
30362
30322
  // eslint-disable-next-line no-useless-escape
30363
30323
  mimeType: "video/webm",
@@ -30377,59 +30337,102 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30377
30337
  audioBitsPerSecond: 64 * 1e3
30378
30338
  };
30379
30339
  }
30380
- const mediaRecorder = new MediaRecorder(stream4, recorderOptions);
30381
- mediaRecorder.ondataavailable = (e3) => {
30382
- bufferSize = bufferSize + e3.data.size;
30383
- if (e3.data.size > 0) {
30384
- buffer.push(e3.data);
30340
+ function buildMediaRecorder(stream5, recorderOptions2) {
30341
+ const tracks = stream5.getTracks();
30342
+ if (tracks.length == 0) {
30343
+ throw new Error("No tracks found");
30385
30344
  }
30386
- if (!stopped) {
30387
- if (lastEvent && e3.data.size === lastEvent.data.size || e3.data.size === 0) {
30388
- proctoringId && lastEvent && e3.data.size === lastEvent.data.size && trackers.registerOnBufferSizeError(
30389
- proctoringId,
30390
- `onBufferSizeError: Recorder size freezed: ${e3.data.size} Mb`
30391
- );
30392
- proctoringId && e3.data.size === 0 && trackers.registerOnBufferSizeError(
30393
- proctoringId,
30394
- `onBufferSizeError: Recorder size equal 0 Mb`
30395
- );
30396
- onBufferSizeErrorCallback && onBufferSizeErrorCallback();
30345
+ const invalidTracks = tracks.find((t3) => t3.readyState != "live");
30346
+ if (invalidTracks) {
30347
+ throw new Error("Track not live: " + invalidTracks.label);
30348
+ }
30349
+ console.log("buildMediaRecorder tracks OK");
30350
+ let mediaRecorder2 = new MediaRecorder(stream5, recorderOptions2);
30351
+ console.log("buildMediaRecorder mediaRecorder OK");
30352
+ mediaRecorder2.ondataavailable = (e3) => {
30353
+ bufferSize = bufferSize + e3.data.size;
30354
+ if (e3.data.size > 0) {
30355
+ buffer.push(e3.data);
30397
30356
  }
30398
- lastEvent = e3;
30399
- } else {
30400
- if (audio && mediaRecorder.state == "inactive") {
30401
- const blob = new Blob(buffer, { type: "audio/webm" });
30402
- buffer = [blob];
30357
+ if (stopped) {
30358
+ resolvePromise && resolvePromise();
30403
30359
  }
30404
- resolvePromise && resolvePromise();
30405
- }
30406
- };
30407
- function startRecording() {
30408
- return new Promise((resolve) => {
30409
- resolvePromise = resolve;
30410
- mediaRecorder.start();
30411
- bufferSize = 0;
30412
- stopped = false;
30413
- if (onBufferSizeError) {
30414
- onBufferSizeInterval = setInterval(async () => {
30415
- await mediaRecorder.requestData();
30416
- }, 3e4);
30360
+ };
30361
+ return mediaRecorder2;
30362
+ }
30363
+ let mediaRecorder = buildMediaRecorder(stream4, recorderOptions);
30364
+ async function startRecorder(recorder2) {
30365
+ return new Promise((resolve, reject) => {
30366
+ var _a2, _b;
30367
+ let started = false;
30368
+ recorder2.onstart = () => {
30369
+ started = true;
30370
+ console.log("recorder onstart");
30371
+ resolve();
30372
+ };
30373
+ recorder2.onerror = (ev) => {
30374
+ console.error("Recorder error event:", ev);
30375
+ stream4.getTracks().forEach((t3) => console.log(t3.readyState));
30376
+ if ("error" in ev) {
30377
+ const err = ev.error;
30378
+ console.error("Error name:", err == null ? void 0 : err.name);
30379
+ console.error("Error message:", err == null ? void 0 : err.message);
30380
+ reject(err || ev);
30381
+ } else {
30382
+ console.warn("Evento sem propriedade error");
30383
+ reject(ev);
30384
+ }
30385
+ };
30386
+ try {
30387
+ console.log("State antes do start:", recorder2.state);
30388
+ recorder2.start(1e4);
30389
+ startTime = new Date(Date.now());
30390
+ } catch (e3) {
30391
+ console.error("Recorder erro ao chamar start event:", e3);
30392
+ console.error("Erro real:", e3, e3 == null ? void 0 : e3.error, (_a2 = e3 == null ? void 0 : e3.error) == null ? void 0 : _a2.name, (_b = e3 == null ? void 0 : e3.error) == null ? void 0 : _b.message);
30393
+ console.error("Erro real 2:", e3, e3 == null ? void 0 : e3.message, e3 == null ? void 0 : e3.name);
30394
+ stream4.getTracks().forEach((t3) => console.log(t3.readyState));
30395
+ return reject(e3);
30417
30396
  }
30397
+ setTimeout(() => {
30398
+ if (!started) {
30399
+ console.error("Timeout ao iniciar o recorder");
30400
+ reject(new Error("Timeout ao iniciar o recorder"));
30401
+ }
30402
+ }, 2e3);
30418
30403
  });
30419
30404
  }
30405
+ async function startRecording() {
30406
+ try {
30407
+ await startRecorder(mediaRecorder);
30408
+ if (mediaRecorder.state === "recording") {
30409
+ bufferSize = 0;
30410
+ stopped = false;
30411
+ return;
30412
+ } else {
30413
+ console.log("Recorder n\xE3o est\xE1 em estado recording ap\xF3s start");
30414
+ }
30415
+ } catch (e3) {
30416
+ console.error("Erro ao iniciar o recorder:", e3);
30417
+ await new Promise((r3) => setTimeout(r3, 300));
30418
+ throw e3;
30419
+ }
30420
+ return;
30421
+ }
30420
30422
  function stopRecording() {
30421
30423
  return new Promise((resolve) => {
30422
30424
  if (mediaRecorder.state == "recording") {
30425
+ console.log("stopRecording Recorder est\xE1 em estado recording, iniciando stop");
30423
30426
  resolvePromise = resolve;
30424
- mediaRecorder.stop();
30425
30427
  stopped = true;
30426
- clearInterval(onBufferSizeInterval);
30427
- stream4.getTracks().forEach((el) => {
30428
- el.stop();
30429
- });
30428
+ mediaRecorder.stop();
30430
30429
  } else {
30430
+ console.log("stopRecording Recorder n\xE3o est\xE1 em estado recording");
30431
30431
  resolve();
30432
30432
  }
30433
+ stream4.getTracks().forEach((el) => {
30434
+ el.stop();
30435
+ });
30433
30436
  });
30434
30437
  }
30435
30438
  function pauseRecording() {
@@ -30455,16 +30458,60 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30455
30458
  function getBufferSize() {
30456
30459
  return bufferSize;
30457
30460
  }
30461
+ function getStartTime() {
30462
+ return startTime;
30463
+ }
30458
30464
  return {
30459
30465
  startRecording,
30460
30466
  stopRecording,
30461
30467
  pauseRecording,
30462
30468
  resumeRecording,
30463
30469
  recorderOptions,
30464
- getBufferSize
30470
+ getBufferSize,
30471
+ getStartTime
30465
30472
  };
30466
30473
  }
30467
30474
 
30475
+ // src/plugins/insights.ts
30476
+ var backendService;
30477
+ var init = (backend) => {
30478
+ backendService = backend;
30479
+ return backendService;
30480
+ };
30481
+ var eventNames = {
30482
+ DEVICES_CHECKED: "devices_checked",
30483
+ START: "start",
30484
+ FINISH: "finish",
30485
+ ERROR: "error",
30486
+ UPLOAD: "upload",
30487
+ UPLOAD_FILE: "upload_file",
30488
+ DOWNLOAD_VIDEO: "download_video",
30489
+ BUFFER_SIZE: "buffer_size",
30490
+ ANOTHER_STREAM: "another_stream",
30491
+ CHANGE_DEVICE: "change_device",
30492
+ STOP_SHARING_SCREEN: "stop_sharing_screen",
30493
+ ERROR_RECORDER_RTC: "error_recorder_rtc",
30494
+ BROWSER_NOT_SUPPORTED: "browser_not_supported",
30495
+ SAVE_ON_SESSION: "save_on_session"
30496
+ };
30497
+ var log = (eventName, properties) => backendService && backendService.log(eventName, properties);
30498
+ var trackers = {
30499
+ registerDevicesChecked: (proctoringId2, success, description) => log(eventNames.DEVICES_CHECKED, { proctoringId: proctoringId2, success, description }),
30500
+ registerStart: (proctoringId2, success, description) => log(eventNames.START, { proctoringId: proctoringId2, success, description }),
30501
+ registerFinish: (proctoringId2, success, description) => log(eventNames.FINISH, { proctoringId: proctoringId2, success, description }),
30502
+ registerError: (proctoringId2, description) => log(eventNames.ERROR, { proctoringId: proctoringId2, description }),
30503
+ registerBrowserNotSupported: (proctoringId2, description) => log(eventNames.BROWSER_NOT_SUPPORTED, { proctoringId: proctoringId2, description }),
30504
+ registerUpload: (proctoringId2, success, description, serviceType, uploadTime) => log(eventNames.UPLOAD, { proctoringId: proctoringId2, success, description, serviceType, uploadTime }),
30505
+ registerUploadFile: (proctoringId2, description, fileType) => log(eventNames.UPLOAD_FILE, { proctoringId: proctoringId2, description, fileType }),
30506
+ registerChangeDevice: (proctoringId2, inOrOut, description) => log(eventNames.CHANGE_DEVICE, { proctoringId: proctoringId2, inOrOut, description }),
30507
+ registerStopSharingScreen: (proctoringId2, description) => log(eventNames.STOP_SHARING_SCREEN, { proctoringId: proctoringId2, description }),
30508
+ registerErrorRecorderRTC: (proctoringId2, description) => log(eventNames.ERROR_RECORDER_RTC, { proctoringId: proctoringId2, description }),
30509
+ registerDownloadFile: (proctoringId2, description) => log(eventNames.DOWNLOAD_VIDEO, { proctoringId: proctoringId2, description }),
30510
+ registerOnBufferSizeError: (proctoringId2, description) => log(eventNames.BUFFER_SIZE, { proctoringId: proctoringId2, description }),
30511
+ registerAnotherStream: (proctoringId2, description) => log(eventNames.ANOTHER_STREAM, { proctoringId: proctoringId2, description }),
30512
+ registerSaveOnSession: (proctoringId2, description) => log(eventNames.SAVE_ON_SESSION, { proctoringId: proctoringId2, description })
30513
+ };
30514
+
30468
30515
  // src/new-flow/upload/UploadService.ts
30469
30516
  var UploadService = class {
30470
30517
  constructor(proctoringId2, backend) {
@@ -30750,12 +30797,12 @@ var VolumeMeter = class {
30750
30797
  async start(options = {}) {
30751
30798
  return new Promise((resolve, reject) => {
30752
30799
  try {
30753
- const audioContext = new AudioContext();
30754
- this.analyser = audioContext.createAnalyser();
30755
- const microphone = audioContext.createMediaStreamSource(this.stream);
30800
+ this.audioContext = new AudioContext();
30801
+ this.analyser = this.audioContext.createAnalyser();
30802
+ this.microphone = this.audioContext.createMediaStreamSource(this.stream);
30756
30803
  this.analyser.smoothingTimeConstant = 0.8;
30757
30804
  this.analyser.fftSize = 1024;
30758
- microphone.connect(this.analyser);
30805
+ this.microphone.connect(this.analyser);
30759
30806
  const processAudio = () => {
30760
30807
  const array = new Uint8Array(this.analyser.frequencyBinCount);
30761
30808
  this.analyser.getByteFrequencyData(array);
@@ -30774,9 +30821,13 @@ var VolumeMeter = class {
30774
30821
  });
30775
30822
  }
30776
30823
  stop() {
30824
+ var _a2, _b, _c2;
30777
30825
  if (this.animationFrameId !== null) {
30778
30826
  cancelAnimationFrame(this.animationFrameId);
30779
30827
  }
30828
+ (_a2 = this.audioContext) == null ? void 0 : _a2.close();
30829
+ (_b = this.microphone) == null ? void 0 : _b.disconnect();
30830
+ (_c2 = this.analyser) == null ? void 0 : _c2.disconnect();
30780
30831
  }
30781
30832
  getVolume() {
30782
30833
  return this.volume;
@@ -30837,6 +30888,7 @@ var CameraRecorder = class {
30837
30888
  this.isCanvasLoopActive = false;
30838
30889
  this.hardwareStream = null;
30839
30890
  this.internalClonedStream = null;
30891
+ this.videoElement = null;
30840
30892
  this.currentRetries = 0;
30841
30893
  this.packageCount = 0;
30842
30894
  this.noiseWait = 20;
@@ -30857,7 +30909,12 @@ var CameraRecorder = class {
30857
30909
  if (((_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.detectPerson) || ((_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.detectCellPhone)) {
30858
30910
  this.objectDetection = new ObjectDetection(
30859
30911
  {
30860
- onRealtimeAlertsCallback: (response) => this.options.onRealtimeAlertsCallback(response)
30912
+ onRealtimeAlertsCallback: (response) => {
30913
+ var _a3, _b2;
30914
+ response.begin = Date.now() - (((_a3 = this.getStartTime()) == null ? void 0 : _a3.getTime()) || 0);
30915
+ response.end = Date.now() - (((_b2 = this.getStartTime()) == null ? void 0 : _b2.getTime()) || 0);
30916
+ this.options.onRealtimeAlertsCallback(response);
30917
+ }
30861
30918
  },
30862
30919
  this.paramsConfig
30863
30920
  );
@@ -30866,7 +30923,12 @@ var CameraRecorder = class {
30866
30923
  if ((_c2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _c2.detectFace) {
30867
30924
  this.faceDetection = new FaceDetection(
30868
30925
  {
30869
- onRealtimeAlertsCallback: (response) => this.options.onRealtimeAlertsCallback(response)
30926
+ onRealtimeAlertsCallback: (response) => {
30927
+ var _a3, _b2;
30928
+ response.begin = Date.now() - (((_a3 = this.getStartTime()) == null ? void 0 : _a3.getTime()) || 0);
30929
+ response.end = Date.now() - (((_b2 = this.getStartTime()) == null ? void 0 : _b2.getTime()) || 0);
30930
+ this.options.onRealtimeAlertsCallback(response);
30931
+ }
30870
30932
  },
30871
30933
  this.paramsConfig
30872
30934
  );
@@ -30892,25 +30954,20 @@ var CameraRecorder = class {
30892
30954
  }
30893
30955
  async bufferError(e3) {
30894
30956
  var _a2, _b;
30895
- console.log("buffer error Camera Recorder params " + this.paramsConfig.videoBehaviourParameters);
30957
+ console.log("buffer error Camera Recorder params ");
30896
30958
  const retryEnabled = ((_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.retryEnabled) || false;
30897
30959
  const maxRetries = ((_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.maxRetries) || 3;
30898
30960
  if (retryEnabled && this.currentRetries < maxRetries) {
30899
30961
  await this.recordingStop();
30900
- await this.startRecording({
30901
- retry: true
30902
- });
30962
+ await this.startRecording();
30903
30963
  this.currentRetries++;
30904
30964
  this.options.onBufferSizeErrorCallback && this.options.onBufferSizeErrorCallback(this.cameraStream);
30905
30965
  } else {
30906
30966
  this.options.onBufferSizeErrorCallback && this.options.onBufferSizeErrorCallback();
30907
30967
  }
30908
30968
  }
30909
- async startRecording(options) {
30910
- var _a2, _b, _c2, _d, _e3, _f, _g, _h;
30911
- if ((((_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.detectPerson) || ((_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.detectCellPhone) || ((_c2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _c2.detectFace)) && !(options == null ? void 0 : options.retry)) {
30912
- await this.initializeDetectors();
30913
- }
30969
+ async startStream() {
30970
+ var _a2;
30914
30971
  const { cameraId, microphoneId, onBufferSizeErrorCallback } = this.options;
30915
30972
  const constraints = {
30916
30973
  audio: { deviceId: microphoneId },
@@ -30934,13 +30991,81 @@ var CameraRecorder = class {
30934
30991
  const track = this.cameraStream.getVideoTracks()[0];
30935
30992
  const settings = track.getSettings();
30936
30993
  let { width = 0, height = 0 } = settings;
30994
+ const isPortrait = (_a2 = screen.orientation) == null ? void 0 : _a2.type.includes("portrait");
30995
+ if (isPortrait && isMobileDevice()) {
30996
+ if (this.videoOptions.width == height && this.videoOptions.height == width) {
30997
+ [width, height] = [height, width];
30998
+ }
30999
+ }
31000
+ if (this.videoOptions.minWidth > width || this.videoOptions.minHeight > height) {
31001
+ throw STREAM_UNDER_MINIMUM_PERMITTED;
31002
+ } else if (this.videoOptions.width !== width || this.videoOptions.height !== height) {
31003
+ trackers.registerAnotherStream(
31004
+ this.proctoringId,
31005
+ `Maybe have another stream active
31006
+ Video Options: ${JSON.stringify(
31007
+ this.videoOptions,
31008
+ null,
31009
+ 2
31010
+ )}
31011
+ Setting: ${JSON.stringify(settings, null, 2)}`
31012
+ );
31013
+ throw ANOTHER_STREAM_ACTIVE;
31014
+ }
31015
+ }
31016
+ async stopStream() {
31017
+ if (this.cameraStream) {
31018
+ this.cameraStream.getTracks().forEach((track) => track.stop());
31019
+ }
31020
+ if (this.internalClonedStream) {
31021
+ this.internalClonedStream.getTracks().forEach((track) => track.stop());
31022
+ this.internalClonedStream = null;
31023
+ }
31024
+ if (this.hardwareStream) {
31025
+ this.hardwareStream.getTracks().forEach((track) => track.stop());
31026
+ this.hardwareStream = null;
31027
+ }
31028
+ }
31029
+ async waitForVideoFlow() {
31030
+ return new Promise((resolve) => {
31031
+ const check = () => {
31032
+ var _a2;
31033
+ if (this.videoElement && ((_a2 = this.videoElement) == null ? void 0 : _a2.readyState) >= 3) return resolve();
31034
+ else requestAnimationFrame(check);
31035
+ };
31036
+ check();
31037
+ });
31038
+ }
31039
+ async attachAndWarmup(stream4) {
31040
+ this.videoElement = document.createElement("video");
31041
+ this.videoElement.srcObject = stream4;
31042
+ this.videoElement.muted = true;
31043
+ await this.videoElement.play().catch((e3) => {
31044
+ });
31045
+ await new Promise((resolve) => {
31046
+ var _a2;
31047
+ if (this.videoElement && ((_a2 = this.videoElement) == null ? void 0 : _a2.readyState) >= 1) return resolve();
31048
+ if (this.videoElement)
31049
+ this.videoElement.onloadedmetadata = () => resolve();
31050
+ });
31051
+ console.log("CameraRecorder checking metadata ok");
31052
+ await this.waitForVideoFlow();
31053
+ console.log("CameraRecorder waiting for video flow ok");
31054
+ await new Promise((r3) => setTimeout(r3, 300));
31055
+ }
31056
+ async startRecording() {
31057
+ var _a2, _b, _c2, _d, _e3, _f, _g;
31058
+ console.log("CameraRecorder startRecording");
31059
+ await this.startStream();
31060
+ await this.attachAndWarmup(this.cameraStream);
30937
31061
  const {
30938
31062
  startRecording,
30939
31063
  stopRecording,
30940
31064
  pauseRecording,
30941
31065
  resumeRecording,
30942
31066
  recorderOptions,
30943
- getBufferSize
31067
+ getBufferSize,
31068
+ getStartTime
30944
31069
  } = recorder(
30945
31070
  this.cameraStream,
30946
31071
  // streamToRecord,
@@ -30955,42 +31080,41 @@ var CameraRecorder = class {
30955
31080
  this.recordingResume = resumeRecording;
30956
31081
  this.recorderOptions = recorderOptions;
30957
31082
  this.getBufferSize = getBufferSize;
30958
- this.recordingStart();
30959
- const isPortrait = (_d = screen.orientation) == null ? void 0 : _d.type.includes("portrait");
30960
- if (isPortrait && isMobileDevice()) {
30961
- if (this.videoOptions.width == height && this.videoOptions.height == width) {
30962
- [width, height] = [height, width];
31083
+ this.getStartTime = getStartTime;
31084
+ try {
31085
+ await new Promise((r3) => setTimeout(r3, 500));
31086
+ await this.recordingStart();
31087
+ } catch (error) {
31088
+ console.log("Camera Recorder error", error);
31089
+ this.stopRecording();
31090
+ const maxRetries = ((_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.maxRetries) || 3;
31091
+ if (this.currentRetries < maxRetries) {
31092
+ console.log("Camera Recorder retry", this.currentRetries);
31093
+ this.currentRetries++;
31094
+ await this.startRecording();
31095
+ } else {
31096
+ throw error;
30963
31097
  }
30964
31098
  }
30965
- if (this.videoOptions.minWidth > width || this.videoOptions.minHeight > height) {
30966
- throw STREAM_UNDER_MINIMUM_PERMITTED;
30967
- } else if (this.videoOptions.width !== width || this.videoOptions.height !== height) {
30968
- trackers.registerAnotherStream(
30969
- this.proctoringId,
30970
- `Maybe have another stream active
30971
- Video Options: ${JSON.stringify(
30972
- this.videoOptions,
30973
- null,
30974
- 2
30975
- )}
30976
- Setting: ${JSON.stringify(settings, null, 2)}`
30977
- );
30978
- throw ANOTHER_STREAM_ACTIVE;
31099
+ if (((_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.detectPerson) || ((_c2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _c2.detectCellPhone) || ((_d = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _d.detectFace)) {
31100
+ await this.initializeDetectors();
30979
31101
  }
30980
- ((_e3 = this.paramsConfig.imageBehaviourParameters) == null ? void 0 : _e3.useUploadImage) && this.options.proctoringType == "IMAGE" && this.photoShotsCycle();
30981
- if ((_f = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _f.detectFace) {
31102
+ if ((_e3 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _e3.detectFace) {
30982
31103
  await this.faceDetection.enableCam(this.cameraStream);
30983
31104
  }
30984
- if (((_g = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _g.detectPerson) || ((_h = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _h.detectCellPhone)) {
31105
+ if (((_f = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _f.detectPerson) || ((_g = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _g.detectCellPhone)) {
30985
31106
  await this.objectDetection.enableCam(this.cameraStream);
30986
31107
  }
30987
31108
  this.filesToUpload = [];
30988
31109
  if (this.options.proctoringType == "REALTIME") {
30989
- this.captureFrame();
31110
+ await this.startRealtimeCapture();
30990
31111
  }
30991
31112
  this.packageCount = 0;
31113
+ console.log("Camera Recorder started OK");
30992
31114
  }
30993
31115
  async stopRecording() {
31116
+ var _a2, _b, _c2;
31117
+ console.log("Camera Recorder stopRecording");
30994
31118
  this.isCanvasLoopActive = false;
30995
31119
  this.recordingStop && await this.recordingStop();
30996
31120
  try {
@@ -31009,6 +31133,16 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31009
31133
  this.hardwareStream.getTracks().forEach((track) => track.stop());
31010
31134
  this.hardwareStream = null;
31011
31135
  }
31136
+ if (this.videoElement) {
31137
+ (_a2 = this.videoElement) == null ? void 0 : _a2.remove();
31138
+ this.videoElement = null;
31139
+ }
31140
+ if (this.video) {
31141
+ (_b = this.video) == null ? void 0 : _b.remove();
31142
+ }
31143
+ if (this.canvas) {
31144
+ (_c2 = this.canvas) == null ? void 0 : _c2.remove();
31145
+ }
31012
31146
  } catch {
31013
31147
  console.error("Erro ao parar os streams de m\xEDdia.");
31014
31148
  }
@@ -31029,35 +31163,6 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31029
31163
  async resumeRecording() {
31030
31164
  await this.recordingResume();
31031
31165
  }
31032
- photoShotsCycle() {
31033
- let imageFile;
31034
- this.configImageCapture();
31035
- this.imageInterval = setInterval(async () => {
31036
- this.canvas.getContext("2d").drawImage(
31037
- this.video,
31038
- 0,
31039
- 0,
31040
- this.videoOptions.width,
31041
- this.videoOptions.height
31042
- );
31043
- const image_data_url = this.canvas.toDataURL("image/jpeg");
31044
- imageFile = await this.getFile(
31045
- image_data_url,
31046
- `${this.proctoringId}_${this.imageCount + 1}.jpg`,
31047
- "image/jpeg"
31048
- );
31049
- if (imageFile && this.upload && this.backendToken) {
31050
- this.upload.upload(
31051
- {
31052
- file: imageFile
31053
- },
31054
- this.backendToken,
31055
- true
31056
- );
31057
- this.imageCount++;
31058
- }
31059
- }, this.paramsConfig.imageBehaviourParameters.uploadInterval * 1e3);
31060
- }
31061
31166
  async getCurrentImageBase64() {
31062
31167
  if (!this.video || !this.canvas) {
31063
31168
  this.configImageCapture();
@@ -31088,30 +31193,35 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31088
31193
  this.canvas.getContext("2d").drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
31089
31194
  return this.canvas.toDataURL("image/jpeg");
31090
31195
  }
31091
- // captura um frame a cada intervalo de tempo definido no paramsConfig.videoBehaviourParameters?.realtimeCaptureInterval!
31092
- captureFrame() {
31093
- var _a2, _b;
31196
+ async captureFrame() {
31197
+ var _a2;
31094
31198
  let imageFile;
31095
- this.configImageCapture();
31096
31199
  const packSize = (_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.realtimePackageSize;
31200
+ this.canvas.getContext("2d").drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
31201
+ const image_data_url = this.canvas.toDataURL("image/jpeg");
31202
+ if (this.proctoringId == void 0) return;
31203
+ if (packSize == this.imageCount) {
31204
+ this.imageCount = 0;
31205
+ const framesToSend = [...this.filesToUpload];
31206
+ this.sendPackage(framesToSend);
31207
+ await this.filesToUpload.splice(0, this.filesToUpload.length);
31208
+ }
31209
+ let imageName = `${this.proctoringId}_${this.imageCount + 1}.jpg`;
31210
+ imageFile = await this.getFile(image_data_url, imageName, "image/jpeg");
31211
+ if (imageFile && imageFile.size > 10 && packSize > 0) {
31212
+ this.filesToUpload.push(imageFile);
31213
+ this.imageCount++;
31214
+ }
31215
+ }
31216
+ // inicia a captura de um frame a cada intervalo de tempo definido no paramsConfig.videoBehaviourParameters?.realtimeCaptureInterval!
31217
+ async startRealtimeCapture() {
31218
+ var _a2;
31219
+ this.configImageCapture();
31097
31220
  this.imageCount = 0;
31221
+ await this.captureFrame();
31098
31222
  this.imageInterval = setInterval(async () => {
31099
- this.canvas.getContext("2d").drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
31100
- const image_data_url = this.canvas.toDataURL("image/jpeg");
31101
- if (this.proctoringId == void 0) return;
31102
- if (packSize == this.imageCount) {
31103
- this.imageCount = 0;
31104
- const framesToSend = [...this.filesToUpload];
31105
- this.sendPackage(framesToSend);
31106
- await this.filesToUpload.splice(0, this.filesToUpload.length);
31107
- }
31108
- let imageName = `${this.proctoringId}_${this.imageCount + 1}.jpg`;
31109
- imageFile = await this.getFile(image_data_url, imageName, "image/jpeg");
31110
- if (imageFile && imageFile.size > 10 && packSize > 0) {
31111
- this.filesToUpload.push(imageFile);
31112
- this.imageCount++;
31113
- }
31114
- }, ((_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.realtimeCaptureInterval) * 1e3);
31223
+ await this.captureFrame();
31224
+ }, ((_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.realtimeCaptureInterval) * 1e3);
31115
31225
  }
31116
31226
  // envia pacote de imagens
31117
31227
  async sendPackage(framesToSend) {
@@ -31119,7 +31229,7 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31119
31229
  let pending = false;
31120
31230
  let undeliveredPackagesCount = 0;
31121
31231
  const packSize = (_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.realtimePackageSize;
31122
- const packCaptureInterval = ((_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.realtimeCaptureInterval) + 1;
31232
+ const packCaptureInterval = (_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.realtimeCaptureInterval;
31123
31233
  if (this.upload && this.backendToken && !pending && this.filesToUpload.length > 0) {
31124
31234
  undeliveredPackagesCount = 0;
31125
31235
  pending = true;
@@ -32307,6 +32417,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
32307
32417
  return this.deviceCheckResult;
32308
32418
  }
32309
32419
  async runCheckDevicesFlow(options, _videoOptions, onModalConfirm, onModalCancel, onUpdate) {
32420
+ var _a2;
32310
32421
  if (_DeviceCheckerService.isModalOpen) {
32311
32422
  return Promise.reject("Modal j\xE1 est\xE1 aberto");
32312
32423
  }
@@ -32324,7 +32435,9 @@ var _DeviceCheckerService = class _DeviceCheckerService {
32324
32435
  options,
32325
32436
  _videoOptions
32326
32437
  );
32327
- this.checkSpyScan();
32438
+ if ((_a2 = this.options) == null ? void 0 : _a2.useSpyScan) {
32439
+ await this.checkSpyScan();
32440
+ }
32328
32441
  const returnData = { cameraStream: this.cameraRecorder.cameraStream };
32329
32442
  this.onUpdateCb = (e3) => onUpdate(e3);
32330
32443
  const resultPromise = new Promise(
@@ -32379,6 +32492,10 @@ var _DeviceCheckerService = class _DeviceCheckerService {
32379
32492
  if (_DeviceCheckerService.isModalOpen) {
32380
32493
  return Promise.reject();
32381
32494
  }
32495
+ this.allowedAmbient = false;
32496
+ this.allowedMicrophone = false;
32497
+ this.allowedAmbient = false;
32498
+ this.allowedPositionFace = false;
32382
32499
  _DeviceCheckerService.isModalOpen = true;
32383
32500
  this.DeviceCheckerUI = new DeviceCheckerUI(options, _videoOptions);
32384
32501
  try {
@@ -32416,8 +32533,8 @@ var _DeviceCheckerService = class _DeviceCheckerService {
32416
32533
  resolve(response);
32417
32534
  });
32418
32535
  } catch (error) {
32536
+ this.DeviceCheckerUI && this.DeviceCheckerUI.closeModal();
32419
32537
  this.closeCheckDevices();
32420
- this.DeviceCheckerUI.closeModal();
32421
32538
  return Promise.reject(error);
32422
32539
  }
32423
32540
  }
@@ -32488,7 +32605,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
32488
32605
  }
32489
32606
  async changeSelectedDevice({ cameraId, microphoneId }) {
32490
32607
  var _a2;
32491
- this.cameraRecorder.stopRecording && await this.cameraRecorder.stopRecording();
32608
+ this.cameraRecorder.stopStream && await this.cameraRecorder.stopStream();
32492
32609
  (_a2 = this.volumeMeter) == null ? void 0 : _a2.stop();
32493
32610
  this.faceDetection.stopDetection();
32494
32611
  this.cameraRecorder = new CameraRecorder(
@@ -32504,7 +32621,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
32504
32621
  height: this.videoOptions.height
32505
32622
  }
32506
32623
  );
32507
- await this.cameraRecorder.startRecording();
32624
+ await this.cameraRecorder.startStream();
32508
32625
  this.videoDeviceInterface(this.cameraRecorder.cameraStream);
32509
32626
  this.audioDeviceInterface(this.cameraRecorder.cameraStream);
32510
32627
  return {
@@ -32512,6 +32629,10 @@ var _DeviceCheckerService = class _DeviceCheckerService {
32512
32629
  };
32513
32630
  }
32514
32631
  async startCheckDevices(options = getDefaultProctoringOptions, _videoOptions) {
32632
+ this.allowedAmbient = false;
32633
+ this.allowedMicrophone = false;
32634
+ this.allowedAmbient = false;
32635
+ this.allowedPositionFace = false;
32515
32636
  this.DeviceCheckerUI && this.DeviceCheckerUI.setSelectOption(
32516
32637
  options,
32517
32638
  (e3) => this.changeSelectedDevice(e3)
@@ -32531,7 +32652,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
32531
32652
  height: this.videoOptions.height
32532
32653
  }
32533
32654
  );
32534
- await this.cameraRecorder.startRecording();
32655
+ await this.cameraRecorder.startStream();
32535
32656
  this.videoDeviceInterface(this.cameraRecorder.cameraStream);
32536
32657
  this.audioDeviceInterface(this.cameraRecorder.cameraStream);
32537
32658
  if (this.DeviceCheckerUI) {
@@ -32548,7 +32669,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
32548
32669
  this.faceDetection.stopDetection();
32549
32670
  (_a2 = this.volumeMeter) == null ? void 0 : _a2.stop();
32550
32671
  this.volumeMedia = Math.ceil(this.volumeSum / this.volumeCounter);
32551
- this.cameraRecorder.stopRecording && await this.cameraRecorder.stopRecording();
32672
+ this.cameraRecorder.stopStream && await this.cameraRecorder.stopStream();
32552
32673
  this.DeviceCheckerUI = void 0;
32553
32674
  this.onUpdateCb = void 0;
32554
32675
  }
@@ -32621,7 +32742,7 @@ var CapturePhoto = class {
32621
32742
  // height: 480,
32622
32743
  // }
32623
32744
  );
32624
- await this.cameraRecorder.startRecording();
32745
+ await this.cameraRecorder.startStream();
32625
32746
  cameraContainer.srcObject = this.cameraRecorder.cameraStream;
32626
32747
  cameraContainer.play();
32627
32748
  }
@@ -32861,7 +32982,7 @@ var CapturePhoto = class {
32861
32982
  });
32862
32983
  }
32863
32984
  async closeInterface() {
32864
- await this.cameraRecorder.stopRecording();
32985
+ await this.cameraRecorder.stopStream();
32865
32986
  const authPhoto = document.querySelector("#authPhoto");
32866
32987
  authPhoto == null ? void 0 : authPhoto.remove();
32867
32988
  }
@@ -33365,54 +33486,6 @@ var AlertRecorder = class {
33365
33486
  }
33366
33487
  };
33367
33488
 
33368
- // src/new-flow/recorders/AudioRecorder.ts
33369
- var AudioRecorder = class {
33370
- constructor(options, audioParams) {
33371
- this.blobs = [];
33372
- this.options = {
33373
- cameraId: void 0,
33374
- microphoneId: void 0
33375
- };
33376
- this.audioParams = {
33377
- recordingBitrate: 128
33378
- };
33379
- audioParams && (this.audioParams = audioParams);
33380
- options && (this.options = options);
33381
- }
33382
- async startRecording() {
33383
- const constraints = {
33384
- audio: { deviceId: this.options.microphoneId || "default" }
33385
- };
33386
- this.audioStream = await navigator.mediaDevices.getUserMedia(constraints);
33387
- const { startRecording, stopRecording, pauseRecording, resumeRecording } = recorder(this.audioStream, this.blobs, void 0, void 0, true);
33388
- this.recordingStart = startRecording;
33389
- this.recordingStop = stopRecording;
33390
- this.recordingPause = pauseRecording;
33391
- this.recordingResume = resumeRecording;
33392
- this.recordingStart();
33393
- }
33394
- async pauseRecording() {
33395
- }
33396
- async resumeRecording() {
33397
- }
33398
- async stopRecording() {
33399
- this.recordingStop && await this.recordingStop();
33400
- }
33401
- async saveOnSession(session, start, end) {
33402
- session.addRecording({
33403
- device: "",
33404
- file: new File(
33405
- this.blobs,
33406
- `EP_${session.id}_audio_${start && end && `${start}_${end}` || "0"}.webm`,
33407
- {
33408
- type: "audio/webm"
33409
- }
33410
- ),
33411
- origin: "Mic" /* Mic */
33412
- });
33413
- }
33414
- };
33415
-
33416
33489
  // node_modules/@mediapipe/tasks-audio/audio_bundle.mjs
33417
33490
  var t2 = "undefined" != typeof self ? self : {};
33418
33491
  function e2() {
@@ -35652,7 +35725,6 @@ var NoiseRecorder = class {
35652
35725
  this.recordingInProgress = false;
35653
35726
  this.recordIndex = 1;
35654
35727
  this.countLoopTimes = 0;
35655
- this.examStartTime = 0;
35656
35728
  this.recordingStartTime = 0;
35657
35729
  this.recordingEndTime = 0;
35658
35730
  this.isSpeech = false;
@@ -35679,12 +35751,7 @@ var NoiseRecorder = class {
35679
35751
  this.proctoringId && this.backend && (this.upload = new UploadService(this.proctoringId, this.backend));
35680
35752
  }
35681
35753
  async startRecording() {
35682
- this.examStartTime = Date.now();
35683
35754
  await this.createAudioClassifier();
35684
- this.audioRecorder = new AudioRecorder(
35685
- void 0,
35686
- this.paramsConfig.audioBehaviourParameters
35687
- );
35688
35755
  this.intervalNoiseDetection = setInterval(
35689
35756
  () => this.onNoiseDetectedRecord(),
35690
35757
  200
@@ -35696,6 +35763,7 @@ var NoiseRecorder = class {
35696
35763
  await this.stopSoundRecord();
35697
35764
  await this.volumeMeter && this.volumeMeter.stop();
35698
35765
  this.audioWorkletNode && this.audioWorkletNode.disconnect();
35766
+ this.context && this.context.close();
35699
35767
  }
35700
35768
  async pauseRecording() {
35701
35769
  }
@@ -35704,7 +35772,7 @@ var NoiseRecorder = class {
35704
35772
  async saveOnSession(session) {
35705
35773
  }
35706
35774
  async onNoiseDetectedRecord() {
35707
- var _a2, _b, _c2, _d;
35775
+ var _a2, _b, _c2, _d, _e3, _f, _g, _h, _i3;
35708
35776
  if (!this.volumeMeter && this.cameraRecorder.cameraStream) {
35709
35777
  this.volumeMeter = new VolumeMeter(this.cameraRecorder.cameraStream);
35710
35778
  this.volumeMeter.start().catch((e3) => {
@@ -35726,7 +35794,7 @@ var NoiseRecorder = class {
35726
35794
  this.recordingChunks = [...this.preRollBuffer];
35727
35795
  const totalSamplesInBuffer = this.preRollBuffer.reduce((acc, chunk) => acc + chunk.length, 0);
35728
35796
  const bufferDurationMs = totalSamplesInBuffer / this.SAMPLE_RATE * 1e3;
35729
- const triggerTime = Date.now() - this.examStartTime;
35797
+ const triggerTime = Date.now() - (((_c2 = this.cameraRecorder.getStartTime()) == null ? void 0 : _c2.getTime()) || 0);
35730
35798
  this.recordingStartTime = triggerTime - bufferDurationMs;
35731
35799
  if (this.recordingStartTime < 0) this.recordingStartTime = 0;
35732
35800
  } else if (this.recordingInProgress) {
@@ -35734,15 +35802,19 @@ var NoiseRecorder = class {
35734
35802
  const currentRecordDuration = Date.now() - this.recordingStartTime;
35735
35803
  if (silenceDuration >= this.SILENCE_THRESHOLD && currentRecordDuration >= 3e3 && this.countLoopTimes > 4) {
35736
35804
  await this.stopSoundRecord();
35737
- if (((_c2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _c2.detectNoise) && !this.isSpeech) {
35805
+ if (((_d = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _d.detectNoise) && !this.isSpeech) {
35738
35806
  this.onRealtimeAlertsCallback({
35807
+ begin: Date.now() - (((_e3 = this.cameraRecorder.getStartTime()) == null ? void 0 : _e3.getTime()) || 0),
35808
+ end: Date.now() - (((_f = this.cameraRecorder.getStartTime()) == null ? void 0 : _f.getTime()) || 0),
35739
35809
  status: "ALERT",
35740
35810
  description: "Barulho detectado",
35741
35811
  type: "audio_detection_on_stream"
35742
35812
  });
35743
35813
  }
35744
- if (((_d = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _d.detectSpeech) && this.isSpeech) {
35814
+ if (((_g = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _g.detectSpeech) && this.isSpeech) {
35745
35815
  this.onRealtimeAlertsCallback({
35816
+ begin: Date.now() - (((_h = this.cameraRecorder.getStartTime()) == null ? void 0 : _h.getTime()) || 0),
35817
+ end: Date.now() - (((_i3 = this.cameraRecorder.getStartTime()) == null ? void 0 : _i3.getTime()) || 0),
35746
35818
  status: "ALERT",
35747
35819
  description: "Fala detectada",
35748
35820
  type: "audio_detection_on_stream"
@@ -35757,8 +35829,9 @@ var NoiseRecorder = class {
35757
35829
  }
35758
35830
  }
35759
35831
  async stopSoundRecord() {
35832
+ var _a2;
35760
35833
  if (!this.recordingInProgress && this.recordingChunks.length === 0) return;
35761
- this.recordingEndTime = Date.now() - this.examStartTime;
35834
+ this.recordingEndTime = Date.now() - (((_a2 = this.cameraRecorder.getStartTime()) == null ? void 0 : _a2.getTime()) || 0);
35762
35835
  if (this.optionsProctoring.proctoringType !== "REALTIME") return;
35763
35836
  const wavBlob = encodeToWav(this.recordingChunks, this.SAMPLE_RATE);
35764
35837
  const file = new File(
@@ -35988,6 +36061,7 @@ var ScreenRecorder = class {
35988
36061
  this.recordingStop && await this.recordingStop();
35989
36062
  }
35990
36063
  async saveOnSession(session) {
36064
+ if (isMobileDevice()) return;
35991
36065
  session.addRecording({
35992
36066
  device: "",
35993
36067
  file: new File(this.blobs, `EP_${session.id}_screen_0.webm`, {
@@ -36197,7 +36271,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36197
36271
  this.connection = null;
36198
36272
  this.context = context;
36199
36273
  this.onRealtimeAlertsCallback = onRealtimeAlertsCallback;
36200
- console.log("context -> ", context);
36201
36274
  this.backend = new BackendService({
36202
36275
  type: (context == null ? void 0 : context.type) || "prod",
36203
36276
  token: context.token
@@ -36211,7 +36284,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36211
36284
  try {
36212
36285
  this.transmissionOk = false;
36213
36286
  const response = await this.backend.externalCameraCheckTransmission("" + this.externalSessionId);
36214
- console.log(response);
36215
36287
  let attempts = 0;
36216
36288
  while (!this.transmissionOk && attempts <= 5) {
36217
36289
  await new Promise((resolve) => setTimeout(resolve, 2e3));
@@ -36228,16 +36300,13 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36228
36300
  try {
36229
36301
  this.proctoringId = proctoringId2;
36230
36302
  const response = await this.backend.externalCameraStartTransmission("" + this.externalSessionId, proctoringId2);
36231
- console.log(response);
36232
36303
  } catch (error) {
36233
- console.error("Erro ao iniciar transmiss\xE3o:", error);
36234
36304
  throw new Error("N\xE3o foi poss\xEDvel iniciar a transmiss\xE3o.");
36235
36305
  }
36236
36306
  }
36237
36307
  async goToPositionGuide() {
36238
36308
  try {
36239
36309
  const response = await this.backend.goToExternalCameraPositionStep("" + this.externalSessionId);
36240
- console.log(response);
36241
36310
  } catch (error) {
36242
36311
  console.error("Erro ao enviar comando de Position:", error);
36243
36312
  throw new Error("N\xE3o foi poss\xEDvel enviar comando de Position Guide.");
@@ -36247,7 +36316,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36247
36316
  if (this.connection) {
36248
36317
  const actionMessage = new ActionMessage();
36249
36318
  actionMessage.command = "Reset";
36250
- console.log("Enviando comando 'Reset' para o aplicativo...");
36251
36319
  this.connection.invoke(
36252
36320
  "SendAction",
36253
36321
  this.externalSessionId,
@@ -36261,7 +36329,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36261
36329
  this.onTakePictureCallback = onTakePictureCallback;
36262
36330
  const actionMessage = new ActionMessage();
36263
36331
  actionMessage.command = "Capture";
36264
- console.log("Enviando comando 'Capture' para o aplicativo...");
36265
36332
  this.connection.invoke(
36266
36333
  "SendAction",
36267
36334
  this.externalSessionId,
@@ -36280,7 +36347,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36280
36347
  await this.reset();
36281
36348
  const response = await this.backend.externalCameraStartSession();
36282
36349
  this.externalSessionId = response.externalSessionId;
36283
- console.log(this.externalSessionId);
36284
36350
  this.currentStep = 0 /* STARTED */;
36285
36351
  const pairingObject = {
36286
36352
  externalSessionId: this.externalSessionId,
@@ -36289,7 +36355,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36289
36355
  };
36290
36356
  const pairingDataString = JSON.stringify(pairingObject);
36291
36357
  this.qrCodeBase64Image = await import_qrcode.default.toDataURL(pairingDataString);
36292
- console.log(this.qrCodeBase64Image);
36293
36358
  return this.qrCodeBase64Image;
36294
36359
  } catch (error) {
36295
36360
  this.disconnectWebSocket();
@@ -36388,7 +36453,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36388
36453
  var _a2;
36389
36454
  const actionMessage = new ActionMessage();
36390
36455
  actionMessage.command = "Cancel";
36391
- console.log("Enviando comando 'Cancel' para o aplicativo...");
36392
36456
  (_a2 = this.connection) == null ? void 0 : _a2.invoke(
36393
36457
  "SendAction",
36394
36458
  this.externalSessionId,
@@ -36728,8 +36792,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36728
36792
  this.connection.on(
36729
36793
  "ReceiveMessage",
36730
36794
  (sessionId, messageStr) => {
36731
- console.log("sessionId: ", sessionId);
36732
- console.log("Message: ", messageStr);
36733
36795
  if (sessionId !== this.externalSessionId) {
36734
36796
  console.warn("Sess\xE3o diferente!");
36735
36797
  return;
@@ -36737,7 +36799,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36737
36799
  try {
36738
36800
  const messageKey = messageStr;
36739
36801
  const message = ExternalCameraStatusEnum[messageKey];
36740
- console.log("Mensagem -> ", message);
36741
36802
  this.handleWebSocketMessage(message);
36742
36803
  } catch (e3) {
36743
36804
  console.error("Erro ao processar mensagem do WebSocket:", e3);
@@ -36747,8 +36808,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36747
36808
  this.connection.on(
36748
36809
  "ReceiveAction",
36749
36810
  (sessionId, actionMessage) => {
36750
- console.log("sessionId: ", sessionId);
36751
- console.log("Message: ", actionMessage);
36752
36811
  if (sessionId !== this.externalSessionId) {
36753
36812
  console.warn("Sess\xE3o diferente!");
36754
36813
  return;
@@ -36762,7 +36821,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36762
36821
  );
36763
36822
  try {
36764
36823
  await this.connection.start();
36765
- console.log("Conectado ao Hub SignalR com sucesso!");
36766
36824
  } catch (err) {
36767
36825
  console.error("Falha ao conectar ou entrar no grupo do SignalR: ", err);
36768
36826
  throw new Error("N\xE3o foi poss\xEDvel conectar ao servi\xE7o em tempo real.");
@@ -36889,7 +36947,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
36889
36947
  if (this.connection) {
36890
36948
  try {
36891
36949
  await this.connection.stop();
36892
- console.log("Desconectado do SignalR.");
36893
36950
  } catch (err) {
36894
36951
  console.error("Erro ao desconectar do SignalR:", err);
36895
36952
  } finally {
@@ -37090,7 +37147,6 @@ var Proctoring = class {
37090
37147
  alertImageBase64: await this.allRecorders.cameraRecorder.getCurrentImageBase64(),
37091
37148
  retry: verifyCount < verifyMaxRetries - 1 ? true : false
37092
37149
  });
37093
- console.log("response stopRealtimeAlert", response);
37094
37150
  return response;
37095
37151
  } catch (error) {
37096
37152
  console.log("error stopRealtimeAlert", error);
@@ -37129,9 +37185,11 @@ var Proctoring = class {
37129
37185
  setDeviceCheckData(data) {
37130
37186
  this.deviceData = data;
37131
37187
  }
37132
- createRecorders(options = getDefaultProctoringOptions) {
37133
- var _a2, _b;
37188
+ async createRecorders(options = getDefaultProctoringOptions) {
37189
+ var _a2, _b, _c2;
37134
37190
  this.onChangeDevices();
37191
+ console.log("Creating recorders");
37192
+ await ((_a2 = this.recorder) == null ? void 0 : _a2.stopAll());
37135
37193
  const cameraRecorder = new CameraRecorder(
37136
37194
  {
37137
37195
  cameraId: this.sessionOptions.cameraId,
@@ -37153,8 +37211,8 @@ var Proctoring = class {
37153
37211
  this.context.token
37154
37212
  );
37155
37213
  const screenRecorder = this.sessionOptions.captureScreen ? new ScreenRecorder({
37156
- allowOnlyFirstMonitor: (_a2 = this.sessionOptions.allowOnlyFirstMonitor) != null ? _a2 : true,
37157
- allowMultipleMonitors: (_b = this.sessionOptions.allowMultipleMonitors) != null ? _b : true,
37214
+ allowOnlyFirstMonitor: (_b = this.sessionOptions.allowOnlyFirstMonitor) != null ? _b : true,
37215
+ allowMultipleMonitors: (_c2 = this.sessionOptions.allowMultipleMonitors) != null ? _c2 : true,
37158
37216
  screenRecorderOptions: this.sessionOptions.screenRecorderOptions,
37159
37217
  onStopSharingScreenCallback: () => this.onStopSharingScreenCallback(),
37160
37218
  onBufferSizeError: this.sessionOptions.onBufferSizeError,
@@ -37179,10 +37237,12 @@ var Proctoring = class {
37179
37237
  );
37180
37238
  const recorders = [
37181
37239
  cameraRecorder,
37182
- screenRecorder,
37240
+ noiseRecorder,
37183
37241
  alertRecorder
37184
37242
  ].filter(Boolean);
37185
- recorders.push(noiseRecorder);
37243
+ if (this.sessionOptions.proctoringType != "REALTIME" && screenRecorder) {
37244
+ recorders.push(screenRecorder);
37245
+ }
37186
37246
  this.recorder = new ProctoringRecorder(this.proctoringSession, recorders);
37187
37247
  return { cameraRecorder, screenRecorder, alertRecorder, noiseRecorder };
37188
37248
  }
@@ -37222,7 +37282,7 @@ var Proctoring = class {
37222
37282
  await this.repository.clear();
37223
37283
  }
37224
37284
  this.proctoringSession = new ProctoringSession();
37225
- this.allRecorders = this.createRecorders(this.sessionOptions);
37285
+ this.allRecorders = await this.createRecorders(this.sessionOptions);
37226
37286
  const startResponse = await this.backend.confirmStart(
37227
37287
  {
37228
37288
  clientId: this.context.clientId,
@@ -37249,7 +37309,13 @@ var Proctoring = class {
37249
37309
  this.allRecorders.cameraRecorder.setProctoringId(this.proctoringId);
37250
37310
  this.allRecorders.noiseRecorder.setProctoringId(this.proctoringId);
37251
37311
  this.proctoringSession.setProctoringId(this.proctoringId);
37252
- await this.recorder.startAll();
37312
+ try {
37313
+ console.log("Starting recorders");
37314
+ await this.recorder.startAll();
37315
+ } catch (error) {
37316
+ console.log("Starting recorders error:", error);
37317
+ throw error;
37318
+ }
37253
37319
  if (options == null ? void 0 : options.useSpyScan) {
37254
37320
  this.spyCam.setProctoringId(this.proctoringId);
37255
37321
  this.spyCam.startCheckSpyCam((_a2 = this.paramsConfig.spyScanInterval) != null ? _a2 : 5, {
@@ -37410,7 +37476,6 @@ Upload Services: ${uploaderServices}`,
37410
37476
  await this.backend.finishAndSendUrls(this.context).then((finishResponse) => {
37411
37477
  var _a2, _b, _c2, _d;
37412
37478
  trackers.registerFinish(this.proctoringSession.id, true, "");
37413
- console.log("finishResponse: ", finishResponse);
37414
37479
  options.onResultAvailable && options.onResultAvailable((_a2 = finishResponse == null ? void 0 : finishResponse.score) != null ? _a2 : 100, (_b = finishResponse == null ? void 0 : finishResponse.scoreThreshold) != null ? _b : 70, (_c2 = finishResponse == null ? void 0 : finishResponse.approved) != null ? _c2 : true, (_d = finishResponse == null ? void 0 : finishResponse.justification) != null ? _d : "");
37415
37480
  }).catch((error) => {
37416
37481
  trackers.registerFinish(
@@ -37539,7 +37604,6 @@ Error: ` + error
37539
37604
  return {
37540
37605
  cameraStream: this.allRecorders.cameraRecorder.cameraStream,
37541
37606
  // recorder (pause & resume)
37542
- // audioStream: this.allRecorders.audioRecorder.audioStream,
37543
37607
  _screenStream: (_a2 = this.allRecorders.screenRecorder) == null ? void 0 : _a2.screenStream
37544
37608
  };
37545
37609
  }