@newtonschool/react_proctoring_library 0.0.9 → 0.0.12

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.
@@ -35,7 +35,8 @@ const ProctorApp = _ref => {
35
35
  userCount: true,
36
36
  tabSwitch: true,
37
37
  fullscreenExit: true,
38
- lookedAway: true
38
+ lookedAway: true,
39
+ isWebcamDataReliable: true
39
40
  },
40
41
  sendData = () => {},
41
42
  shouldSendDataOnBreach = false
@@ -51,7 +52,7 @@ const ProctorApp = _ref => {
51
52
  setFullscreen,
52
53
  fullScreenExitCount
53
54
  } = (0, _hooks.useFullscreenData)(firstFullScreenDone);
54
- const [userCount, lookedAwayCount] = (0, _useWebcamData.default)(webcamReference, canvasReference);
55
+ const [userCount, lookedAwayCount, isWebcamDataReliable] = (0, _useWebcamData.default)(webcamReference, canvasReference);
55
56
  const tabSwitchCount = (0, _hooks.useTabSwitchCount)(firstFullScreenDone);
56
57
  (0, _react.useEffect)(() => {
57
58
  (0, _utils.removeStatsFromLocalStorage)(proctoringIdentifier);
@@ -62,13 +63,14 @@ const ProctorApp = _ref => {
62
63
  userCount,
63
64
  tabSwitchCount,
64
65
  fullScreenExitCount,
65
- lookedAwayCount
66
+ lookedAwayCount,
67
+ isWebcamDataReliable
66
68
  }, proctoringIdentifier, sendData);
67
69
  }
68
70
 
69
- (0, _utils.updateStatistics)(statistics, tabSwitchCount, fullScreenExitCount, lookedAwayCount, userCount);
71
+ (0, _utils.updateStatistics)(statistics, tabSwitchCount, fullScreenExitCount, lookedAwayCount, userCount, isWebcamDataReliable);
70
72
  (0, _utils.addOrUpdateStatsToLocalStorage)(proctoringIdentifier, statistics.current);
71
- }, [userCount, tabSwitchCount, fullScreenExitCount, lookedAwayCount, proctoringIdentifier, sendData, shouldSendDataOnBreach]);
73
+ }, [userCount, tabSwitchCount, fullScreenExitCount, lookedAwayCount, isWebcamDataReliable, proctoringIdentifier, sendData, shouldSendDataOnBreach]);
72
74
 
73
75
  if (proctoringIdentifier === undefined) {
74
76
  // todo
@@ -3,10 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.initialValues = exports.glancePercentageToPass = exports.evaluateVideoIntervalInSeconds = exports.bodyPixConfigs = exports.INITIAL_STATISTICS = void 0;
6
+ exports.initialValues = exports.gpuTypes = exports.glancePercentageToPass = exports.evaluateVideoIntervalInSeconds = exports.bodyPixConfigs = exports.INITIAL_STATISTICS = void 0;
7
7
  const initialValues = {
8
8
  tabSwitchCount: 0,
9
9
  userCount: 0,
10
+ isWebcamDataReliable: true,
10
11
  isWatching: true,
11
12
  canOpenFullScreen: false,
12
13
  fullScreenExitCount: 0,
@@ -18,7 +19,8 @@ const INITIAL_STATISTICS = {
18
19
  TAB_SWITCH_COUNT: initialValues.tabSwitchCount,
19
20
  FULLSCREEN_EXIT_COUNT: initialValues.fullScreenExitCount,
20
21
  LOOKED_AWAY_COUNT: initialValues.lookedAwayCount,
21
- USER_COUNT_MAX: initialValues.userCount
22
+ USER_COUNT_MAX: initialValues.userCount,
23
+ IS_WEBCAM_DATA_RELIABLE: initialValues.isWebcamDataReliable
22
24
  };
23
25
  exports.INITIAL_STATISTICS = INITIAL_STATISTICS;
24
26
  const bodyPixConfigs = {
@@ -35,4 +37,6 @@ exports.bodyPixConfigs = bodyPixConfigs;
35
37
  const glancePercentageToPass = 60;
36
38
  exports.glancePercentageToPass = glancePercentageToPass;
37
39
  const evaluateVideoIntervalInSeconds = 1;
38
- exports.evaluateVideoIntervalInSeconds = evaluateVideoIntervalInSeconds;
40
+ exports.evaluateVideoIntervalInSeconds = evaluateVideoIntervalInSeconds;
41
+ const gpuTypes = ["apple", "amd", "radeon", "nvidia", "geforce"];
42
+ exports.gpuTypes = gpuTypes;
@@ -42,50 +42,58 @@ const getIsWatching = async (network, video) => {
42
42
  }
43
43
  };
44
44
 
45
+ const deviceHasGPU = (0, _utils.isGPUAvailable)();
46
+
45
47
  function useWebcamData(webcamReference, canvasReference) {
46
48
  const [userCount, setUserCount] = (0, _react.useState)(_defaults.initialValues.userCount);
47
49
  const [isWatching, setIsWatching] = (0, _react.useState)(_defaults.initialValues.isWatching);
48
50
  const [lookedAwayCount, setLookedAwayCount] = (0, _react.useState)(_defaults.initialValues.lookedAwayCount);
51
+ const [isWebcamDataReliable, setIsWebcamDataReliable] = (0, _react.useState)(_defaults.initialValues.isWebcamDataReliable);
52
+ (0, _react.useEffect)(() => {
53
+ setIsWebcamDataReliable(deviceHasGPU);
54
+ }, []);
49
55
  (0, _react.useEffect)(() => {
50
- const loadBodyPixModel = async () => {
51
- try {
52
- const network = await bodyPix.load();
53
- setInterval(async () => {
54
- if ((0, _utils.isWebcamVideoValid)(webcamReference)) {
55
- var _users$length;
56
-
57
- const video = webcamReference.current.video;
58
- const {
59
- videoWidth,
60
- videoHeight
61
- } = video;
62
- video.width = videoWidth;
63
- video.height = videoHeight;
64
- canvasReference.current.width = videoWidth;
65
- canvasReference.current.height = videoHeight;
66
- const users = await getUsers(network, video);
67
- const count = (_users$length = users === null || users === void 0 ? void 0 : users.length) !== null && _users$length !== void 0 ? _users$length : 0;
68
- setUserCount(count);
69
-
70
- if (count) {
71
- setIsWatching(getIsWatching(network, video));
72
- } else {
73
- setIsWatching(false);
56
+ if (deviceHasGPU) {
57
+ const loadBodyPixModel = async () => {
58
+ try {
59
+ const network = await bodyPix.load();
60
+ setInterval(async () => {
61
+ if ((0, _utils.isWebcamVideoValid)(webcamReference)) {
62
+ var _users$length;
63
+
64
+ const video = webcamReference.current.video;
65
+ const {
66
+ videoWidth,
67
+ videoHeight
68
+ } = video;
69
+ video.width = videoWidth;
70
+ video.height = videoHeight;
71
+ canvasReference.current.width = videoWidth;
72
+ canvasReference.current.height = videoHeight;
73
+ const users = await getUsers(network, video);
74
+ const count = (_users$length = users === null || users === void 0 ? void 0 : users.length) !== null && _users$length !== void 0 ? _users$length : 0;
75
+ setUserCount(count);
76
+
77
+ if (count) {
78
+ setIsWatching(getIsWatching(network, video));
79
+ } else {
80
+ setIsWatching(false);
81
+ }
74
82
  }
75
- }
76
- }, _defaults.evaluateVideoIntervalInSeconds * 1000);
77
- } catch (err) {
78
- console.log("Error Trace:", err);
79
- return;
80
- }
81
- };
82
-
83
- loadBodyPixModel();
83
+ }, _defaults.evaluateVideoIntervalInSeconds * 1000);
84
+ } catch (err) {
85
+ console.log("Error Trace:", err);
86
+ return;
87
+ }
88
+ };
89
+
90
+ loadBodyPixModel();
91
+ }
84
92
  }, [webcamReference, canvasReference]);
85
93
  (0, _react.useEffect)(() => {
86
94
  if (!isWatching) {
87
95
  setLookedAwayCount(lookedAwayCount => lookedAwayCount + 1);
88
96
  }
89
97
  }, [isWatching]);
90
- return [userCount, lookedAwayCount];
98
+ return [userCount, lookedAwayCount, isWebcamDataReliable];
91
99
  }
@@ -16,11 +16,23 @@ const sendDataOnBreach = (statistics, currentData, proctoringIdentifier, sendDat
16
16
  userCount,
17
17
  tabSwitchCount,
18
18
  fullScreenExitCount,
19
- lookedAwayCount
19
+ lookedAwayCount,
20
+ isWebcamDataReliable
20
21
  } = currentData;
21
22
  const timestamp = Date.now();
22
23
  const data = statistics.current;
23
24
 
25
+ if (data.IS_WEBCAM_DATA_RELIABLE !== isWebcamDataReliable) {
26
+ sendData({
27
+ proctoringIdentifier,
28
+ breach: "IS_WEBCAM_DATA_RELIABLE",
29
+ timestamp,
30
+ data: _objectSpread(_objectSpread({}, data), {}, {
31
+ IS_WEBCAM_DATA_RELIABLE: isWebcamDataReliable
32
+ })
33
+ });
34
+ }
35
+
24
36
  if (data.USER_COUNT_MAX < userCount) {
25
37
  sendData({
26
38
  proctoringIdentifier,
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isGPUAvailable = void 0;
7
+
8
+ require("core-js/modules/web.dom-collections.iterator.js");
9
+
10
+ require("core-js/modules/es.array.includes.js");
11
+
12
+ require("core-js/modules/es.string.includes.js");
13
+
14
+ var _defaults = require("../constants/defaults");
15
+
16
+ const isGPUAvailable = () => {
17
+ const canvas = document.createElement("canvas");
18
+ const webgl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
19
+ const debugInfo = webgl.getExtension("webgl_debug_renderer_info");
20
+ const gpu = webgl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL).toLowerCase();
21
+
22
+ for (const gpuType of _defaults.gpuTypes) {
23
+ if (gpu.includes(gpuType)) return true;
24
+ }
25
+
26
+ return false;
27
+ };
28
+
29
+ exports.isGPUAvailable = isGPUAvailable;
@@ -63,6 +63,12 @@ Object.defineProperty(exports, "isArrayValid", {
63
63
  return _arrayUtils.isArrayValid;
64
64
  }
65
65
  });
66
+ Object.defineProperty(exports, "isGPUAvailable", {
67
+ enumerable: true,
68
+ get: function get() {
69
+ return _gpuUtils.isGPUAvailable;
70
+ }
71
+ });
66
72
  Object.defineProperty(exports, "isWebcamVideoValid", {
67
73
  enumerable: true,
68
74
  get: function get() {
@@ -102,4 +108,6 @@ var _browserUtils = require("./browserUtils");
102
108
 
103
109
  var _breachUtils = require("./breachUtils");
104
110
 
105
- var _arrayUtils = require("./arrayUtils");
111
+ var _arrayUtils = require("./arrayUtils");
112
+
113
+ var _gpuUtils = require("./gpuUtils");
@@ -11,11 +11,12 @@ const isWebcamVideoValid = webcamReference => webcamReference !== null && webcam
11
11
 
12
12
  exports.isWebcamVideoValid = isWebcamVideoValid;
13
13
 
14
- const updateStatistics = (statistics, tabSwitchCount, fullScreenExitCount, lookedAwayCount, userCount) => {
14
+ const updateStatistics = (statistics, tabSwitchCount, fullScreenExitCount, lookedAwayCount, userCount, isWebcamDataReliable) => {
15
15
  statistics.current.TAB_SWITCH_COUNT = tabSwitchCount;
16
16
  statistics.current.FULLSCREEN_EXIT_COUNT = fullScreenExitCount;
17
17
  statistics.current.LOOKED_AWAY_COUNT = lookedAwayCount;
18
18
  statistics.current.USER_COUNT_MAX = Math.max(userCount, statistics.current.USER_COUNT_MAX);
19
+ statistics.current.IS_WEBCAM_DATA_RELIABLE = isWebcamDataReliable;
19
20
  };
20
21
 
21
22
  exports.updateStatistics = updateStatistics;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newtonschool/react_proctoring_library",
3
- "version": "0.0.9",
3
+ "version": "0.0.12",
4
4
  "description": "Used to proctor online tests",
5
5
  "author": "ayushkagrawal,shreyachandra",
6
6
  "main": "dist/index.js",