easyproctor 2.5.8 → 2.6.0

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/README.md CHANGED
@@ -264,6 +264,9 @@ const {
264
264
  });
265
265
  ```
266
266
 
267
+ ## Release Note V 2.6.0
268
+ - Implementação da comunicação entre componente e navegador seguro
269
+
267
270
  ## Release Note V 2.5.8
268
271
  - removendo fechamento do webm com a duração para refinamento
269
272
 
@@ -16,6 +16,7 @@ export declare const TOKEN_MISSING = "token_missing";
16
16
  export declare const CREDENTIALS_MISSING = "credentials_missing";
17
17
  export declare const CAMERA_BLOCKED = "camera_blocked";
18
18
  export declare const SPY_SCAN_API_NOT_FOUND = "spy_scan_api_not_found";
19
+ export declare const SAFE_BROWSER_API_NOT_FOUND = "safe_browser_api_not_found";
19
20
  export declare const ERROR_ON_MOBILE_APP_NOT_FOUND = "error_on_mobile_app_not_found";
20
21
  export declare const EXTERNAL_CAMERA_NOT_STARTED = "external_camera_not_started";
21
22
  export declare const EXTERNAL_CAMERA_CHECK_TRANSMISSION = "external_camera_timed_out";
package/esm/index.js CHANGED
@@ -9155,9 +9155,8 @@ var BaseDetection = class {
9155
9155
  this.createdVideo && this.video && document.body.removeChild(this.video);
9156
9156
  this.createdVideo = false;
9157
9157
  }
9158
- enableCam(cameraStream) {
9158
+ enableCam(cameraStream, delay = 1e4) {
9159
9159
  var _a2;
9160
- console.log("BaseDetection enableCam");
9161
9160
  if (!this.detector) {
9162
9161
  console.log("Wait! Detector not loaded yet.");
9163
9162
  return;
@@ -9183,7 +9182,11 @@ var BaseDetection = class {
9183
9182
  cameraStream && !this.video.srcObject && (this.video.srcObject = cameraStream);
9184
9183
  this.video.play();
9185
9184
  const that = this;
9186
- (_a2 = this.video) == null ? void 0 : _a2.addEventListener("loadeddata", () => that.predictWebcam());
9185
+ (_a2 = this.video) == null ? void 0 : _a2.addEventListener("loadeddata", () => {
9186
+ this.animationFrameId = setTimeout(() => {
9187
+ that.predictWebcam();
9188
+ }, delay);
9189
+ });
9187
9190
  const style = document.createElement("style");
9188
9191
  style.type = "text/css";
9189
9192
  style.innerHTML = `
@@ -9202,6 +9205,7 @@ var BaseDetection = class {
9202
9205
  console.log("BaseDetection enableCam OK");
9203
9206
  }
9204
9207
  async predictWebcam() {
9208
+ if (this.detecting == false) return;
9205
9209
  if (this.lastVideoTime === -1) {
9206
9210
  await this.detector.setOptions({ runningMode: "VIDEO" });
9207
9211
  }
@@ -9263,7 +9267,7 @@ var BaseDetection = class {
9263
9267
  case "person_ok":
9264
9268
  return "Pessoa detectada";
9265
9269
  case "cellphone_ok":
9266
- return "Nenhum celular detectadoa";
9270
+ return "Nenhum celular detectado";
9267
9271
  case "face_ok":
9268
9272
  return "Face detectada";
9269
9273
  case "ok_position_face_detected":
@@ -12707,12 +12711,12 @@ function setRecorderProctoringId(id) {
12707
12711
  }
12708
12712
  function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCallback, audio = false) {
12709
12713
  let resolvePromise;
12710
- let stopped = false;
12711
12714
  let onBufferSizeInterval;
12712
12715
  let lastEvent;
12713
12716
  let bufferSize;
12714
12717
  bufferSize = 0;
12715
12718
  let startTime;
12719
+ let duration = 0;
12716
12720
  let recorderOptions = {
12717
12721
  // eslint-disable-next-line no-useless-escape
12718
12722
  mimeType: "video/webm",
@@ -12749,10 +12753,6 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12749
12753
  if (e3.data.size > 0) {
12750
12754
  buffer.push(e3.data);
12751
12755
  }
12752
- if (stopped) {
12753
- console.log("buildMediaRecorder ondataavailable stopped");
12754
- resolvePromise && resolvePromise();
12755
- }
12756
12756
  };
12757
12757
  return mediaRecorder2;
12758
12758
  }
@@ -12764,6 +12764,7 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12764
12764
  recorder2.onstart = () => {
12765
12765
  started = true;
12766
12766
  console.log("recorder onstart");
12767
+ startTime = new Date(Date.now());
12767
12768
  resolve();
12768
12769
  };
12769
12770
  recorder2.onerror = (ev) => {
@@ -12803,7 +12804,6 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12803
12804
  await startRecorder(mediaRecorder);
12804
12805
  if (mediaRecorder.state === "recording") {
12805
12806
  bufferSize = 0;
12806
- stopped = false;
12807
12807
  return;
12808
12808
  } else {
12809
12809
  console.log("Recorder n\xE3o est\xE1 em estado recording ap\xF3s start");
@@ -12822,9 +12822,13 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12822
12822
  resolvePromise = resolve;
12823
12823
  mediaRecorder.onstop = () => {
12824
12824
  console.log("recorder onstop");
12825
+ duration = Date.now() - startTime.getTime() || 0;
12826
+ console.log("duration no onstop", duration);
12827
+ resolvePromise && resolvePromise();
12825
12828
  };
12826
- stopped = true;
12827
12829
  mediaRecorder.stop();
12830
+ duration = Date.now() - startTime.getTime() || 0;
12831
+ console.log("duration imediatamente ap\xF3s mediaRecorder.stop()", duration);
12828
12832
  } else {
12829
12833
  console.log("stopRecording Recorder n\xE3o est\xE1 em estado recording");
12830
12834
  resolve();
@@ -12860,6 +12864,9 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12860
12864
  function getStartTime() {
12861
12865
  return startTime;
12862
12866
  }
12867
+ function getDuration() {
12868
+ return duration;
12869
+ }
12863
12870
  return {
12864
12871
  startRecording,
12865
12872
  stopRecording,
@@ -12867,7 +12874,8 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12867
12874
  resumeRecording,
12868
12875
  recorderOptions,
12869
12876
  getBufferSize,
12870
- getStartTime
12877
+ getStartTime,
12878
+ getDuration
12871
12879
  };
12872
12880
  }
12873
12881
 
@@ -13093,6 +13101,7 @@ var BROWSER_NOT_SUPPORTED = "browser_not_supported";
13093
13101
  var TOKEN_MISSING = "token_missing";
13094
13102
  var CREDENTIALS_MISSING = "credentials_missing";
13095
13103
  var SPY_SCAN_API_NOT_FOUND = "spy_scan_api_not_found";
13104
+ var SAFE_BROWSER_API_NOT_FOUND = "safe_browser_api_not_found";
13096
13105
  var EXTERNAL_CAMERA_NOT_STARTED = "external_camera_not_started";
13097
13106
 
13098
13107
  // src/modules/objectDetection.ts
@@ -13290,6 +13299,7 @@ var CameraRecorder = class {
13290
13299
  this.internalClonedStream = null;
13291
13300
  this.videoElement = null;
13292
13301
  this.duration = 0;
13302
+ this.stopped = false;
13293
13303
  this.currentRetries = 0;
13294
13304
  this.packageCount = 0;
13295
13305
  this.noiseWait = 20;
@@ -13466,7 +13476,8 @@ Setting: ${JSON.stringify(settings, null, 2)}`
13466
13476
  resumeRecording,
13467
13477
  recorderOptions,
13468
13478
  getBufferSize,
13469
- getStartTime
13479
+ getStartTime,
13480
+ getDuration
13470
13481
  } = recorder(
13471
13482
  this.cameraStream,
13472
13483
  // streamToRecord,
@@ -13482,6 +13493,7 @@ Setting: ${JSON.stringify(settings, null, 2)}`
13482
13493
  this.recorderOptions = recorderOptions;
13483
13494
  this.getBufferSize = getBufferSize;
13484
13495
  this.getStartTime = getStartTime;
13496
+ this.getDuration = getDuration;
13485
13497
  try {
13486
13498
  await new Promise((r3) => setTimeout(r3, 500));
13487
13499
  await this.recordingStart();
@@ -13497,6 +13509,7 @@ Setting: ${JSON.stringify(settings, null, 2)}`
13497
13509
  throw error;
13498
13510
  }
13499
13511
  }
13512
+ this.stopped = false;
13500
13513
  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)) {
13501
13514
  await this.initializeDetectors();
13502
13515
  }
@@ -13514,8 +13527,9 @@ Setting: ${JSON.stringify(settings, null, 2)}`
13514
13527
  console.log("Camera Recorder started OK");
13515
13528
  }
13516
13529
  async stopRecording() {
13517
- var _a2, _b, _c2, _d;
13530
+ var _a2, _b, _c2;
13518
13531
  console.log("Camera Recorder stopRecording");
13532
+ this.stopped = true;
13519
13533
  this.isCanvasLoopActive = false;
13520
13534
  this.faceDetection && this.faceDetection.detecting && this.faceDetection.stopDetection();
13521
13535
  this.objectDetection && this.objectDetection.detecting && this.objectDetection.stopDetection();
@@ -13524,7 +13538,7 @@ Setting: ${JSON.stringify(settings, null, 2)}`
13524
13538
  this.volumeMeter && this.volumeMeter.stop();
13525
13539
  this.intervalNoiseDetection && clearInterval(this.intervalNoiseDetection);
13526
13540
  this.recordingStop && await this.recordingStop();
13527
- this.duration = Date.now() - ((_a2 = this.getStartTime()) == null ? void 0 : _a2.getTime()) || 0;
13541
+ this.duration = this.getDuration ? this.getDuration() : 0;
13528
13542
  try {
13529
13543
  if (this.animationFrameId) {
13530
13544
  cancelAnimationFrame(this.animationFrameId);
@@ -13542,14 +13556,14 @@ Setting: ${JSON.stringify(settings, null, 2)}`
13542
13556
  this.hardwareStream = null;
13543
13557
  }
13544
13558
  if (this.videoElement) {
13545
- (_b = this.videoElement) == null ? void 0 : _b.remove();
13559
+ (_a2 = this.videoElement) == null ? void 0 : _a2.remove();
13546
13560
  this.videoElement = null;
13547
13561
  }
13548
13562
  if (this.video) {
13549
- (_c2 = this.video) == null ? void 0 : _c2.remove();
13563
+ (_b = this.video) == null ? void 0 : _b.remove();
13550
13564
  }
13551
13565
  if (this.canvas) {
13552
- (_d = this.canvas) == null ? void 0 : _d.remove();
13566
+ (_c2 = this.canvas) == null ? void 0 : _c2.remove();
13553
13567
  }
13554
13568
  } catch (e3) {
13555
13569
  console.error("Erro ao parar os streams de m\xEDdia.");
@@ -13695,8 +13709,8 @@ Setting: ${JSON.stringify(settings, null, 2)}`
13695
13709
  type: ((_b = this.recorderOptions) == null ? void 0 : _b.mimeType) || "video/webm"
13696
13710
  });
13697
13711
  const fixedBlob = await (0, import_fix_webm_duration.default)(rawBlob, this.duration);
13698
- const file = new File(
13699
- [rawBlob],
13712
+ const fileWithDuration = new File(
13713
+ [fixedBlob],
13700
13714
  `EP_${session.id}_camera_0.webm`,
13701
13715
  { type: rawBlob.type }
13702
13716
  );
@@ -13707,7 +13721,7 @@ Setting: ${JSON.stringify(settings, null, 2)}`
13707
13721
 
13708
13722
  Video:
13709
13723
  ${JSON.stringify(this.recorderOptions)}`,
13710
- file,
13724
+ file: fileWithDuration,
13711
13725
  origin: "Camera" /* Camera */
13712
13726
  });
13713
13727
  }
@@ -14980,7 +14994,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
14980
14994
  videoDeviceInterface(stream) {
14981
14995
  this.DeviceCheckerUI && this.DeviceCheckerUI.videoDeviceInterfaceUI(stream);
14982
14996
  this.isUnderResolution();
14983
- this.faceDetection.enableCam(stream);
14997
+ this.faceDetection.enableCam(stream, 1e3);
14984
14998
  }
14985
14999
  audioDeviceInterface(stream) {
14986
15000
  this.volumeMeter = new VolumeMeter(this.cameraRecorder.cameraStream);
@@ -18681,6 +18695,49 @@ var Auth = class {
18681
18695
  }
18682
18696
  };
18683
18697
 
18698
+ // src/new-flow/backend/SafeBrowserBackendService.ts
18699
+ var SafeBrowserBackendService = class {
18700
+ constructor() {
18701
+ this.baseUrl = "http://localhost:7485/Station/api";
18702
+ }
18703
+ async isAlive() {
18704
+ const paramsConfig = await this.makeRequestAxios({
18705
+ path: `/health`,
18706
+ method: "GET",
18707
+ jwt: this.token
18708
+ }).catch((error) => {
18709
+ throw "N\xE3o foi poss\xEDvel realizar a requisi\xE7\xE3o, tente novamente mais tarde";
18710
+ });
18711
+ return paramsConfig.data;
18712
+ }
18713
+ async setProctoringId(proctoringId2) {
18714
+ const paramsConfig = await this.makeRequestAxios({
18715
+ path: `/update-station/` + proctoringId2,
18716
+ method: "POST",
18717
+ jwt: this.token
18718
+ }).catch((error) => {
18719
+ throw "N\xE3o foi poss\xEDvel realizar a requisi\xE7\xE3o, tente novamente mais tarde";
18720
+ });
18721
+ return paramsConfig.data;
18722
+ }
18723
+ async makeRequestAxios(data) {
18724
+ const { path, method, body, jwt } = data;
18725
+ const resp = await axios_default.request({
18726
+ url: this.baseUrl + path,
18727
+ method,
18728
+ headers: {
18729
+ Authorization: `Bearer ${jwt}`,
18730
+ "Access-Control-Allow-Origin": "*"
18731
+ },
18732
+ data: body
18733
+ });
18734
+ if (resp.status >= 400) {
18735
+ throw "N\xE3o foi poss\xEDvel realizar a requisi\xE7\xE3o, tente novamente mais tarde";
18736
+ }
18737
+ return resp;
18738
+ }
18739
+ };
18740
+
18684
18741
  // node_modules/@microsoft/signalr/dist/esm/Errors.js
18685
18742
  var HttpError = class extends Error {
18686
18743
  /** Constructs a new instance of {@link @microsoft/signalr.HttpError}.
@@ -22443,6 +22500,7 @@ var Proctoring = class {
22443
22500
  async internalOnRealtimeAlerts(response) {
22444
22501
  if (this.sessionOptions.proctoringType === "REALTIME" && (response.type === "face_detection_on_stream" || response.type === "person_detection_on_stream" || response.type === "lost_focus" || response.type === "focus")) {
22445
22502
  if (response.status === "ALERT") {
22503
+ if (this.allRecorders.cameraRecorder.stopped) return;
22446
22504
  await this.backend.startRealtimeAlert({
22447
22505
  proctoringId: this.proctoringId,
22448
22506
  begin: response.begin,
@@ -22450,6 +22508,7 @@ var Proctoring = class {
22450
22508
  alert: this.convertRealtimeCategoryToAlertCategory(response.category)
22451
22509
  });
22452
22510
  } else if (response.status === "OK") {
22511
+ if (this.allRecorders.cameraRecorder.stopped && response.description !== "face_stop") return;
22453
22512
  await this.stopRealtimeAlert(response);
22454
22513
  }
22455
22514
  }
@@ -22532,7 +22591,7 @@ var Proctoring = class {
22532
22591
  recorders.push(screenRecorder);
22533
22592
  }
22534
22593
  this.recorder = new ProctoringRecorder(this.proctoringSession, recorders);
22535
- return { cameraRecorder, screenRecorder, alertRecorder, noiseRecorder };
22594
+ return { screenRecorder, alertRecorder, noiseRecorder, cameraRecorder };
22536
22595
  }
22537
22596
  async login() {
22538
22597
  var _a2;
@@ -22562,6 +22621,13 @@ var Proctoring = class {
22562
22621
  } catch (error) {
22563
22622
  throw SPY_SCAN_API_NOT_FOUND;
22564
22623
  }
22624
+ try {
22625
+ if (options == null ? void 0 : options.useSafeBrowserAPI) {
22626
+ await this.safeBrowserBackendService.isAlive();
22627
+ }
22628
+ } catch (error) {
22629
+ throw SAFE_BROWSER_API_NOT_FOUND;
22630
+ }
22565
22631
  if (this.state != "Stop" /* Stop */) {
22566
22632
  throw PROCTORING_ALREADY_STARTED;
22567
22633
  }
@@ -22597,6 +22663,13 @@ var Proctoring = class {
22597
22663
  this.allRecorders.cameraRecorder.setProctoringId(this.proctoringId);
22598
22664
  this.allRecorders.noiseRecorder.setProctoringId(this.proctoringId);
22599
22665
  this.proctoringSession.setProctoringId(this.proctoringId);
22666
+ try {
22667
+ if (options == null ? void 0 : options.useSafeBrowserAPI) {
22668
+ await this.safeBrowserBackendService.setProctoringId(this.proctoringId);
22669
+ }
22670
+ } catch (error) {
22671
+ throw SAFE_BROWSER_API_NOT_FOUND;
22672
+ }
22600
22673
  try {
22601
22674
  console.log("Starting recorders");
22602
22675
  await this.recorder.startAll();
@@ -22818,7 +22891,7 @@ Error: ` + error
22818
22891
  }
22819
22892
  }
22820
22893
  async initConfig(useGeolocation) {
22821
- var _a2;
22894
+ var _a2, _b;
22822
22895
  try {
22823
22896
  const paramsConfig = await this.backend.getParamsConfig(
22824
22897
  this.context
@@ -22850,6 +22923,9 @@ Error: ` + error
22850
22923
  onRealtimeAlertsCallback: (response) => this.onRealtimeAlertsCallback(response)
22851
22924
  });
22852
22925
  }
22926
+ if ((_b = this.sessionOptions) == null ? void 0 : _b.useSafeBrowserAPI) {
22927
+ this.safeBrowserBackendService = new SafeBrowserBackendService();
22928
+ }
22853
22929
  } catch (err) {
22854
22930
  this.proctoringId && trackers.registerError(this.proctoringId, "Erro no initConfig!");
22855
22931
  await this.cancel();