@newtonschool/react_proctoring_library 0.0.11 → 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,18 +52,8 @@ 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
- (0, _react.useEffect)(() => {
57
- if (shouldSendDataOnBreach && (userCount < 0 || lookedAwayCount < 0)) {
58
- (0, _utils.sendDataOnBreach)(statistics, {
59
- userCount,
60
- tabSwitchCount,
61
- fullScreenExitCount,
62
- lookedAwayCount
63
- }, proctoringIdentifier, sendData);
64
- }
65
- }, []);
66
57
  (0, _react.useEffect)(() => {
67
58
  (0, _utils.removeStatsFromLocalStorage)(proctoringIdentifier);
68
59
  }, [proctoringIdentifier]);
@@ -72,13 +63,14 @@ const ProctorApp = _ref => {
72
63
  userCount,
73
64
  tabSwitchCount,
74
65
  fullScreenExitCount,
75
- lookedAwayCount
66
+ lookedAwayCount,
67
+ isWebcamDataReliable
76
68
  }, proctoringIdentifier, sendData);
77
69
  }
78
70
 
79
- (0, _utils.updateStatistics)(statistics, tabSwitchCount, fullScreenExitCount, lookedAwayCount, userCount);
71
+ (0, _utils.updateStatistics)(statistics, tabSwitchCount, fullScreenExitCount, lookedAwayCount, userCount, isWebcamDataReliable);
80
72
  (0, _utils.addOrUpdateStatsToLocalStorage)(proctoringIdentifier, statistics.current);
81
- }, [userCount, tabSwitchCount, fullScreenExitCount, lookedAwayCount, proctoringIdentifier, sendData, shouldSendDataOnBreach]);
73
+ }, [userCount, tabSwitchCount, fullScreenExitCount, lookedAwayCount, isWebcamDataReliable, proctoringIdentifier, sendData, shouldSendDataOnBreach]);
82
74
 
83
75
  if (proctoringIdentifier === undefined) {
84
76
  // todo
@@ -7,6 +7,7 @@ exports.initialValues = exports.gpuTypes = exports.glancePercentageToPass = expo
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 = {
@@ -42,14 +42,18 @@ const getIsWatching = async (network, video) => {
42
42
  }
43
43
  };
44
44
 
45
- const gpuAvailable = (0, _utils.isGPUAvailable)();
45
+ const deviceHasGPU = (0, _utils.isGPUAvailable)();
46
46
 
47
47
  function useWebcamData(webcamReference, canvasReference) {
48
- const [userCount, setUserCount] = (0, _react.useState)(gpuAvailable ? _defaults.initialValues.userCount : -1);
49
- const [isWatching, setIsWatching] = (0, _react.useState)(gpuAvailable ? _defaults.initialValues.isWatching : -1);
48
+ const [userCount, setUserCount] = (0, _react.useState)(_defaults.initialValues.userCount);
49
+ const [isWatching, setIsWatching] = (0, _react.useState)(_defaults.initialValues.isWatching);
50
50
  const [lookedAwayCount, setLookedAwayCount] = (0, _react.useState)(_defaults.initialValues.lookedAwayCount);
51
+ const [isWebcamDataReliable, setIsWebcamDataReliable] = (0, _react.useState)(_defaults.initialValues.isWebcamDataReliable);
51
52
  (0, _react.useEffect)(() => {
52
- if (gpuAvailable) {
53
+ setIsWebcamDataReliable(deviceHasGPU);
54
+ }, []);
55
+ (0, _react.useEffect)(() => {
56
+ if (deviceHasGPU) {
53
57
  const loadBodyPixModel = async () => {
54
58
  try {
55
59
  const network = await bodyPix.load();
@@ -91,5 +95,5 @@ function useWebcamData(webcamReference, canvasReference) {
91
95
  setLookedAwayCount(lookedAwayCount => lookedAwayCount + 1);
92
96
  }
93
97
  }, [isWatching]);
94
- return [userCount, lookedAwayCount];
98
+ return [userCount, lookedAwayCount, isWebcamDataReliable];
95
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,
@@ -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.11",
3
+ "version": "0.0.12",
4
4
  "description": "Used to proctor online tests",
5
5
  "author": "ayushkagrawal,shreyachandra",
6
6
  "main": "dist/index.js",