easyproctor-hml 2.5.21 → 2.5.23

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
@@ -12167,7 +12167,10 @@ function validatePartialVideoOptions(options) {
12167
12167
  width: options.width,
12168
12168
  height: options.height,
12169
12169
  minWidth: options.minWidth,
12170
- minHeight: options.minHeight
12170
+ minHeight: options.minHeight,
12171
+ timeSlice: options.timeSlice,
12172
+ videoBitsPerSecond: options.videoBitsPerSecond,
12173
+ mimeType: options.mimeType
12171
12174
  };
12172
12175
  } else {
12173
12176
  return { width: 640, height: 480 };
@@ -12254,7 +12257,7 @@ var proctoringId;
12254
12257
  function setRecorderProctoringId(id) {
12255
12258
  proctoringId = id;
12256
12259
  }
12257
- function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCallback, audio = false) {
12260
+ function recorder(stream, buffer, videoOptions, onBufferSizeError = false, onBufferSizeErrorCallback, audio = false) {
12258
12261
  let resolvePromise;
12259
12262
  let stopped = false;
12260
12263
  let onBufferSizeInterval;
@@ -12274,15 +12277,28 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12274
12277
  "vp9 codec not supported. Using default mimeType without vp9."
12275
12278
  );
12276
12279
  }
12280
+ if (videoOptions == null ? void 0 : videoOptions.mimeType) {
12281
+ recorderOptions.mimeType = videoOptions == null ? void 0 : videoOptions.mimeType;
12282
+ }
12283
+ if ((videoOptions == null ? void 0 : videoOptions.videoBitsPerSecond) != void 0) {
12284
+ recorderOptions.videoBitsPerSecond = videoOptions == null ? void 0 : videoOptions.videoBitsPerSecond;
12285
+ }
12277
12286
  if (audio) {
12278
12287
  recorderOptions = {
12279
12288
  mimeType: "audio/webm",
12280
12289
  audioBitsPerSecond: 64 * 1e3
12281
12290
  };
12282
12291
  }
12292
+ console.log("recorderOptions bitsPerSecond", recorderOptions.bitsPerSecond);
12283
12293
  const mediaRecorder = new MediaRecorder(stream, recorderOptions);
12284
12294
  mediaRecorder.ondataavailable = (e3) => {
12285
12295
  bufferSize = bufferSize + e3.data.size;
12296
+ console.log("video tracks length > 0", stream.getVideoTracks().length > 0);
12297
+ if (stream.getVideoTracks().length > 0) {
12298
+ const videoTrack = stream.getVideoTracks()[0];
12299
+ console.log(videoTrack.readyState);
12300
+ console.log(videoTrack.enabled);
12301
+ }
12286
12302
  if (e3.data.size > 0) {
12287
12303
  buffer.push(e3.data);
12288
12304
  }
@@ -12296,6 +12312,7 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12296
12312
  proctoringId,
12297
12313
  `onBufferSizeError: Recorder size equal 0 Mb`
12298
12314
  );
12315
+ console.log("onbuffer size error");
12299
12316
  onBufferSizeErrorCallback && onBufferSizeErrorCallback();
12300
12317
  }
12301
12318
  lastEvent = e3;
@@ -12310,14 +12327,14 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12310
12327
  function startRecording() {
12311
12328
  return new Promise((resolve) => {
12312
12329
  resolvePromise = resolve;
12313
- mediaRecorder.start();
12330
+ var timeSlice = 1e4;
12331
+ if ((videoOptions == null ? void 0 : videoOptions.timeSlice) != void 0) {
12332
+ timeSlice = videoOptions == null ? void 0 : videoOptions.timeSlice;
12333
+ }
12334
+ console.log("startRecording", timeSlice);
12335
+ mediaRecorder.start(timeSlice);
12314
12336
  bufferSize = 0;
12315
12337
  stopped = false;
12316
- if (onBufferSizeError) {
12317
- onBufferSizeInterval = setInterval(async () => {
12318
- await mediaRecorder.requestData();
12319
- }, 3e4);
12320
- }
12321
12338
  });
12322
12339
  }
12323
12340
  function stopRecording() {
@@ -12326,7 +12343,6 @@ function recorder(stream, buffer, onBufferSizeError = false, onBufferSizeErrorCa
12326
12343
  resolvePromise = resolve;
12327
12344
  mediaRecorder.stop();
12328
12345
  stopped = true;
12329
- clearInterval(onBufferSizeInterval);
12330
12346
  stream.getTracks().forEach((el) => {
12331
12347
  el.stop();
12332
12348
  });
@@ -12809,6 +12825,66 @@ var CameraRecorder = class {
12809
12825
  this.options.onBufferSizeErrorCallback && this.options.onBufferSizeErrorCallback();
12810
12826
  }
12811
12827
  }
12828
+ async startStream(options) {
12829
+ var _a2;
12830
+ const { cameraId, microphoneId, onBufferSizeErrorCallback } = this.options;
12831
+ const constraints = {
12832
+ audio: { deviceId: microphoneId },
12833
+ video: {
12834
+ deviceId: cameraId,
12835
+ width: this.videoOptions.width,
12836
+ height: this.videoOptions.height,
12837
+ frameRate: 15
12838
+ }
12839
+ };
12840
+ try {
12841
+ this.hardwareStream = await navigator.mediaDevices.getUserMedia(
12842
+ constraints
12843
+ );
12844
+ } catch (error) {
12845
+ if (error.toString() == "NotReadableError: Could not start video source")
12846
+ throw "N\xE3o foi poss\xEDvel conectar a camera, ela pode estar sendo utilizada por outro programa";
12847
+ throw error;
12848
+ }
12849
+ this.cameraStream = this.hardwareStream;
12850
+ const track = this.cameraStream.getVideoTracks()[0];
12851
+ const settings = track.getSettings();
12852
+ let { width = 0, height = 0 } = settings;
12853
+ const isPortrait = (_a2 = screen.orientation) == null ? void 0 : _a2.type.includes("portrait");
12854
+ if (isPortrait && isMobileDevice()) {
12855
+ if (this.videoOptions.width == height && this.videoOptions.height == width) {
12856
+ [width, height] = [height, width];
12857
+ }
12858
+ }
12859
+ if (this.videoOptions.minWidth > width || this.videoOptions.minHeight > height) {
12860
+ throw STREAM_UNDER_MINIMUM_PERMITTED;
12861
+ } else if (this.videoOptions.width !== width || this.videoOptions.height !== height) {
12862
+ trackers.registerAnotherStream(
12863
+ this.proctoringId,
12864
+ `Maybe have another stream active
12865
+ Video Options: ${JSON.stringify(
12866
+ this.videoOptions,
12867
+ null,
12868
+ 2
12869
+ )}
12870
+ Setting: ${JSON.stringify(settings, null, 2)}`
12871
+ );
12872
+ throw ANOTHER_STREAM_ACTIVE;
12873
+ }
12874
+ }
12875
+ async stopStream() {
12876
+ if (this.cameraStream) {
12877
+ this.cameraStream.getTracks().forEach((track) => track.stop());
12878
+ }
12879
+ if (this.internalClonedStream) {
12880
+ this.internalClonedStream.getTracks().forEach((track) => track.stop());
12881
+ this.internalClonedStream = null;
12882
+ }
12883
+ if (this.hardwareStream) {
12884
+ this.hardwareStream.getTracks().forEach((track) => track.stop());
12885
+ this.hardwareStream = null;
12886
+ }
12887
+ }
12812
12888
  async startRecording(options) {
12813
12889
  var _a2, _b, _c2, _d, _e3, _f, _g, _h;
12814
12890
  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)) {
@@ -12848,6 +12924,7 @@ var CameraRecorder = class {
12848
12924
  this.cameraStream,
12849
12925
  // streamToRecord,
12850
12926
  this.blobs,
12927
+ this.videoOptions,
12851
12928
  this.options.onBufferSizeError,
12852
12929
  (e3) => this.bufferError(e3),
12853
12930
  false
@@ -15375,7 +15452,7 @@ var AudioRecorder = class {
15375
15452
  audio: { deviceId: this.options.microphoneId || "default" }
15376
15453
  };
15377
15454
  this.audioStream = await navigator.mediaDevices.getUserMedia(constraints);
15378
- const { startRecording, stopRecording, pauseRecording, resumeRecording } = recorder(this.audioStream, this.blobs, void 0, void 0, true);
15455
+ const { startRecording, stopRecording, pauseRecording, resumeRecording } = recorder(this.audioStream, this.blobs, null, void 0, void 0, true);
15379
15456
  this.recordingStart = startRecording;
15380
15457
  this.recordingStop = stopRecording;
15381
15458
  this.recordingPause = pauseRecording;
@@ -17966,7 +18043,7 @@ var ScreenRecorder = class {
17966
18043
  });
17967
18044
  throw NOT_SHARED_SCREEN;
17968
18045
  }
17969
- const { startRecording, stopRecording } = recorder(this.screenStream, this.blobs, this.options.onBufferSizeError, onBufferSizeErrorCallback);
18046
+ const { startRecording, stopRecording } = recorder(this.screenStream, this.blobs, null, this.options.onBufferSizeError, onBufferSizeErrorCallback);
17970
18047
  this.recordingStart = startRecording;
17971
18048
  this.recordingStop = stopRecording;
17972
18049
  this.recordingStart();
@@ -21986,7 +22063,10 @@ var Proctoring = class {
21986
22063
  width: this.videoOptions.width,
21987
22064
  height: this.videoOptions.height,
21988
22065
  minWidth: this.videoOptions.minWidth,
21989
- minHeight: this.videoOptions.minHeight
22066
+ minHeight: this.videoOptions.minHeight,
22067
+ timeSlice: this.videoOptions.timeSlice,
22068
+ videoBitsPerSecond: this.videoOptions.videoBitsPerSecond,
22069
+ mimeType: this.videoOptions.mimeType
21990
22070
  },
21991
22071
  this.paramsConfig,
21992
22072
  this.backend,
package/index.js CHANGED
@@ -30264,7 +30264,10 @@ function validatePartialVideoOptions(options) {
30264
30264
  width: options.width,
30265
30265
  height: options.height,
30266
30266
  minWidth: options.minWidth,
30267
- minHeight: options.minHeight
30267
+ minHeight: options.minHeight,
30268
+ timeSlice: options.timeSlice,
30269
+ videoBitsPerSecond: options.videoBitsPerSecond,
30270
+ mimeType: options.mimeType
30268
30271
  };
30269
30272
  } else {
30270
30273
  return { width: 640, height: 480 };
@@ -30351,7 +30354,7 @@ var proctoringId;
30351
30354
  function setRecorderProctoringId(id) {
30352
30355
  proctoringId = id;
30353
30356
  }
30354
- function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorCallback, audio = false) {
30357
+ function recorder(stream4, buffer, videoOptions, onBufferSizeError = false, onBufferSizeErrorCallback, audio = false) {
30355
30358
  let resolvePromise;
30356
30359
  let stopped = false;
30357
30360
  let onBufferSizeInterval;
@@ -30371,15 +30374,28 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30371
30374
  "vp9 codec not supported. Using default mimeType without vp9."
30372
30375
  );
30373
30376
  }
30377
+ if (videoOptions == null ? void 0 : videoOptions.mimeType) {
30378
+ recorderOptions.mimeType = videoOptions == null ? void 0 : videoOptions.mimeType;
30379
+ }
30380
+ if ((videoOptions == null ? void 0 : videoOptions.videoBitsPerSecond) != void 0) {
30381
+ recorderOptions.videoBitsPerSecond = videoOptions == null ? void 0 : videoOptions.videoBitsPerSecond;
30382
+ }
30374
30383
  if (audio) {
30375
30384
  recorderOptions = {
30376
30385
  mimeType: "audio/webm",
30377
30386
  audioBitsPerSecond: 64 * 1e3
30378
30387
  };
30379
30388
  }
30389
+ console.log("recorderOptions bitsPerSecond", recorderOptions.bitsPerSecond);
30380
30390
  const mediaRecorder = new MediaRecorder(stream4, recorderOptions);
30381
30391
  mediaRecorder.ondataavailable = (e3) => {
30382
30392
  bufferSize = bufferSize + e3.data.size;
30393
+ console.log("video tracks length > 0", stream4.getVideoTracks().length > 0);
30394
+ if (stream4.getVideoTracks().length > 0) {
30395
+ const videoTrack = stream4.getVideoTracks()[0];
30396
+ console.log(videoTrack.readyState);
30397
+ console.log(videoTrack.enabled);
30398
+ }
30383
30399
  if (e3.data.size > 0) {
30384
30400
  buffer.push(e3.data);
30385
30401
  }
@@ -30393,6 +30409,7 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30393
30409
  proctoringId,
30394
30410
  `onBufferSizeError: Recorder size equal 0 Mb`
30395
30411
  );
30412
+ console.log("onbuffer size error");
30396
30413
  onBufferSizeErrorCallback && onBufferSizeErrorCallback();
30397
30414
  }
30398
30415
  lastEvent = e3;
@@ -30407,14 +30424,14 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30407
30424
  function startRecording() {
30408
30425
  return new Promise((resolve) => {
30409
30426
  resolvePromise = resolve;
30410
- mediaRecorder.start();
30427
+ var timeSlice = 1e4;
30428
+ if ((videoOptions == null ? void 0 : videoOptions.timeSlice) != void 0) {
30429
+ timeSlice = videoOptions == null ? void 0 : videoOptions.timeSlice;
30430
+ }
30431
+ console.log("startRecording", timeSlice);
30432
+ mediaRecorder.start(timeSlice);
30411
30433
  bufferSize = 0;
30412
30434
  stopped = false;
30413
- if (onBufferSizeError) {
30414
- onBufferSizeInterval = setInterval(async () => {
30415
- await mediaRecorder.requestData();
30416
- }, 3e4);
30417
- }
30418
30435
  });
30419
30436
  }
30420
30437
  function stopRecording() {
@@ -30423,7 +30440,6 @@ function recorder(stream4, buffer, onBufferSizeError = false, onBufferSizeErrorC
30423
30440
  resolvePromise = resolve;
30424
30441
  mediaRecorder.stop();
30425
30442
  stopped = true;
30426
- clearInterval(onBufferSizeInterval);
30427
30443
  stream4.getTracks().forEach((el) => {
30428
30444
  el.stop();
30429
30445
  });
@@ -30906,6 +30922,66 @@ var CameraRecorder = class {
30906
30922
  this.options.onBufferSizeErrorCallback && this.options.onBufferSizeErrorCallback();
30907
30923
  }
30908
30924
  }
30925
+ async startStream(options) {
30926
+ var _a2;
30927
+ const { cameraId, microphoneId, onBufferSizeErrorCallback } = this.options;
30928
+ const constraints = {
30929
+ audio: { deviceId: microphoneId },
30930
+ video: {
30931
+ deviceId: cameraId,
30932
+ width: this.videoOptions.width,
30933
+ height: this.videoOptions.height,
30934
+ frameRate: 15
30935
+ }
30936
+ };
30937
+ try {
30938
+ this.hardwareStream = await navigator.mediaDevices.getUserMedia(
30939
+ constraints
30940
+ );
30941
+ } catch (error) {
30942
+ if (error.toString() == "NotReadableError: Could not start video source")
30943
+ throw "N\xE3o foi poss\xEDvel conectar a camera, ela pode estar sendo utilizada por outro programa";
30944
+ throw error;
30945
+ }
30946
+ this.cameraStream = this.hardwareStream;
30947
+ const track = this.cameraStream.getVideoTracks()[0];
30948
+ const settings = track.getSettings();
30949
+ let { width = 0, height = 0 } = settings;
30950
+ const isPortrait = (_a2 = screen.orientation) == null ? void 0 : _a2.type.includes("portrait");
30951
+ if (isPortrait && isMobileDevice()) {
30952
+ if (this.videoOptions.width == height && this.videoOptions.height == width) {
30953
+ [width, height] = [height, width];
30954
+ }
30955
+ }
30956
+ if (this.videoOptions.minWidth > width || this.videoOptions.minHeight > height) {
30957
+ throw STREAM_UNDER_MINIMUM_PERMITTED;
30958
+ } else if (this.videoOptions.width !== width || this.videoOptions.height !== height) {
30959
+ trackers.registerAnotherStream(
30960
+ this.proctoringId,
30961
+ `Maybe have another stream active
30962
+ Video Options: ${JSON.stringify(
30963
+ this.videoOptions,
30964
+ null,
30965
+ 2
30966
+ )}
30967
+ Setting: ${JSON.stringify(settings, null, 2)}`
30968
+ );
30969
+ throw ANOTHER_STREAM_ACTIVE;
30970
+ }
30971
+ }
30972
+ async stopStream() {
30973
+ if (this.cameraStream) {
30974
+ this.cameraStream.getTracks().forEach((track) => track.stop());
30975
+ }
30976
+ if (this.internalClonedStream) {
30977
+ this.internalClonedStream.getTracks().forEach((track) => track.stop());
30978
+ this.internalClonedStream = null;
30979
+ }
30980
+ if (this.hardwareStream) {
30981
+ this.hardwareStream.getTracks().forEach((track) => track.stop());
30982
+ this.hardwareStream = null;
30983
+ }
30984
+ }
30909
30985
  async startRecording(options) {
30910
30986
  var _a2, _b, _c2, _d, _e3, _f, _g, _h;
30911
30987
  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)) {
@@ -30945,6 +31021,7 @@ var CameraRecorder = class {
30945
31021
  this.cameraStream,
30946
31022
  // streamToRecord,
30947
31023
  this.blobs,
31024
+ this.videoOptions,
30948
31025
  this.options.onBufferSizeError,
30949
31026
  (e3) => this.bufferError(e3),
30950
31027
  false
@@ -33472,7 +33549,7 @@ var AudioRecorder = class {
33472
33549
  audio: { deviceId: this.options.microphoneId || "default" }
33473
33550
  };
33474
33551
  this.audioStream = await navigator.mediaDevices.getUserMedia(constraints);
33475
- const { startRecording, stopRecording, pauseRecording, resumeRecording } = recorder(this.audioStream, this.blobs, void 0, void 0, true);
33552
+ const { startRecording, stopRecording, pauseRecording, resumeRecording } = recorder(this.audioStream, this.blobs, null, void 0, void 0, true);
33476
33553
  this.recordingStart = startRecording;
33477
33554
  this.recordingStop = stopRecording;
33478
33555
  this.recordingPause = pauseRecording;
@@ -36063,7 +36140,7 @@ var ScreenRecorder = class {
36063
36140
  });
36064
36141
  throw NOT_SHARED_SCREEN;
36065
36142
  }
36066
- const { startRecording, stopRecording } = recorder(this.screenStream, this.blobs, this.options.onBufferSizeError, onBufferSizeErrorCallback);
36143
+ const { startRecording, stopRecording } = recorder(this.screenStream, this.blobs, null, this.options.onBufferSizeError, onBufferSizeErrorCallback);
36067
36144
  this.recordingStart = startRecording;
36068
36145
  this.recordingStop = stopRecording;
36069
36146
  this.recordingStart();
@@ -37235,7 +37312,10 @@ var Proctoring = class {
37235
37312
  width: this.videoOptions.width,
37236
37313
  height: this.videoOptions.height,
37237
37314
  minWidth: this.videoOptions.minWidth,
37238
- minHeight: this.videoOptions.minHeight
37315
+ minHeight: this.videoOptions.minHeight,
37316
+ timeSlice: this.videoOptions.timeSlice,
37317
+ videoBitsPerSecond: this.videoOptions.videoBitsPerSecond,
37318
+ mimeType: this.videoOptions.mimeType
37239
37319
  },
37240
37320
  this.paramsConfig,
37241
37321
  this.backend,
@@ -56,6 +56,10 @@ export declare class CameraRecorder implements IRecorder {
56
56
  configImageCapture(): void;
57
57
  currentRetries: number;
58
58
  bufferError(e: any): Promise<void>;
59
+ startStream(options?: {
60
+ retry?: boolean;
61
+ }): Promise<void>;
62
+ stopStream(): Promise<void>;
59
63
  startRecording(options?: {
60
64
  retry?: boolean;
61
65
  }): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easyproctor-hml",
3
- "version": "2.5.21",
3
+ "version": "2.5.23",
4
4
  "description": "Modulo web de gravação do EasyProctor",
5
5
  "main": "./index.js",
6
6
  "module": "./esm/index.js",
@@ -1,5 +1,6 @@
1
+ import { ProctoringVideoOptions } from "../proctoring/options/ProctoringVideoOptions";
1
2
  export declare function setRecorderProctoringId(id: string): void;
2
- export default function recorder(stream: MediaStream, buffer: Blob[], onBufferSizeError?: boolean, onBufferSizeErrorCallback?: (e?: any) => void, audio?: boolean): {
3
+ export default function recorder(stream: MediaStream, buffer: Blob[], videoOptions: ProctoringVideoOptions | null, onBufferSizeError?: boolean, onBufferSizeErrorCallback?: (e?: any) => void, audio?: boolean): {
3
4
  startRecording: () => Promise<void>;
4
5
  stopRecording: () => Promise<void>;
5
6
  pauseRecording: () => Promise<void>;
@@ -3,6 +3,9 @@ export interface ProctoringVideoOptions {
3
3
  height: number;
4
4
  minWidth?: number;
5
5
  minHeight?: number;
6
+ timeSlice?: number;
7
+ videoBitsPerSecond?: number;
8
+ mimeType?: string;
6
9
  }
7
10
  export declare function validatePartialVideoOptions(options: Partial<ProctoringVideoOptions>): ProctoringVideoOptions;
8
11
  export declare const getDefaultProctoringVideoOptions: ProctoringVideoOptions;