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/index.js CHANGED
@@ -26440,9 +26440,8 @@ var BaseDetection = class {
26440
26440
  this.createdVideo && this.video && document.body.removeChild(this.video);
26441
26441
  this.createdVideo = false;
26442
26442
  }
26443
- enableCam(cameraStream) {
26443
+ enableCam(cameraStream, delay = 1e4) {
26444
26444
  var _a2;
26445
- console.log("BaseDetection enableCam");
26446
26445
  if (!this.detector) {
26447
26446
  console.log("Wait! Detector not loaded yet.");
26448
26447
  return;
@@ -26468,7 +26467,11 @@ var BaseDetection = class {
26468
26467
  cameraStream && !this.video.srcObject && (this.video.srcObject = cameraStream);
26469
26468
  this.video.play();
26470
26469
  const that = this;
26471
- (_a2 = this.video) == null ? void 0 : _a2.addEventListener("loadeddata", () => that.predictWebcam());
26470
+ (_a2 = this.video) == null ? void 0 : _a2.addEventListener("loadeddata", () => {
26471
+ this.animationFrameId = setTimeout(() => {
26472
+ that.predictWebcam();
26473
+ }, delay);
26474
+ });
26472
26475
  const style = document.createElement("style");
26473
26476
  style.type = "text/css";
26474
26477
  style.innerHTML = `
@@ -26487,6 +26490,7 @@ var BaseDetection = class {
26487
26490
  console.log("BaseDetection enableCam OK");
26488
26491
  }
26489
26492
  async predictWebcam() {
26493
+ if (this.detecting == false) return;
26490
26494
  if (this.lastVideoTime === -1) {
26491
26495
  await this.detector.setOptions({ runningMode: "VIDEO" });
26492
26496
  }
@@ -26548,7 +26552,7 @@ var BaseDetection = class {
26548
26552
  case "person_ok":
26549
26553
  return "Pessoa detectada";
26550
26554
  case "cellphone_ok":
26551
- return "Nenhum celular detectadoa";
26555
+ return "Nenhum celular detectado";
26552
26556
  case "face_ok":
26553
26557
  return "Face detectada";
26554
26558
  case "ok_position_face_detected":
@@ -30804,12 +30808,12 @@ function setRecorderProctoringId(id) {
30804
30808
  }
30805
30809
  function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorCallback, audio = false) {
30806
30810
  let resolvePromise;
30807
- let stopped = false;
30808
30811
  let onBufferSizeInterval;
30809
30812
  let lastEvent;
30810
30813
  let bufferSize;
30811
30814
  bufferSize = 0;
30812
30815
  let startTime;
30816
+ let duration = 0;
30813
30817
  let recorderOptions = {
30814
30818
  // eslint-disable-next-line no-useless-escape
30815
30819
  mimeType: "video/webm",
@@ -30846,10 +30850,6 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30846
30850
  if (e3.data.size > 0) {
30847
30851
  buffer.push(e3.data);
30848
30852
  }
30849
- if (stopped) {
30850
- console.log("buildMediaRecorder ondataavailable stopped");
30851
- resolvePromise && resolvePromise();
30852
- }
30853
30853
  };
30854
30854
  return mediaRecorder2;
30855
30855
  }
@@ -30861,6 +30861,7 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30861
30861
  recorder2.onstart = () => {
30862
30862
  started = true;
30863
30863
  console.log("recorder onstart");
30864
+ startTime = new Date(Date.now());
30864
30865
  resolve();
30865
30866
  };
30866
30867
  recorder2.onerror = (ev) => {
@@ -30900,7 +30901,6 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30900
30901
  await startRecorder(mediaRecorder);
30901
30902
  if (mediaRecorder.state === "recording") {
30902
30903
  bufferSize = 0;
30903
- stopped = false;
30904
30904
  return;
30905
30905
  } else {
30906
30906
  console.log("Recorder n\xE3o est\xE1 em estado recording ap\xF3s start");
@@ -30919,9 +30919,13 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30919
30919
  resolvePromise = resolve;
30920
30920
  mediaRecorder.onstop = () => {
30921
30921
  console.log("recorder onstop");
30922
+ duration = Date.now() - startTime.getTime() || 0;
30923
+ console.log("duration no onstop", duration);
30924
+ resolvePromise && resolvePromise();
30922
30925
  };
30923
- stopped = true;
30924
30926
  mediaRecorder.stop();
30927
+ duration = Date.now() - startTime.getTime() || 0;
30928
+ console.log("duration imediatamente ap\xF3s mediaRecorder.stop()", duration);
30925
30929
  } else {
30926
30930
  console.log("stopRecording Recorder n\xE3o est\xE1 em estado recording");
30927
30931
  resolve();
@@ -30957,6 +30961,9 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30957
30961
  function getStartTime() {
30958
30962
  return startTime;
30959
30963
  }
30964
+ function getDuration() {
30965
+ return duration;
30966
+ }
30960
30967
  return {
30961
30968
  startRecording,
30962
30969
  stopRecording,
@@ -30964,7 +30971,8 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30964
30971
  resumeRecording,
30965
30972
  recorderOptions,
30966
30973
  getBufferSize,
30967
- getStartTime
30974
+ getStartTime,
30975
+ getDuration
30968
30976
  };
30969
30977
  }
30970
30978
 
@@ -31190,6 +31198,7 @@ var BROWSER_NOT_SUPPORTED = "browser_not_supported";
31190
31198
  var TOKEN_MISSING = "token_missing";
31191
31199
  var CREDENTIALS_MISSING = "credentials_missing";
31192
31200
  var SPY_SCAN_API_NOT_FOUND = "spy_scan_api_not_found";
31201
+ var SAFE_BROWSER_API_NOT_FOUND = "safe_browser_api_not_found";
31193
31202
  var EXTERNAL_CAMERA_NOT_STARTED = "external_camera_not_started";
31194
31203
 
31195
31204
  // src/modules/objectDetection.ts
@@ -31387,6 +31396,7 @@ var CameraRecorder = class {
31387
31396
  this.internalClonedStream = null;
31388
31397
  this.videoElement = null;
31389
31398
  this.duration = 0;
31399
+ this.stopped = false;
31390
31400
  this.currentRetries = 0;
31391
31401
  this.packageCount = 0;
31392
31402
  this.noiseWait = 20;
@@ -31563,7 +31573,8 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31563
31573
  resumeRecording,
31564
31574
  recorderOptions,
31565
31575
  getBufferSize,
31566
- getStartTime
31576
+ getStartTime,
31577
+ getDuration
31567
31578
  } = recorder(
31568
31579
  this.cameraStream,
31569
31580
  // streamToRecord,
@@ -31579,6 +31590,7 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31579
31590
  this.recorderOptions = recorderOptions;
31580
31591
  this.getBufferSize = getBufferSize;
31581
31592
  this.getStartTime = getStartTime;
31593
+ this.getDuration = getDuration;
31582
31594
  try {
31583
31595
  await new Promise((r3) => setTimeout(r3, 500));
31584
31596
  await this.recordingStart();
@@ -31594,6 +31606,7 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31594
31606
  throw error;
31595
31607
  }
31596
31608
  }
31609
+ this.stopped = false;
31597
31610
  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)) {
31598
31611
  await this.initializeDetectors();
31599
31612
  }
@@ -31611,8 +31624,9 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31611
31624
  console.log("Camera Recorder started OK");
31612
31625
  }
31613
31626
  async stopRecording() {
31614
- var _a2, _b, _c2, _d;
31627
+ var _a2, _b, _c2;
31615
31628
  console.log("Camera Recorder stopRecording");
31629
+ this.stopped = true;
31616
31630
  this.isCanvasLoopActive = false;
31617
31631
  this.faceDetection && this.faceDetection.detecting && this.faceDetection.stopDetection();
31618
31632
  this.objectDetection && this.objectDetection.detecting && this.objectDetection.stopDetection();
@@ -31621,7 +31635,7 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31621
31635
  this.volumeMeter && this.volumeMeter.stop();
31622
31636
  this.intervalNoiseDetection && clearInterval(this.intervalNoiseDetection);
31623
31637
  this.recordingStop && await this.recordingStop();
31624
- this.duration = Date.now() - ((_a2 = this.getStartTime()) == null ? void 0 : _a2.getTime()) || 0;
31638
+ this.duration = this.getDuration ? this.getDuration() : 0;
31625
31639
  try {
31626
31640
  if (this.animationFrameId) {
31627
31641
  cancelAnimationFrame(this.animationFrameId);
@@ -31639,14 +31653,14 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31639
31653
  this.hardwareStream = null;
31640
31654
  }
31641
31655
  if (this.videoElement) {
31642
- (_b = this.videoElement) == null ? void 0 : _b.remove();
31656
+ (_a2 = this.videoElement) == null ? void 0 : _a2.remove();
31643
31657
  this.videoElement = null;
31644
31658
  }
31645
31659
  if (this.video) {
31646
- (_c2 = this.video) == null ? void 0 : _c2.remove();
31660
+ (_b = this.video) == null ? void 0 : _b.remove();
31647
31661
  }
31648
31662
  if (this.canvas) {
31649
- (_d = this.canvas) == null ? void 0 : _d.remove();
31663
+ (_c2 = this.canvas) == null ? void 0 : _c2.remove();
31650
31664
  }
31651
31665
  } catch {
31652
31666
  console.error("Erro ao parar os streams de m\xEDdia.");
@@ -31792,8 +31806,8 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31792
31806
  type: ((_b = this.recorderOptions) == null ? void 0 : _b.mimeType) || "video/webm"
31793
31807
  });
31794
31808
  const fixedBlob = await (0, import_fix_webm_duration.default)(rawBlob, this.duration);
31795
- const file = new File(
31796
- [rawBlob],
31809
+ const fileWithDuration = new File(
31810
+ [fixedBlob],
31797
31811
  `EP_${session.id}_camera_0.webm`,
31798
31812
  { type: rawBlob.type }
31799
31813
  );
@@ -31804,7 +31818,7 @@ Setting: ${JSON.stringify(settings, null, 2)}`
31804
31818
 
31805
31819
  Video:
31806
31820
  ${JSON.stringify(this.recorderOptions)}`,
31807
- file,
31821
+ file: fileWithDuration,
31808
31822
  origin: "Camera" /* Camera */
31809
31823
  });
31810
31824
  }
@@ -33077,7 +33091,7 @@ var _DeviceCheckerService = class _DeviceCheckerService {
33077
33091
  videoDeviceInterface(stream4) {
33078
33092
  this.DeviceCheckerUI && this.DeviceCheckerUI.videoDeviceInterfaceUI(stream4);
33079
33093
  this.isUnderResolution();
33080
- this.faceDetection.enableCam(stream4);
33094
+ this.faceDetection.enableCam(stream4, 1e3);
33081
33095
  }
33082
33096
  audioDeviceInterface(stream4) {
33083
33097
  this.volumeMeter = new VolumeMeter(this.cameraRecorder.cameraStream);
@@ -36778,6 +36792,49 @@ var Auth = class {
36778
36792
  }
36779
36793
  };
36780
36794
 
36795
+ // src/new-flow/backend/SafeBrowserBackendService.ts
36796
+ var SafeBrowserBackendService = class {
36797
+ constructor() {
36798
+ this.baseUrl = "http://localhost:7485/Station/api";
36799
+ }
36800
+ async isAlive() {
36801
+ const paramsConfig = await this.makeRequestAxios({
36802
+ path: `/health`,
36803
+ method: "GET",
36804
+ jwt: this.token
36805
+ }).catch((error) => {
36806
+ throw "N\xE3o foi poss\xEDvel realizar a requisi\xE7\xE3o, tente novamente mais tarde";
36807
+ });
36808
+ return paramsConfig.data;
36809
+ }
36810
+ async setProctoringId(proctoringId2) {
36811
+ const paramsConfig = await this.makeRequestAxios({
36812
+ path: `/update-station/` + proctoringId2,
36813
+ method: "POST",
36814
+ jwt: this.token
36815
+ }).catch((error) => {
36816
+ throw "N\xE3o foi poss\xEDvel realizar a requisi\xE7\xE3o, tente novamente mais tarde";
36817
+ });
36818
+ return paramsConfig.data;
36819
+ }
36820
+ async makeRequestAxios(data) {
36821
+ const { path, method, body, jwt } = data;
36822
+ const resp = await axios_default.request({
36823
+ url: this.baseUrl + path,
36824
+ method,
36825
+ headers: {
36826
+ Authorization: `Bearer ${jwt}`,
36827
+ "Access-Control-Allow-Origin": "*"
36828
+ },
36829
+ data: body
36830
+ });
36831
+ if (resp.status >= 400) {
36832
+ throw "N\xE3o foi poss\xEDvel realizar a requisi\xE7\xE3o, tente novamente mais tarde";
36833
+ }
36834
+ return resp;
36835
+ }
36836
+ };
36837
+
36781
36838
  // src/proctoring/ExternalCameraChecker.ts
36782
36839
  var import_signalr = __toESM(require_cjs());
36783
36840
  var import_qrcode = __toESM(require_lib());
@@ -37692,6 +37749,7 @@ var Proctoring = class {
37692
37749
  async internalOnRealtimeAlerts(response) {
37693
37750
  if (this.sessionOptions.proctoringType === "REALTIME" && (response.type === "face_detection_on_stream" || response.type === "person_detection_on_stream" || response.type === "lost_focus" || response.type === "focus")) {
37694
37751
  if (response.status === "ALERT") {
37752
+ if (this.allRecorders.cameraRecorder.stopped) return;
37695
37753
  await this.backend.startRealtimeAlert({
37696
37754
  proctoringId: this.proctoringId,
37697
37755
  begin: response.begin,
@@ -37699,6 +37757,7 @@ var Proctoring = class {
37699
37757
  alert: this.convertRealtimeCategoryToAlertCategory(response.category)
37700
37758
  });
37701
37759
  } else if (response.status === "OK") {
37760
+ if (this.allRecorders.cameraRecorder.stopped && response.description !== "face_stop") return;
37702
37761
  await this.stopRealtimeAlert(response);
37703
37762
  }
37704
37763
  }
@@ -37781,7 +37840,7 @@ var Proctoring = class {
37781
37840
  recorders.push(screenRecorder);
37782
37841
  }
37783
37842
  this.recorder = new ProctoringRecorder(this.proctoringSession, recorders);
37784
- return { cameraRecorder, screenRecorder, alertRecorder, noiseRecorder };
37843
+ return { screenRecorder, alertRecorder, noiseRecorder, cameraRecorder };
37785
37844
  }
37786
37845
  async login() {
37787
37846
  var _a2;
@@ -37811,6 +37870,13 @@ var Proctoring = class {
37811
37870
  } catch (error) {
37812
37871
  throw SPY_SCAN_API_NOT_FOUND;
37813
37872
  }
37873
+ try {
37874
+ if (options == null ? void 0 : options.useSafeBrowserAPI) {
37875
+ await this.safeBrowserBackendService.isAlive();
37876
+ }
37877
+ } catch (error) {
37878
+ throw SAFE_BROWSER_API_NOT_FOUND;
37879
+ }
37814
37880
  if (this.state != "Stop" /* Stop */) {
37815
37881
  throw PROCTORING_ALREADY_STARTED;
37816
37882
  }
@@ -37846,6 +37912,13 @@ var Proctoring = class {
37846
37912
  this.allRecorders.cameraRecorder.setProctoringId(this.proctoringId);
37847
37913
  this.allRecorders.noiseRecorder.setProctoringId(this.proctoringId);
37848
37914
  this.proctoringSession.setProctoringId(this.proctoringId);
37915
+ try {
37916
+ if (options == null ? void 0 : options.useSafeBrowserAPI) {
37917
+ await this.safeBrowserBackendService.setProctoringId(this.proctoringId);
37918
+ }
37919
+ } catch (error) {
37920
+ throw SAFE_BROWSER_API_NOT_FOUND;
37921
+ }
37849
37922
  try {
37850
37923
  console.log("Starting recorders");
37851
37924
  await this.recorder.startAll();
@@ -38067,7 +38140,7 @@ Error: ` + error
38067
38140
  }
38068
38141
  }
38069
38142
  async initConfig(useGeolocation) {
38070
- var _a2;
38143
+ var _a2, _b;
38071
38144
  try {
38072
38145
  const paramsConfig = await this.backend.getParamsConfig(
38073
38146
  this.context
@@ -38099,6 +38172,9 @@ Error: ` + error
38099
38172
  onRealtimeAlertsCallback: (response) => this.onRealtimeAlertsCallback(response)
38100
38173
  });
38101
38174
  }
38175
+ if ((_b = this.sessionOptions) == null ? void 0 : _b.useSafeBrowserAPI) {
38176
+ this.safeBrowserBackendService = new SafeBrowserBackendService();
38177
+ }
38102
38178
  } catch (err) {
38103
38179
  this.proctoringId && trackers.registerError(this.proctoringId, "Erro no initConfig!");
38104
38180
  await this.cancel();
@@ -22,7 +22,7 @@ export declare class BaseDetection {
22
22
  }, paramsConfig?: IParamsConfig, classVideo?: string, classDiv?: string);
23
23
  initializeDetector(): Promise<void>;
24
24
  stopDetection(): void;
25
- enableCam(cameraStream?: MediaProvider | null | undefined): void;
25
+ enableCam(cameraStream?: MediaProvider | null | undefined, delay?: number): void;
26
26
  lastVideoTime: number;
27
27
  lastExecutionDate: number;
28
28
  predictWebcam(): Promise<void>;
@@ -0,0 +1,13 @@
1
+ export declare class SafeBrowserBackendService {
2
+ private readonly baseUrl;
3
+ token: string;
4
+ constructor();
5
+ isAlive(): Promise<boolean>;
6
+ setProctoringId(proctoringId: string): Promise<any>;
7
+ makeRequestAxios<R>(data: {
8
+ path: string;
9
+ method: "GET" | "POST" | "PUT";
10
+ body?: any;
11
+ jwt: string;
12
+ }): Promise<R>;
13
+ }
@@ -38,6 +38,7 @@ export declare class CameraRecorder implements IRecorder {
38
38
  private internalClonedStream;
39
39
  private videoElement;
40
40
  private duration;
41
+ stopped: boolean;
41
42
  constructor(options: {
42
43
  cameraId?: string;
43
44
  microphoneId?: string;
@@ -54,6 +55,7 @@ export declare class CameraRecorder implements IRecorder {
54
55
  recordingResume: () => any;
55
56
  getBufferSize: () => any;
56
57
  getStartTime: () => any;
58
+ getDuration: () => any;
57
59
  setProctoringId(proctoringId: string): void;
58
60
  initializeDetectors(): Promise<void>;
59
61
  configImageCapture(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easyproctor",
3
- "version": "2.5.8",
3
+ "version": "2.6.0",
4
4
  "description": "Modulo web de gravação do EasyProctor",
5
5
  "main": "./index.js",
6
6
  "module": "./esm/index.js",
@@ -7,4 +7,5 @@ export default function recorder(stream: MediaStream, buffer: Blob[], onBufferSi
7
7
  recorderOptions: MediaRecorderOptions;
8
8
  getBufferSize: () => number;
9
9
  getStartTime: () => Date | undefined;
10
+ getDuration: () => number;
10
11
  };
@@ -12,6 +12,7 @@ export interface ProctoringSessionOptions {
12
12
  useSpyScan?: boolean;
13
13
  useExternalCamera?: boolean;
14
14
  useChallenge?: boolean;
15
+ useSafeBrowserAPI?: boolean;
15
16
  screenRecorderOptions?: {
16
17
  width: number;
17
18
  height: number;
@@ -54,6 +54,7 @@ export declare class Proctoring {
54
54
  private recorder;
55
55
  private allRecorders;
56
56
  private spyCam;
57
+ private safeBrowserBackendService;
57
58
  appChecker: ExternalCameraChecker;
58
59
  private verifyFirstFaceInterval;
59
60
  private onStopSharingScreenCallback;