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/esm/index.js CHANGED
@@ -8693,7 +8693,6 @@ var BaseDetection = class {
8693
8693
  }
8694
8694
  cameraStream && !this.video.srcObject && (this.video.srcObject = cameraStream);
8695
8695
  this.video.play();
8696
- this.startTime = new Date(Date.now());
8697
8696
  const that = this;
8698
8697
  (_a2 = this.video) == null ? void 0 : _a2.addEventListener("loadeddata", () => that.predictWebcam());
8699
8698
  const style = document.createElement("style");
@@ -8736,8 +8735,8 @@ var BaseDetection = class {
8736
8735
  description: this.alertTranslate(description),
8737
8736
  type,
8738
8737
  category: description,
8739
- begin: Date.now() - this.startTime.getTime(),
8740
- end: Date.now() - this.startTime.getTime()
8738
+ begin: 0,
8739
+ end: 0
8741
8740
  });
8742
8741
  if (this.options.onRealtimeAlertsCallback == null)
8743
8742
  this.error && (this.error.innerText = description);
@@ -8748,8 +8747,8 @@ var BaseDetection = class {
8748
8747
  description: this.alertTranslate(description),
8749
8748
  type,
8750
8749
  category: description,
8751
- begin: Date.now() - this.startTime.getTime(),
8752
- end: Date.now() - this.startTime.getTime()
8750
+ begin: 0,
8751
+ end: 0
8753
8752
  });
8754
8753
  this.error && (this.error.innerText = "");
8755
8754
  }
@@ -12209,46 +12208,6 @@ function isMobileDevice() {
12209
12208
  return /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
12210
12209
  }
12211
12210
 
12212
- // src/plugins/insights.ts
12213
- var backendService;
12214
- var init = (backend) => {
12215
- backendService = backend;
12216
- return backendService;
12217
- };
12218
- var eventNames = {
12219
- DEVICES_CHECKED: "devices_checked",
12220
- START: "start",
12221
- FINISH: "finish",
12222
- ERROR: "error",
12223
- UPLOAD: "upload",
12224
- UPLOAD_FILE: "upload_file",
12225
- DOWNLOAD_VIDEO: "download_video",
12226
- BUFFER_SIZE: "buffer_size",
12227
- ANOTHER_STREAM: "another_stream",
12228
- CHANGE_DEVICE: "change_device",
12229
- STOP_SHARING_SCREEN: "stop_sharing_screen",
12230
- ERROR_RECORDER_RTC: "error_recorder_rtc",
12231
- BROWSER_NOT_SUPPORTED: "browser_not_supported",
12232
- SAVE_ON_SESSION: "save_on_session"
12233
- };
12234
- var log = (eventName, properties) => backendService && backendService.log(eventName, properties);
12235
- var trackers = {
12236
- registerDevicesChecked: (proctoringId2, success, description) => log(eventNames.DEVICES_CHECKED, { proctoringId: proctoringId2, success, description }),
12237
- registerStart: (proctoringId2, success, description) => log(eventNames.START, { proctoringId: proctoringId2, success, description }),
12238
- registerFinish: (proctoringId2, success, description) => log(eventNames.FINISH, { proctoringId: proctoringId2, success, description }),
12239
- registerError: (proctoringId2, description) => log(eventNames.ERROR, { proctoringId: proctoringId2, description }),
12240
- registerBrowserNotSupported: (proctoringId2, description) => log(eventNames.BROWSER_NOT_SUPPORTED, { proctoringId: proctoringId2, description }),
12241
- registerUpload: (proctoringId2, success, description, serviceType, uploadTime) => log(eventNames.UPLOAD, { proctoringId: proctoringId2, success, description, serviceType, uploadTime }),
12242
- registerUploadFile: (proctoringId2, description, fileType) => log(eventNames.UPLOAD_FILE, { proctoringId: proctoringId2, description, fileType }),
12243
- registerChangeDevice: (proctoringId2, inOrOut, description) => log(eventNames.CHANGE_DEVICE, { proctoringId: proctoringId2, inOrOut, description }),
12244
- registerStopSharingScreen: (proctoringId2, description) => log(eventNames.STOP_SHARING_SCREEN, { proctoringId: proctoringId2, description }),
12245
- registerErrorRecorderRTC: (proctoringId2, description) => log(eventNames.ERROR_RECORDER_RTC, { proctoringId: proctoringId2, description }),
12246
- registerDownloadFile: (proctoringId2, description) => log(eventNames.DOWNLOAD_VIDEO, { proctoringId: proctoringId2, description }),
12247
- registerOnBufferSizeError: (proctoringId2, description) => log(eventNames.BUFFER_SIZE, { proctoringId: proctoringId2, description }),
12248
- registerAnotherStream: (proctoringId2, description) => log(eventNames.ANOTHER_STREAM, { proctoringId: proctoringId2, description }),
12249
- registerSaveOnSession: (proctoringId2, description) => log(eventNames.SAVE_ON_SESSION, { proctoringId: proctoringId2, description })
12250
- };
12251
-
12252
12211
  // src/plugins/recorder.ts
12253
12212
  var proctoringId;
12254
12213
  function setRecorderProctoringId(id) {
@@ -12261,6 +12220,7 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12261
12220
  let lastEvent;
12262
12221
  let bufferSize;
12263
12222
  bufferSize = 0;
12223
+ let startTime;
12264
12224
  let recorderOptions = {
12265
12225
  // eslint-disable-next-line no-useless-escape
12266
12226
  mimeType: "video/webm",
@@ -12280,59 +12240,102 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12280
12240
  audioBitsPerSecond: 64 * 1e3
12281
12241
  };
12282
12242
  }
12283
- const mediaRecorder = new MediaRecorder(stream, recorderOptions);
12284
- mediaRecorder.ondataavailable = (e3) => {
12285
- bufferSize = bufferSize + e3.data.size;
12286
- if (e3.data.size > 0) {
12287
- buffer.push(e3.data);
12288
- }
12289
- if (!stopped) {
12290
- if (lastEvent && e3.data.size === lastEvent.data.size || e3.data.size === 0) {
12291
- proctoringId && lastEvent && e3.data.size === lastEvent.data.size && trackers.registerOnBufferSizeError(
12292
- proctoringId,
12293
- `onBufferSizeError: Recorder size freezed: ${e3.data.size} Mb`
12294
- );
12295
- proctoringId && e3.data.size === 0 && trackers.registerOnBufferSizeError(
12296
- proctoringId,
12297
- `onBufferSizeError: Recorder size equal 0 Mb`
12298
- );
12299
- onBufferSizeErrorCallback && onBufferSizeErrorCallback();
12243
+ function buildMediaRecorder(stream2, recorderOptions2) {
12244
+ const tracks = stream2.getTracks();
12245
+ if (tracks.length == 0) {
12246
+ throw new Error("No tracks found");
12247
+ }
12248
+ const invalidTracks = tracks.find((t3) => t3.readyState != "live");
12249
+ if (invalidTracks) {
12250
+ throw new Error("Track not live: " + invalidTracks.label);
12251
+ }
12252
+ console.log("buildMediaRecorder tracks OK");
12253
+ let mediaRecorder2 = new MediaRecorder(stream2, recorderOptions2);
12254
+ console.log("buildMediaRecorder mediaRecorder OK");
12255
+ mediaRecorder2.ondataavailable = (e3) => {
12256
+ bufferSize = bufferSize + e3.data.size;
12257
+ if (e3.data.size > 0) {
12258
+ buffer.push(e3.data);
12300
12259
  }
12301
- lastEvent = e3;
12302
- } else {
12303
- if (audio && mediaRecorder.state == "inactive") {
12304
- const blob = new Blob(buffer, { type: "audio/webm" });
12305
- buffer = [blob];
12260
+ if (stopped) {
12261
+ resolvePromise && resolvePromise();
12306
12262
  }
12307
- resolvePromise && resolvePromise();
12308
- }
12309
- };
12310
- function startRecording() {
12311
- return new Promise((resolve) => {
12312
- resolvePromise = resolve;
12313
- mediaRecorder.start();
12314
- bufferSize = 0;
12315
- stopped = false;
12316
- if (onBufferSizeError) {
12317
- onBufferSizeInterval = setInterval(async () => {
12318
- await mediaRecorder.requestData();
12319
- }, 3e4);
12263
+ };
12264
+ return mediaRecorder2;
12265
+ }
12266
+ let mediaRecorder = buildMediaRecorder(stream, recorderOptions);
12267
+ async function startRecorder(recorder2) {
12268
+ return new Promise((resolve, reject) => {
12269
+ var _a2, _b;
12270
+ let started = false;
12271
+ recorder2.onstart = () => {
12272
+ started = true;
12273
+ console.log("recorder onstart");
12274
+ resolve();
12275
+ };
12276
+ recorder2.onerror = (ev) => {
12277
+ console.error("Recorder error event:", ev);
12278
+ stream.getTracks().forEach((t3) => console.log(t3.readyState));
12279
+ if ("error" in ev) {
12280
+ const err = ev.error;
12281
+ console.error("Error name:", err == null ? void 0 : err.name);
12282
+ console.error("Error message:", err == null ? void 0 : err.message);
12283
+ reject(err || ev);
12284
+ } else {
12285
+ console.warn("Evento sem propriedade error");
12286
+ reject(ev);
12287
+ }
12288
+ };
12289
+ try {
12290
+ console.log("State antes do start:", recorder2.state);
12291
+ recorder2.start(1e4);
12292
+ startTime = new Date(Date.now());
12293
+ } catch (e3) {
12294
+ console.error("Recorder erro ao chamar start event:", e3);
12295
+ 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);
12296
+ console.error("Erro real 2:", e3, e3 == null ? void 0 : e3.message, e3 == null ? void 0 : e3.name);
12297
+ stream.getTracks().forEach((t3) => console.log(t3.readyState));
12298
+ return reject(e3);
12320
12299
  }
12300
+ setTimeout(() => {
12301
+ if (!started) {
12302
+ console.error("Timeout ao iniciar o recorder");
12303
+ reject(new Error("Timeout ao iniciar o recorder"));
12304
+ }
12305
+ }, 2e3);
12321
12306
  });
12322
12307
  }
12308
+ async function startRecording() {
12309
+ try {
12310
+ await startRecorder(mediaRecorder);
12311
+ if (mediaRecorder.state === "recording") {
12312
+ bufferSize = 0;
12313
+ stopped = false;
12314
+ return;
12315
+ } else {
12316
+ console.log("Recorder n\xE3o est\xE1 em estado recording ap\xF3s start");
12317
+ }
12318
+ } catch (e3) {
12319
+ console.error("Erro ao iniciar o recorder:", e3);
12320
+ await new Promise((r3) => setTimeout(r3, 300));
12321
+ throw e3;
12322
+ }
12323
+ return;
12324
+ }
12323
12325
  function stopRecording() {
12324
12326
  return new Promise((resolve) => {
12325
12327
  if (mediaRecorder.state == "recording") {
12328
+ console.log("stopRecording Recorder est\xE1 em estado recording, iniciando stop");
12326
12329
  resolvePromise = resolve;
12327
- mediaRecorder.stop();
12328
12330
  stopped = true;
12329
- clearInterval(onBufferSizeInterval);
12330
- stream.getTracks().forEach((el) => {
12331
- el.stop();
12332
- });
12331
+ mediaRecorder.stop();
12333
12332
  } else {
12333
+ console.log("stopRecording Recorder n\xE3o est\xE1 em estado recording");
12334
12334
  resolve();
12335
12335
  }
12336
+ stream.getTracks().forEach((el) => {
12337
+ el.stop();
12338
+ });
12336
12339
  });
12337
12340
  }
12338
12341
  function pauseRecording() {
@@ -12358,16 +12361,60 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12358
12361
  function getBufferSize() {
12359
12362
  return bufferSize;
12360
12363
  }
12364
+ function getStartTime() {
12365
+ return startTime;
12366
+ }
12361
12367
  return {
12362
12368
  startRecording,
12363
12369
  stopRecording,
12364
12370
  pauseRecording,
12365
12371
  resumeRecording,
12366
12372
  recorderOptions,
12367
- getBufferSize
12373
+ getBufferSize,
12374
+ getStartTime
12368
12375
  };
12369
12376
  }
12370
12377
 
12378
+ // src/plugins/insights.ts
12379
+ var backendService;
12380
+ var init = (backend) => {
12381
+ backendService = backend;
12382
+ return backendService;
12383
+ };
12384
+ var eventNames = {
12385
+ DEVICES_CHECKED: "devices_checked",
12386
+ START: "start",
12387
+ FINISH: "finish",
12388
+ ERROR: "error",
12389
+ UPLOAD: "upload",
12390
+ UPLOAD_FILE: "upload_file",
12391
+ DOWNLOAD_VIDEO: "download_video",
12392
+ BUFFER_SIZE: "buffer_size",
12393
+ ANOTHER_STREAM: "another_stream",
12394
+ CHANGE_DEVICE: "change_device",
12395
+ STOP_SHARING_SCREEN: "stop_sharing_screen",
12396
+ ERROR_RECORDER_RTC: "error_recorder_rtc",
12397
+ BROWSER_NOT_SUPPORTED: "browser_not_supported",
12398
+ SAVE_ON_SESSION: "save_on_session"
12399
+ };
12400
+ var log = (eventName, properties) => backendService && backendService.log(eventName, properties);
12401
+ var trackers = {
12402
+ registerDevicesChecked: (proctoringId2, success, description) => log(eventNames.DEVICES_CHECKED, { proctoringId: proctoringId2, success, description }),
12403
+ registerStart: (proctoringId2, success, description) => log(eventNames.START, { proctoringId: proctoringId2, success, description }),
12404
+ registerFinish: (proctoringId2, success, description) => log(eventNames.FINISH, { proctoringId: proctoringId2, success, description }),
12405
+ registerError: (proctoringId2, description) => log(eventNames.ERROR, { proctoringId: proctoringId2, description }),
12406
+ registerBrowserNotSupported: (proctoringId2, description) => log(eventNames.BROWSER_NOT_SUPPORTED, { proctoringId: proctoringId2, description }),
12407
+ registerUpload: (proctoringId2, success, description, serviceType, uploadTime) => log(eventNames.UPLOAD, { proctoringId: proctoringId2, success, description, serviceType, uploadTime }),
12408
+ registerUploadFile: (proctoringId2, description, fileType) => log(eventNames.UPLOAD_FILE, { proctoringId: proctoringId2, description, fileType }),
12409
+ registerChangeDevice: (proctoringId2, inOrOut, description) => log(eventNames.CHANGE_DEVICE, { proctoringId: proctoringId2, inOrOut, description }),
12410
+ registerStopSharingScreen: (proctoringId2, description) => log(eventNames.STOP_SHARING_SCREEN, { proctoringId: proctoringId2, description }),
12411
+ registerErrorRecorderRTC: (proctoringId2, description) => log(eventNames.ERROR_RECORDER_RTC, { proctoringId: proctoringId2, description }),
12412
+ registerDownloadFile: (proctoringId2, description) => log(eventNames.DOWNLOAD_VIDEO, { proctoringId: proctoringId2, description }),
12413
+ registerOnBufferSizeError: (proctoringId2, description) => log(eventNames.BUFFER_SIZE, { proctoringId: proctoringId2, description }),
12414
+ registerAnotherStream: (proctoringId2, description) => log(eventNames.ANOTHER_STREAM, { proctoringId: proctoringId2, description }),
12415
+ registerSaveOnSession: (proctoringId2, description) => log(eventNames.SAVE_ON_SESSION, { proctoringId: proctoringId2, description })
12416
+ };
12417
+
12371
12418
  // src/new-flow/upload/UploadService.ts
12372
12419
  var UploadService = class {
12373
12420
  constructor(proctoringId2, backend) {
@@ -12653,12 +12700,12 @@ var VolumeMeter = class {
12653
12700
  async start(options = {}) {
12654
12701
  return new Promise((resolve, reject) => {
12655
12702
  try {
12656
- const audioContext = new AudioContext();
12657
- this.analyser = audioContext.createAnalyser();
12658
- const microphone = audioContext.createMediaStreamSource(this.stream);
12703
+ this.audioContext = new AudioContext();
12704
+ this.analyser = this.audioContext.createAnalyser();
12705
+ this.microphone = this.audioContext.createMediaStreamSource(this.stream);
12659
12706
  this.analyser.smoothingTimeConstant = 0.8;
12660
12707
  this.analyser.fftSize = 1024;
12661
- microphone.connect(this.analyser);
12708
+ this.microphone.connect(this.analyser);
12662
12709
  const processAudio = () => {
12663
12710
  const array = new Uint8Array(this.analyser.frequencyBinCount);
12664
12711
  this.analyser.getByteFrequencyData(array);
@@ -12677,9 +12724,13 @@ var VolumeMeter = class {
12677
12724
  });
12678
12725
  }
12679
12726
  stop() {
12727
+ var _a2, _b, _c2;
12680
12728
  if (this.animationFrameId !== null) {
12681
12729
  cancelAnimationFrame(this.animationFrameId);
12682
12730
  }
12731
+ (_a2 = this.audioContext) == null ? void 0 : _a2.close();
12732
+ (_b = this.microphone) == null ? void 0 : _b.disconnect();
12733
+ (_c2 = this.analyser) == null ? void 0 : _c2.disconnect();
12683
12734
  }
12684
12735
  getVolume() {
12685
12736
  return this.volume;
@@ -12740,6 +12791,7 @@ var CameraRecorder = class {
12740
12791
  this.isCanvasLoopActive = false;
12741
12792
  this.hardwareStream = null;
12742
12793
  this.internalClonedStream = null;
12794
+ this.videoElement = null;
12743
12795
  this.currentRetries = 0;
12744
12796
  this.packageCount = 0;
12745
12797
  this.noiseWait = 20;
@@ -12760,7 +12812,12 @@ var CameraRecorder = class {
12760
12812
  if (((_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.detectPerson) || ((_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.detectCellPhone)) {
12761
12813
  this.objectDetection = new ObjectDetection(
12762
12814
  {
12763
- onRealtimeAlertsCallback: (response) => this.options.onRealtimeAlertsCallback(response)
12815
+ onRealtimeAlertsCallback: (response) => {
12816
+ var _a3, _b2;
12817
+ response.begin = Date.now() - (((_a3 = this.getStartTime()) == null ? void 0 : _a3.getTime()) || 0);
12818
+ response.end = Date.now() - (((_b2 = this.getStartTime()) == null ? void 0 : _b2.getTime()) || 0);
12819
+ this.options.onRealtimeAlertsCallback(response);
12820
+ }
12764
12821
  },
12765
12822
  this.paramsConfig
12766
12823
  );
@@ -12769,7 +12826,12 @@ var CameraRecorder = class {
12769
12826
  if ((_c2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _c2.detectFace) {
12770
12827
  this.faceDetection = new FaceDetection(
12771
12828
  {
12772
- onRealtimeAlertsCallback: (response) => this.options.onRealtimeAlertsCallback(response)
12829
+ onRealtimeAlertsCallback: (response) => {
12830
+ var _a3, _b2;
12831
+ response.begin = Date.now() - (((_a3 = this.getStartTime()) == null ? void 0 : _a3.getTime()) || 0);
12832
+ response.end = Date.now() - (((_b2 = this.getStartTime()) == null ? void 0 : _b2.getTime()) || 0);
12833
+ this.options.onRealtimeAlertsCallback(response);
12834
+ }
12773
12835
  },
12774
12836
  this.paramsConfig
12775
12837
  );
@@ -12795,25 +12857,20 @@ var CameraRecorder = class {
12795
12857
  }
12796
12858
  async bufferError(e3) {
12797
12859
  var _a2, _b;
12798
- console.log("buffer error Camera Recorder params " + this.paramsConfig.videoBehaviourParameters);
12860
+ console.log("buffer error Camera Recorder params ");
12799
12861
  const retryEnabled = ((_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.retryEnabled) || false;
12800
12862
  const maxRetries = ((_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.maxRetries) || 3;
12801
12863
  if (retryEnabled && this.currentRetries < maxRetries) {
12802
12864
  await this.recordingStop();
12803
- await this.startRecording({
12804
- retry: true
12805
- });
12865
+ await this.startRecording();
12806
12866
  this.currentRetries++;
12807
12867
  this.options.onBufferSizeErrorCallback && this.options.onBufferSizeErrorCallback(this.cameraStream);
12808
12868
  } else {
12809
12869
  this.options.onBufferSizeErrorCallback && this.options.onBufferSizeErrorCallback();
12810
12870
  }
12811
12871
  }
12812
- async startRecording(options) {
12813
- var _a2, _b, _c2, _d, _e3, _f, _g, _h;
12814
- 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)) {
12815
- await this.initializeDetectors();
12816
- }
12872
+ async startStream() {
12873
+ var _a2;
12817
12874
  const { cameraId, microphoneId, onBufferSizeErrorCallback } = this.options;
12818
12875
  const constraints = {
12819
12876
  audio: { deviceId: microphoneId },
@@ -12837,13 +12894,81 @@ var CameraRecorder = class {
12837
12894
  const track = this.cameraStream.getVideoTracks()[0];
12838
12895
  const settings = track.getSettings();
12839
12896
  let { width = 0, height = 0 } = settings;
12897
+ const isPortrait = (_a2 = screen.orientation) == null ? void 0 : _a2.type.includes("portrait");
12898
+ if (isPortrait && isMobileDevice()) {
12899
+ if (this.videoOptions.width == height && this.videoOptions.height == width) {
12900
+ [width, height] = [height, width];
12901
+ }
12902
+ }
12903
+ if (this.videoOptions.minWidth > width || this.videoOptions.minHeight > height) {
12904
+ throw STREAM_UNDER_MINIMUM_PERMITTED;
12905
+ } else if (this.videoOptions.width !== width || this.videoOptions.height !== height) {
12906
+ trackers.registerAnotherStream(
12907
+ this.proctoringId,
12908
+ `Maybe have another stream active
12909
+ Video Options: ${JSON.stringify(
12910
+ this.videoOptions,
12911
+ null,
12912
+ 2
12913
+ )}
12914
+ Setting: ${JSON.stringify(settings, null, 2)}`
12915
+ );
12916
+ throw ANOTHER_STREAM_ACTIVE;
12917
+ }
12918
+ }
12919
+ async stopStream() {
12920
+ if (this.cameraStream) {
12921
+ this.cameraStream.getTracks().forEach((track) => track.stop());
12922
+ }
12923
+ if (this.internalClonedStream) {
12924
+ this.internalClonedStream.getTracks().forEach((track) => track.stop());
12925
+ this.internalClonedStream = null;
12926
+ }
12927
+ if (this.hardwareStream) {
12928
+ this.hardwareStream.getTracks().forEach((track) => track.stop());
12929
+ this.hardwareStream = null;
12930
+ }
12931
+ }
12932
+ async waitForVideoFlow() {
12933
+ return new Promise((resolve) => {
12934
+ const check = () => {
12935
+ var _a2;
12936
+ if (this.videoElement && ((_a2 = this.videoElement) == null ? void 0 : _a2.readyState) >= 3) return resolve();
12937
+ else requestAnimationFrame(check);
12938
+ };
12939
+ check();
12940
+ });
12941
+ }
12942
+ async attachAndWarmup(stream) {
12943
+ this.videoElement = document.createElement("video");
12944
+ this.videoElement.srcObject = stream;
12945
+ this.videoElement.muted = true;
12946
+ await this.videoElement.play().catch((e3) => {
12947
+ });
12948
+ await new Promise((resolve) => {
12949
+ var _a2;
12950
+ if (this.videoElement && ((_a2 = this.videoElement) == null ? void 0 : _a2.readyState) >= 1) return resolve();
12951
+ if (this.videoElement)
12952
+ this.videoElement.onloadedmetadata = () => resolve();
12953
+ });
12954
+ console.log("CameraRecorder checking metadata ok");
12955
+ await this.waitForVideoFlow();
12956
+ console.log("CameraRecorder waiting for video flow ok");
12957
+ await new Promise((r3) => setTimeout(r3, 300));
12958
+ }
12959
+ async startRecording() {
12960
+ var _a2, _b, _c2, _d, _e3, _f, _g;
12961
+ console.log("CameraRecorder startRecording");
12962
+ await this.startStream();
12963
+ await this.attachAndWarmup(this.cameraStream);
12840
12964
  const {
12841
12965
  startRecording,
12842
12966
  stopRecording,
12843
12967
  pauseRecording,
12844
12968
  resumeRecording,
12845
12969
  recorderOptions,
12846
- getBufferSize
12970
+ getBufferSize,
12971
+ getStartTime
12847
12972
  } = recorder(
12848
12973
  this.cameraStream,
12849
12974
  // streamToRecord,
@@ -12858,42 +12983,41 @@ var CameraRecorder = class {
12858
12983
  this.recordingResume = resumeRecording;
12859
12984
  this.recorderOptions = recorderOptions;
12860
12985
  this.getBufferSize = getBufferSize;
12861
- this.recordingStart();
12862
- const isPortrait = (_d = screen.orientation) == null ? void 0 : _d.type.includes("portrait");
12863
- if (isPortrait && isMobileDevice()) {
12864
- if (this.videoOptions.width == height && this.videoOptions.height == width) {
12865
- [width, height] = [height, width];
12986
+ this.getStartTime = getStartTime;
12987
+ try {
12988
+ await new Promise((r3) => setTimeout(r3, 500));
12989
+ await this.recordingStart();
12990
+ } catch (error) {
12991
+ console.log("Camera Recorder error", error);
12992
+ this.stopRecording();
12993
+ const maxRetries = ((_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.maxRetries) || 3;
12994
+ if (this.currentRetries < maxRetries) {
12995
+ console.log("Camera Recorder retry", this.currentRetries);
12996
+ this.currentRetries++;
12997
+ await this.startRecording();
12998
+ } else {
12999
+ throw error;
12866
13000
  }
12867
13001
  }
12868
- if (this.videoOptions.minWidth > width || this.videoOptions.minHeight > height) {
12869
- throw STREAM_UNDER_MINIMUM_PERMITTED;
12870
- } else if (this.videoOptions.width !== width || this.videoOptions.height !== height) {
12871
- trackers.registerAnotherStream(
12872
- this.proctoringId,
12873
- `Maybe have another stream active
12874
- Video Options: ${JSON.stringify(
12875
- this.videoOptions,
12876
- null,
12877
- 2
12878
- )}
12879
- Setting: ${JSON.stringify(settings, null, 2)}`
12880
- );
12881
- throw ANOTHER_STREAM_ACTIVE;
13002
+ 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)) {
13003
+ await this.initializeDetectors();
12882
13004
  }
12883
- ((_e3 = this.paramsConfig.imageBehaviourParameters) == null ? void 0 : _e3.useUploadImage) && this.options.proctoringType == "IMAGE" && this.photoShotsCycle();
12884
- if ((_f = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _f.detectFace) {
13005
+ if ((_e3 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _e3.detectFace) {
12885
13006
  await this.faceDetection.enableCam(this.cameraStream);
12886
13007
  }
12887
- if (((_g = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _g.detectPerson) || ((_h = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _h.detectCellPhone)) {
13008
+ if (((_f = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _f.detectPerson) || ((_g = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _g.detectCellPhone)) {
12888
13009
  await this.objectDetection.enableCam(this.cameraStream);
12889
13010
  }
12890
13011
  this.filesToUpload = [];
12891
13012
  if (this.options.proctoringType == "REALTIME") {
12892
- this.captureFrame();
13013
+ await this.startRealtimeCapture();
12893
13014
  }
12894
13015
  this.packageCount = 0;
13016
+ console.log("Camera Recorder started OK");
12895
13017
  }
12896
13018
  async stopRecording() {
13019
+ var _a2, _b, _c2;
13020
+ console.log("Camera Recorder stopRecording");
12897
13021
  this.isCanvasLoopActive = false;
12898
13022
  this.recordingStop && await this.recordingStop();
12899
13023
  try {
@@ -12912,6 +13036,16 @@ Setting: ${JSON.stringify(settings, null, 2)}`
12912
13036
  this.hardwareStream.getTracks().forEach((track) => track.stop());
12913
13037
  this.hardwareStream = null;
12914
13038
  }
13039
+ if (this.videoElement) {
13040
+ (_a2 = this.videoElement) == null ? void 0 : _a2.remove();
13041
+ this.videoElement = null;
13042
+ }
13043
+ if (this.video) {
13044
+ (_b = this.video) == null ? void 0 : _b.remove();
13045
+ }
13046
+ if (this.canvas) {
13047
+ (_c2 = this.canvas) == null ? void 0 : _c2.remove();
13048
+ }
12915
13049
  } catch (e3) {
12916
13050
  console.error("Erro ao parar os streams de m\xEDdia.");
12917
13051
  }
@@ -12932,35 +13066,6 @@ Setting: ${JSON.stringify(settings, null, 2)}`
12932
13066
  async resumeRecording() {
12933
13067
  await this.recordingResume();
12934
13068
  }
12935
- photoShotsCycle() {
12936
- let imageFile;
12937
- this.configImageCapture();
12938
- this.imageInterval = setInterval(async () => {
12939
- this.canvas.getContext("2d").drawImage(
12940
- this.video,
12941
- 0,
12942
- 0,
12943
- this.videoOptions.width,
12944
- this.videoOptions.height
12945
- );
12946
- const image_data_url = this.canvas.toDataURL("image/jpeg");
12947
- imageFile = await this.getFile(
12948
- image_data_url,
12949
- `${this.proctoringId}_${this.imageCount + 1}.jpg`,
12950
- "image/jpeg"
12951
- );
12952
- if (imageFile && this.upload && this.backendToken) {
12953
- this.upload.upload(
12954
- {
12955
- file: imageFile
12956
- },
12957
- this.backendToken,
12958
- true
12959
- );
12960
- this.imageCount++;
12961
- }
12962
- }, this.paramsConfig.imageBehaviourParameters.uploadInterval * 1e3);
12963
- }
12964
13069
  async getCurrentImageBase64() {
12965
13070
  if (!this.video || !this.canvas) {
12966
13071
  this.configImageCapture();
@@ -12991,30 +13096,35 @@ Setting: ${JSON.stringify(settings, null, 2)}`
12991
13096
  this.canvas.getContext("2d").drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
12992
13097
  return this.canvas.toDataURL("image/jpeg");
12993
13098
  }
12994
- // captura um frame a cada intervalo de tempo definido no paramsConfig.videoBehaviourParameters?.realtimeCaptureInterval!
12995
- captureFrame() {
12996
- var _a2, _b;
13099
+ async captureFrame() {
13100
+ var _a2;
12997
13101
  let imageFile;
12998
- this.configImageCapture();
12999
13102
  const packSize = (_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.realtimePackageSize;
13103
+ this.canvas.getContext("2d").drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
13104
+ const image_data_url = this.canvas.toDataURL("image/jpeg");
13105
+ if (this.proctoringId == void 0) return;
13106
+ if (packSize == this.imageCount) {
13107
+ this.imageCount = 0;
13108
+ const framesToSend = [...this.filesToUpload];
13109
+ this.sendPackage(framesToSend);
13110
+ await this.filesToUpload.splice(0, this.filesToUpload.length);
13111
+ }
13112
+ let imageName = `${this.proctoringId}_${this.imageCount + 1}.jpg`;
13113
+ imageFile = await this.getFile(image_data_url, imageName, "image/jpeg");
13114
+ if (imageFile && imageFile.size > 10 && packSize > 0) {
13115
+ this.filesToUpload.push(imageFile);
13116
+ this.imageCount++;
13117
+ }
13118
+ }
13119
+ // inicia a captura de um frame a cada intervalo de tempo definido no paramsConfig.videoBehaviourParameters?.realtimeCaptureInterval!
13120
+ async startRealtimeCapture() {
13121
+ var _a2;
13122
+ this.configImageCapture();
13000
13123
  this.imageCount = 0;
13124
+ await this.captureFrame();
13001
13125
  this.imageInterval = setInterval(async () => {
13002
- this.canvas.getContext("2d").drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
13003
- const image_data_url = this.canvas.toDataURL("image/jpeg");
13004
- if (this.proctoringId == void 0) return;
13005
- if (packSize == this.imageCount) {
13006
- this.imageCount = 0;
13007
- const framesToSend = [...this.filesToUpload];
13008
- this.sendPackage(framesToSend);
13009
- await this.filesToUpload.splice(0, this.filesToUpload.length);
13010
- }
13011
- let imageName = `${this.proctoringId}_${this.imageCount + 1}.jpg`;
13012
- imageFile = await this.getFile(image_data_url, imageName, "image/jpeg");
13013
- if (imageFile && imageFile.size > 10 && packSize > 0) {
13014
- this.filesToUpload.push(imageFile);
13015
- this.imageCount++;
13016
- }
13017
- }, ((_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.realtimeCaptureInterval) * 1e3);
13126
+ await this.captureFrame();
13127
+ }, ((_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.realtimeCaptureInterval) * 1e3);
13018
13128
  }
13019
13129
  // envia pacote de imagens
13020
13130
  async sendPackage(framesToSend) {
@@ -13022,7 +13132,7 @@ Setting: ${JSON.stringify(settings, null, 2)}`
13022
13132
  let pending = false;
13023
13133
  let undeliveredPackagesCount = 0;
13024
13134
  const packSize = (_a2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _a2.realtimePackageSize;
13025
- const packCaptureInterval = ((_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.realtimeCaptureInterval) + 1;
13135
+ const packCaptureInterval = (_b = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _b.realtimeCaptureInterval;
13026
13136
  if (this.upload && this.backendToken && !pending && this.filesToUpload.length > 0) {
13027
13137
  undeliveredPackagesCount = 0;
13028
13138
  pending = true;
@@ -14210,6 +14320,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
14210
14320
  return this.deviceCheckResult;
14211
14321
  }
14212
14322
  async runCheckDevicesFlow(options, _videoOptions, onModalConfirm, onModalCancel, onUpdate) {
14323
+ var _a2;
14213
14324
  if (_DeviceCheckerService.isModalOpen) {
14214
14325
  return Promise.reject("Modal j\xE1 est\xE1 aberto");
14215
14326
  }
@@ -14227,7 +14338,9 @@ var _DeviceCheckerService = class _DeviceCheckerService {
14227
14338
  options,
14228
14339
  _videoOptions
14229
14340
  );
14230
- this.checkSpyScan();
14341
+ if ((_a2 = this.options) == null ? void 0 : _a2.useSpyScan) {
14342
+ await this.checkSpyScan();
14343
+ }
14231
14344
  const returnData = { cameraStream: this.cameraRecorder.cameraStream };
14232
14345
  this.onUpdateCb = (e3) => onUpdate(e3);
14233
14346
  const resultPromise = new Promise(
@@ -14282,6 +14395,10 @@ var _DeviceCheckerService = class _DeviceCheckerService {
14282
14395
  if (_DeviceCheckerService.isModalOpen) {
14283
14396
  return Promise.reject();
14284
14397
  }
14398
+ this.allowedAmbient = false;
14399
+ this.allowedMicrophone = false;
14400
+ this.allowedAmbient = false;
14401
+ this.allowedPositionFace = false;
14285
14402
  _DeviceCheckerService.isModalOpen = true;
14286
14403
  this.DeviceCheckerUI = new DeviceCheckerUI(options, _videoOptions);
14287
14404
  try {
@@ -14319,8 +14436,8 @@ var _DeviceCheckerService = class _DeviceCheckerService {
14319
14436
  resolve(response);
14320
14437
  });
14321
14438
  } catch (error) {
14439
+ this.DeviceCheckerUI && this.DeviceCheckerUI.closeModal();
14322
14440
  this.closeCheckDevices();
14323
- this.DeviceCheckerUI.closeModal();
14324
14441
  return Promise.reject(error);
14325
14442
  }
14326
14443
  }
@@ -14391,7 +14508,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
14391
14508
  }
14392
14509
  async changeSelectedDevice({ cameraId, microphoneId }) {
14393
14510
  var _a2;
14394
- this.cameraRecorder.stopRecording && await this.cameraRecorder.stopRecording();
14511
+ this.cameraRecorder.stopStream && await this.cameraRecorder.stopStream();
14395
14512
  (_a2 = this.volumeMeter) == null ? void 0 : _a2.stop();
14396
14513
  this.faceDetection.stopDetection();
14397
14514
  this.cameraRecorder = new CameraRecorder(
@@ -14407,7 +14524,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
14407
14524
  height: this.videoOptions.height
14408
14525
  }
14409
14526
  );
14410
- await this.cameraRecorder.startRecording();
14527
+ await this.cameraRecorder.startStream();
14411
14528
  this.videoDeviceInterface(this.cameraRecorder.cameraStream);
14412
14529
  this.audioDeviceInterface(this.cameraRecorder.cameraStream);
14413
14530
  return {
@@ -14415,6 +14532,10 @@ var _DeviceCheckerService = class _DeviceCheckerService {
14415
14532
  };
14416
14533
  }
14417
14534
  async startCheckDevices(options = getDefaultProctoringOptions, _videoOptions) {
14535
+ this.allowedAmbient = false;
14536
+ this.allowedMicrophone = false;
14537
+ this.allowedAmbient = false;
14538
+ this.allowedPositionFace = false;
14418
14539
  this.DeviceCheckerUI && this.DeviceCheckerUI.setSelectOption(
14419
14540
  options,
14420
14541
  (e3) => this.changeSelectedDevice(e3)
@@ -14434,7 +14555,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
14434
14555
  height: this.videoOptions.height
14435
14556
  }
14436
14557
  );
14437
- await this.cameraRecorder.startRecording();
14558
+ await this.cameraRecorder.startStream();
14438
14559
  this.videoDeviceInterface(this.cameraRecorder.cameraStream);
14439
14560
  this.audioDeviceInterface(this.cameraRecorder.cameraStream);
14440
14561
  if (this.DeviceCheckerUI) {
@@ -14451,7 +14572,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
14451
14572
  this.faceDetection.stopDetection();
14452
14573
  (_a2 = this.volumeMeter) == null ? void 0 : _a2.stop();
14453
14574
  this.volumeMedia = Math.ceil(this.volumeSum / this.volumeCounter);
14454
- this.cameraRecorder.stopRecording && await this.cameraRecorder.stopRecording();
14575
+ this.cameraRecorder.stopStream && await this.cameraRecorder.stopStream();
14455
14576
  this.DeviceCheckerUI = void 0;
14456
14577
  this.onUpdateCb = void 0;
14457
14578
  }
@@ -14524,7 +14645,7 @@ var CapturePhoto = class {
14524
14645
  // height: 480,
14525
14646
  // }
14526
14647
  );
14527
- await this.cameraRecorder.startRecording();
14648
+ await this.cameraRecorder.startStream();
14528
14649
  cameraContainer.srcObject = this.cameraRecorder.cameraStream;
14529
14650
  cameraContainer.play();
14530
14651
  }
@@ -14764,7 +14885,7 @@ var CapturePhoto = class {
14764
14885
  });
14765
14886
  }
14766
14887
  async closeInterface() {
14767
- await this.cameraRecorder.stopRecording();
14888
+ await this.cameraRecorder.stopStream();
14768
14889
  const authPhoto = document.querySelector("#authPhoto");
14769
14890
  authPhoto == null ? void 0 : authPhoto.remove();
14770
14891
  }
@@ -15268,54 +15389,6 @@ var AlertRecorder = class {
15268
15389
  }
15269
15390
  };
15270
15391
 
15271
- // src/new-flow/recorders/AudioRecorder.ts
15272
- var AudioRecorder = class {
15273
- constructor(options, audioParams) {
15274
- this.blobs = [];
15275
- this.options = {
15276
- cameraId: void 0,
15277
- microphoneId: void 0
15278
- };
15279
- this.audioParams = {
15280
- recordingBitrate: 128
15281
- };
15282
- audioParams && (this.audioParams = audioParams);
15283
- options && (this.options = options);
15284
- }
15285
- async startRecording() {
15286
- const constraints = {
15287
- audio: { deviceId: this.options.microphoneId || "default" }
15288
- };
15289
- this.audioStream = await navigator.mediaDevices.getUserMedia(constraints);
15290
- const { startRecording, stopRecording, pauseRecording, resumeRecording } = recorder(this.audioStream, this.blobs, void 0, void 0, true);
15291
- this.recordingStart = startRecording;
15292
- this.recordingStop = stopRecording;
15293
- this.recordingPause = pauseRecording;
15294
- this.recordingResume = resumeRecording;
15295
- this.recordingStart();
15296
- }
15297
- async pauseRecording() {
15298
- }
15299
- async resumeRecording() {
15300
- }
15301
- async stopRecording() {
15302
- this.recordingStop && await this.recordingStop();
15303
- }
15304
- async saveOnSession(session, start, end) {
15305
- session.addRecording({
15306
- device: "",
15307
- file: new File(
15308
- this.blobs,
15309
- `EP_${session.id}_audio_${start && end && `${start}_${end}` || "0"}.webm`,
15310
- {
15311
- type: "audio/webm"
15312
- }
15313
- ),
15314
- origin: "Mic" /* Mic */
15315
- });
15316
- }
15317
- };
15318
-
15319
15392
  // node_modules/@mediapipe/tasks-audio/audio_bundle.mjs
15320
15393
  var t2 = "undefined" != typeof self ? self : {};
15321
15394
  function e2() {
@@ -17555,7 +17628,6 @@ var NoiseRecorder = class {
17555
17628
  this.recordingInProgress = false;
17556
17629
  this.recordIndex = 1;
17557
17630
  this.countLoopTimes = 0;
17558
- this.examStartTime = 0;
17559
17631
  this.recordingStartTime = 0;
17560
17632
  this.recordingEndTime = 0;
17561
17633
  this.isSpeech = false;
@@ -17582,12 +17654,7 @@ var NoiseRecorder = class {
17582
17654
  this.proctoringId && this.backend && (this.upload = new UploadService(this.proctoringId, this.backend));
17583
17655
  }
17584
17656
  async startRecording() {
17585
- this.examStartTime = Date.now();
17586
17657
  await this.createAudioClassifier();
17587
- this.audioRecorder = new AudioRecorder(
17588
- void 0,
17589
- this.paramsConfig.audioBehaviourParameters
17590
- );
17591
17658
  this.intervalNoiseDetection = setInterval(
17592
17659
  () => this.onNoiseDetectedRecord(),
17593
17660
  200
@@ -17599,6 +17666,7 @@ var NoiseRecorder = class {
17599
17666
  await this.stopSoundRecord();
17600
17667
  await this.volumeMeter && this.volumeMeter.stop();
17601
17668
  this.audioWorkletNode && this.audioWorkletNode.disconnect();
17669
+ this.context && this.context.close();
17602
17670
  }
17603
17671
  async pauseRecording() {
17604
17672
  }
@@ -17607,7 +17675,7 @@ var NoiseRecorder = class {
17607
17675
  async saveOnSession(session) {
17608
17676
  }
17609
17677
  async onNoiseDetectedRecord() {
17610
- var _a2, _b, _c2, _d;
17678
+ var _a2, _b, _c2, _d, _e3, _f, _g, _h, _i3;
17611
17679
  if (!this.volumeMeter && this.cameraRecorder.cameraStream) {
17612
17680
  this.volumeMeter = new VolumeMeter(this.cameraRecorder.cameraStream);
17613
17681
  this.volumeMeter.start().catch((e3) => {
@@ -17629,7 +17697,7 @@ var NoiseRecorder = class {
17629
17697
  this.recordingChunks = [...this.preRollBuffer];
17630
17698
  const totalSamplesInBuffer = this.preRollBuffer.reduce((acc, chunk) => acc + chunk.length, 0);
17631
17699
  const bufferDurationMs = totalSamplesInBuffer / this.SAMPLE_RATE * 1e3;
17632
- const triggerTime = Date.now() - this.examStartTime;
17700
+ const triggerTime = Date.now() - (((_c2 = this.cameraRecorder.getStartTime()) == null ? void 0 : _c2.getTime()) || 0);
17633
17701
  this.recordingStartTime = triggerTime - bufferDurationMs;
17634
17702
  if (this.recordingStartTime < 0) this.recordingStartTime = 0;
17635
17703
  } else if (this.recordingInProgress) {
@@ -17637,15 +17705,19 @@ var NoiseRecorder = class {
17637
17705
  const currentRecordDuration = Date.now() - this.recordingStartTime;
17638
17706
  if (silenceDuration >= this.SILENCE_THRESHOLD && currentRecordDuration >= 3e3 && this.countLoopTimes > 4) {
17639
17707
  await this.stopSoundRecord();
17640
- if (((_c2 = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _c2.detectNoise) && !this.isSpeech) {
17708
+ if (((_d = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _d.detectNoise) && !this.isSpeech) {
17641
17709
  this.onRealtimeAlertsCallback({
17710
+ begin: Date.now() - (((_e3 = this.cameraRecorder.getStartTime()) == null ? void 0 : _e3.getTime()) || 0),
17711
+ end: Date.now() - (((_f = this.cameraRecorder.getStartTime()) == null ? void 0 : _f.getTime()) || 0),
17642
17712
  status: "ALERT",
17643
17713
  description: "Barulho detectado",
17644
17714
  type: "audio_detection_on_stream"
17645
17715
  });
17646
17716
  }
17647
- if (((_d = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _d.detectSpeech) && this.isSpeech) {
17717
+ if (((_g = this.paramsConfig.videoBehaviourParameters) == null ? void 0 : _g.detectSpeech) && this.isSpeech) {
17648
17718
  this.onRealtimeAlertsCallback({
17719
+ begin: Date.now() - (((_h = this.cameraRecorder.getStartTime()) == null ? void 0 : _h.getTime()) || 0),
17720
+ end: Date.now() - (((_i3 = this.cameraRecorder.getStartTime()) == null ? void 0 : _i3.getTime()) || 0),
17649
17721
  status: "ALERT",
17650
17722
  description: "Fala detectada",
17651
17723
  type: "audio_detection_on_stream"
@@ -17660,8 +17732,9 @@ var NoiseRecorder = class {
17660
17732
  }
17661
17733
  }
17662
17734
  async stopSoundRecord() {
17735
+ var _a2;
17663
17736
  if (!this.recordingInProgress && this.recordingChunks.length === 0) return;
17664
- this.recordingEndTime = Date.now() - this.examStartTime;
17737
+ this.recordingEndTime = Date.now() - (((_a2 = this.cameraRecorder.getStartTime()) == null ? void 0 : _a2.getTime()) || 0);
17665
17738
  if (this.optionsProctoring.proctoringType !== "REALTIME") return;
17666
17739
  const wavBlob = encodeToWav(this.recordingChunks, this.SAMPLE_RATE);
17667
17740
  const file = new File(
@@ -17891,6 +17964,7 @@ var ScreenRecorder = class {
17891
17964
  this.recordingStop && await this.recordingStop();
17892
17965
  }
17893
17966
  async saveOnSession(session) {
17967
+ if (isMobileDevice()) return;
17894
17968
  session.addRecording({
17895
17969
  device: "",
17896
17970
  file: new File(this.blobs, `EP_${session.id}_screen_0.webm`, {
@@ -20948,7 +21022,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
20948
21022
  this.connection = null;
20949
21023
  this.context = context;
20950
21024
  this.onRealtimeAlertsCallback = onRealtimeAlertsCallback;
20951
- console.log("context -> ", context);
20952
21025
  this.backend = new BackendService({
20953
21026
  type: (context == null ? void 0 : context.type) || "prod",
20954
21027
  token: context.token
@@ -20962,7 +21035,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
20962
21035
  try {
20963
21036
  this.transmissionOk = false;
20964
21037
  const response = await this.backend.externalCameraCheckTransmission("" + this.externalSessionId);
20965
- console.log(response);
20966
21038
  let attempts = 0;
20967
21039
  while (!this.transmissionOk && attempts <= 5) {
20968
21040
  await new Promise((resolve) => setTimeout(resolve, 2e3));
@@ -20979,16 +21051,13 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
20979
21051
  try {
20980
21052
  this.proctoringId = proctoringId2;
20981
21053
  const response = await this.backend.externalCameraStartTransmission("" + this.externalSessionId, proctoringId2);
20982
- console.log(response);
20983
21054
  } catch (error) {
20984
- console.error("Erro ao iniciar transmiss\xE3o:", error);
20985
21055
  throw new Error("N\xE3o foi poss\xEDvel iniciar a transmiss\xE3o.");
20986
21056
  }
20987
21057
  }
20988
21058
  async goToPositionGuide() {
20989
21059
  try {
20990
21060
  const response = await this.backend.goToExternalCameraPositionStep("" + this.externalSessionId);
20991
- console.log(response);
20992
21061
  } catch (error) {
20993
21062
  console.error("Erro ao enviar comando de Position:", error);
20994
21063
  throw new Error("N\xE3o foi poss\xEDvel enviar comando de Position Guide.");
@@ -20998,7 +21067,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
20998
21067
  if (this.connection) {
20999
21068
  const actionMessage = new ActionMessage();
21000
21069
  actionMessage.command = "Reset";
21001
- console.log("Enviando comando 'Reset' para o aplicativo...");
21002
21070
  this.connection.invoke(
21003
21071
  "SendAction",
21004
21072
  this.externalSessionId,
@@ -21012,7 +21080,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
21012
21080
  this.onTakePictureCallback = onTakePictureCallback;
21013
21081
  const actionMessage = new ActionMessage();
21014
21082
  actionMessage.command = "Capture";
21015
- console.log("Enviando comando 'Capture' para o aplicativo...");
21016
21083
  this.connection.invoke(
21017
21084
  "SendAction",
21018
21085
  this.externalSessionId,
@@ -21031,7 +21098,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
21031
21098
  await this.reset();
21032
21099
  const response = await this.backend.externalCameraStartSession();
21033
21100
  this.externalSessionId = response.externalSessionId;
21034
- console.log(this.externalSessionId);
21035
21101
  this.currentStep = 0 /* STARTED */;
21036
21102
  const pairingObject = {
21037
21103
  externalSessionId: this.externalSessionId,
@@ -21040,7 +21106,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
21040
21106
  };
21041
21107
  const pairingDataString = JSON.stringify(pairingObject);
21042
21108
  this.qrCodeBase64Image = await import_qrcode.default.toDataURL(pairingDataString);
21043
- console.log(this.qrCodeBase64Image);
21044
21109
  return this.qrCodeBase64Image;
21045
21110
  } catch (error) {
21046
21111
  this.disconnectWebSocket();
@@ -21139,7 +21204,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
21139
21204
  var _a2;
21140
21205
  const actionMessage = new ActionMessage();
21141
21206
  actionMessage.command = "Cancel";
21142
- console.log("Enviando comando 'Cancel' para o aplicativo...");
21143
21207
  (_a2 = this.connection) == null ? void 0 : _a2.invoke(
21144
21208
  "SendAction",
21145
21209
  this.externalSessionId,
@@ -21479,8 +21543,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
21479
21543
  this.connection.on(
21480
21544
  "ReceiveMessage",
21481
21545
  (sessionId, messageStr) => {
21482
- console.log("sessionId: ", sessionId);
21483
- console.log("Message: ", messageStr);
21484
21546
  if (sessionId !== this.externalSessionId) {
21485
21547
  console.warn("Sess\xE3o diferente!");
21486
21548
  return;
@@ -21488,7 +21550,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
21488
21550
  try {
21489
21551
  const messageKey = messageStr;
21490
21552
  const message = ExternalCameraStatusEnum[messageKey];
21491
- console.log("Mensagem -> ", message);
21492
21553
  this.handleWebSocketMessage(message);
21493
21554
  } catch (e3) {
21494
21555
  console.error("Erro ao processar mensagem do WebSocket:", e3);
@@ -21498,8 +21559,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
21498
21559
  this.connection.on(
21499
21560
  "ReceiveAction",
21500
21561
  (sessionId, actionMessage) => {
21501
- console.log("sessionId: ", sessionId);
21502
- console.log("Message: ", actionMessage);
21503
21562
  if (sessionId !== this.externalSessionId) {
21504
21563
  console.warn("Sess\xE3o diferente!");
21505
21564
  return;
@@ -21513,7 +21572,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
21513
21572
  );
21514
21573
  try {
21515
21574
  await this.connection.start();
21516
- console.log("Conectado ao Hub SignalR com sucesso!");
21517
21575
  } catch (err) {
21518
21576
  console.error("Falha ao conectar ou entrar no grupo do SignalR: ", err);
21519
21577
  throw new Error("N\xE3o foi poss\xEDvel conectar ao servi\xE7o em tempo real.");
@@ -21640,7 +21698,6 @@ var _ExternalCameraChecker = class _ExternalCameraChecker {
21640
21698
  if (this.connection) {
21641
21699
  try {
21642
21700
  await this.connection.stop();
21643
- console.log("Desconectado do SignalR.");
21644
21701
  } catch (err) {
21645
21702
  console.error("Erro ao desconectar do SignalR:", err);
21646
21703
  } finally {
@@ -21841,7 +21898,6 @@ var Proctoring = class {
21841
21898
  alertImageBase64: await this.allRecorders.cameraRecorder.getCurrentImageBase64(),
21842
21899
  retry: verifyCount < verifyMaxRetries - 1 ? true : false
21843
21900
  });
21844
- console.log("response stopRealtimeAlert", response);
21845
21901
  return response;
21846
21902
  } catch (error) {
21847
21903
  console.log("error stopRealtimeAlert", error);
@@ -21880,9 +21936,11 @@ var Proctoring = class {
21880
21936
  setDeviceCheckData(data) {
21881
21937
  this.deviceData = data;
21882
21938
  }
21883
- createRecorders(options = getDefaultProctoringOptions) {
21884
- var _a2, _b;
21939
+ async createRecorders(options = getDefaultProctoringOptions) {
21940
+ var _a2, _b, _c2;
21885
21941
  this.onChangeDevices();
21942
+ console.log("Creating recorders");
21943
+ await ((_a2 = this.recorder) == null ? void 0 : _a2.stopAll());
21886
21944
  const cameraRecorder = new CameraRecorder(
21887
21945
  {
21888
21946
  cameraId: this.sessionOptions.cameraId,
@@ -21904,8 +21962,8 @@ var Proctoring = class {
21904
21962
  this.context.token
21905
21963
  );
21906
21964
  const screenRecorder = this.sessionOptions.captureScreen ? new ScreenRecorder({
21907
- allowOnlyFirstMonitor: (_a2 = this.sessionOptions.allowOnlyFirstMonitor) != null ? _a2 : true,
21908
- allowMultipleMonitors: (_b = this.sessionOptions.allowMultipleMonitors) != null ? _b : true,
21965
+ allowOnlyFirstMonitor: (_b = this.sessionOptions.allowOnlyFirstMonitor) != null ? _b : true,
21966
+ allowMultipleMonitors: (_c2 = this.sessionOptions.allowMultipleMonitors) != null ? _c2 : true,
21909
21967
  screenRecorderOptions: this.sessionOptions.screenRecorderOptions,
21910
21968
  onStopSharingScreenCallback: () => this.onStopSharingScreenCallback(),
21911
21969
  onBufferSizeError: this.sessionOptions.onBufferSizeError,
@@ -21930,10 +21988,12 @@ var Proctoring = class {
21930
21988
  );
21931
21989
  const recorders = [
21932
21990
  cameraRecorder,
21933
- screenRecorder,
21991
+ noiseRecorder,
21934
21992
  alertRecorder
21935
21993
  ].filter(Boolean);
21936
- recorders.push(noiseRecorder);
21994
+ if (this.sessionOptions.proctoringType != "REALTIME" && screenRecorder) {
21995
+ recorders.push(screenRecorder);
21996
+ }
21937
21997
  this.recorder = new ProctoringRecorder(this.proctoringSession, recorders);
21938
21998
  return { cameraRecorder, screenRecorder, alertRecorder, noiseRecorder };
21939
21999
  }
@@ -21973,7 +22033,7 @@ var Proctoring = class {
21973
22033
  await this.repository.clear();
21974
22034
  }
21975
22035
  this.proctoringSession = new ProctoringSession();
21976
- this.allRecorders = this.createRecorders(this.sessionOptions);
22036
+ this.allRecorders = await this.createRecorders(this.sessionOptions);
21977
22037
  const startResponse = await this.backend.confirmStart(
21978
22038
  {
21979
22039
  clientId: this.context.clientId,
@@ -22000,7 +22060,13 @@ var Proctoring = class {
22000
22060
  this.allRecorders.cameraRecorder.setProctoringId(this.proctoringId);
22001
22061
  this.allRecorders.noiseRecorder.setProctoringId(this.proctoringId);
22002
22062
  this.proctoringSession.setProctoringId(this.proctoringId);
22003
- await this.recorder.startAll();
22063
+ try {
22064
+ console.log("Starting recorders");
22065
+ await this.recorder.startAll();
22066
+ } catch (error) {
22067
+ console.log("Starting recorders error:", error);
22068
+ throw error;
22069
+ }
22004
22070
  if (options == null ? void 0 : options.useSpyScan) {
22005
22071
  this.spyCam.setProctoringId(this.proctoringId);
22006
22072
  this.spyCam.startCheckSpyCam((_a2 = this.paramsConfig.spyScanInterval) != null ? _a2 : 5, {
@@ -22161,7 +22227,6 @@ Upload Services: ${uploaderServices}`,
22161
22227
  await this.backend.finishAndSendUrls(this.context).then((finishResponse) => {
22162
22228
  var _a2, _b, _c2, _d;
22163
22229
  trackers.registerFinish(this.proctoringSession.id, true, "");
22164
- console.log("finishResponse: ", finishResponse);
22165
22230
  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 : "");
22166
22231
  }).catch((error) => {
22167
22232
  trackers.registerFinish(
@@ -22290,7 +22355,6 @@ Error: ` + error
22290
22355
  return {
22291
22356
  cameraStream: this.allRecorders.cameraRecorder.cameraStream,
22292
22357
  // recorder (pause & resume)
22293
- // audioStream: this.allRecorders.audioRecorder.audioStream,
22294
22358
  _screenStream: (_a2 = this.allRecorders.screenRecorder) == null ? void 0 : _a2.screenStream
22295
22359
  };
22296
22360
  }