@newtonschool/react_proctoring_library 0.0.53 → 0.0.55

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.
@@ -22,6 +22,7 @@ var _webcamActivityTracker = _interopRequireDefault(require("../webcam-activity-
22
22
  var _browserUtils = require("../../utils/browserUtils");
23
23
  var _screenshareActivityTracker = require("../screenshare-activity-tracker");
24
24
  var _dom = require("../../constants/dom");
25
+ var _useIsPageFocussed = _interopRequireDefault(require("../../hooks/useIsPageFocussed"));
25
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
27
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
28
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -84,6 +85,7 @@ const ProctorApp = _ref => {
84
85
  }, [proctoringIdentifier, getProctorParamValues]);
85
86
  const [userCount, lookedAwayCount] = (0, _useWebcamData.default)(references.webcamReference, references.canvasReference, proctorParams);
86
87
  const isTabSwitched = !(0, _hooks.usePageVisibility)(proctorParams.tabSwitch);
88
+ const isPageFocussed = (0, _useIsPageFocussed.default)(proctorParams.pageFocus);
87
89
  (0, _react.useEffect)(() => {
88
90
  if (recurring) {
89
91
  recurringFetchIntervalRef.current = setInterval(() => {
@@ -102,7 +104,8 @@ const ProctorApp = _ref => {
102
104
  isTabSwitched,
103
105
  isFullScreen: permissions.fullscreen,
104
106
  lookedAwayCount,
105
- isWebcamDataNotReliable: !isWebcamProcessingReliable
107
+ isWebcamDataNotReliable: !isWebcamProcessingReliable,
108
+ isPageFocussed
106
109
  };
107
110
  const breachData = (0, _breachUtils.getDataOnBreach)(statistics, currentStats, proctorParams);
108
111
  (0, _utils.updateStatistics)(statistics, currentStats, proctorParams);
@@ -111,7 +114,7 @@ const ProctorApp = _ref => {
111
114
  sendWebcamSnapshot(true, breachData.breachedParam);
112
115
  sendScreengrab(true, breachData.breachedParam);
113
116
  }
114
- }, [userCount, isTabSwitched, permissions.fullscreen, lookedAwayCount, sendProctoredParamValues, sendWebcamSnapshot, sendScreengrab, proctorParams]);
117
+ }, [userCount, isTabSwitched, isPageFocussed, permissions.fullscreen, lookedAwayCount, sendProctoredParamValues, sendWebcamSnapshot, sendScreengrab, proctorParams]);
115
118
  const shouldShowProctoredComponent = (0, _breachUtils.showProctoredComponent)(proctorParams, permissions);
116
119
  return /*#__PURE__*/_react.default.createElement("div", {
117
120
  className: "".concat(proctorParams.copyPasteProctoring ? 'disable-copy-paste fullwidth fullheight' : 'fullwidth fullheight')
@@ -11,11 +11,13 @@ const defaultConfig = {
11
11
  lookedAway: true,
12
12
  webcamSnapshots: true,
13
13
  screenshareSnapshots: true,
14
- copyPasteProctoring: true
14
+ copyPasteProctoring: true,
15
+ pageFocus: true
15
16
  };
16
17
  exports.defaultConfig = defaultConfig;
17
18
  const initialValues = {
18
19
  isTabSwitched: false,
20
+ pageFocus: true,
19
21
  userCount: 0,
20
22
  isWebcamDataNotReliable: true,
21
23
  isWatching: true,
@@ -26,11 +28,12 @@ const initialValues = {
26
28
  };
27
29
  exports.initialValues = initialValues;
28
30
  const STATS_PARAMS = {
29
- isTabSwitched: "IS_TAB_SWITCHED",
30
- isFullscreen: "IS_FULLSCREEN",
31
- lookedAwayCount: "LOOKED_AWAY_COUNT",
32
- userCountMax: "USER_COUNT_MAX",
33
- isWebcamNotReliable: "IS_WEBCAM_DATA_NOT_RELIABLE"
31
+ isTabSwitched: 'IS_TAB_SWITCHED',
32
+ isPageFocussed: 'PAGE_FOCUS',
33
+ isFullscreen: 'IS_FULLSCREEN',
34
+ lookedAwayCount: 'LOOKED_AWAY_COUNT',
35
+ userCountMax: 'USER_COUNT_MAX',
36
+ isWebcamNotReliable: 'IS_WEBCAM_DATA_NOT_RELIABLE'
34
37
  };
35
38
  exports.STATS_PARAMS = STATS_PARAMS;
36
39
  const INITIAL_STATISTICS = {
@@ -42,13 +45,13 @@ const INITIAL_STATISTICS = {
42
45
  };
43
46
  exports.INITIAL_STATISTICS = INITIAL_STATISTICS;
44
47
  const proctorParamsToPermission = {
45
- fullscreenExit: "fullscreen",
46
- lookedAway: "video",
47
- webcamSnapshots: "video",
48
- screenshareSnapshots: "screenshare"
48
+ fullscreenExit: 'fullscreen',
49
+ lookedAway: 'video',
50
+ webcamSnapshots: 'video',
51
+ screenshareSnapshots: 'screenshare'
49
52
  };
50
53
  exports.proctorParamsToPermission = proctorParamsToPermission;
51
54
  const evaluateVideoIntervalInSeconds = 5;
52
55
  exports.evaluateVideoIntervalInSeconds = evaluateVideoIntervalInSeconds;
53
- const gpuTypes = ["intel", "apple", "amd", "radeon", "nvidia", "geforce"];
56
+ const gpuTypes = ['intel', 'apple', 'amd', 'radeon', 'nvidia', 'geforce'];
54
57
  exports.gpuTypes = gpuTypes;
@@ -10,13 +10,7 @@ var _utils = require("../utils");
10
10
  const focusEvent = (0, _utils.getFocusEventName)();
11
11
  const blurEvent = (0, _utils.getBlurEventName)();
12
12
  function useIsPageFocussed(isProctorParam) {
13
- const [isFocussed, setIsFocussed] = (0, _react.useState)(true);
14
- const updateVisibilityOnFocus = () => {
15
- setIsFocussed(true);
16
- };
17
- const updateVisibilityOnBlur = () => {
18
- setIsFocussed(false);
19
- };
13
+ const [isPageFocussed, setIsPageFocussed] = (0, _react.useState)(true);
20
14
  (0, _react.useEffect)(() => {
21
15
  window.addEventListener(focusEvent, updateVisibilityOnFocus, false);
22
16
  window.addEventListener(blurEvent, updateVisibilityOnBlur, false);
@@ -25,5 +19,13 @@ function useIsPageFocussed(isProctorParam) {
25
19
  window.removeEventListener(blurEvent, updateVisibilityOnBlur);
26
20
  };
27
21
  }, []);
28
- return isFocussed && isProctorParam;
22
+ const updateVisibilityOnFocus = () => {
23
+ setIsPageFocussed(true);
24
+ };
25
+ const updateVisibilityOnBlur = () => {
26
+ if ((0, _utils.getIsDocumentVisible)()) {
27
+ setIsPageFocussed(false);
28
+ }
29
+ };
30
+ return isPageFocussed && isProctorParam;
29
31
  }
@@ -26,6 +26,9 @@ const getInitialStats = proctorParams => {
26
26
  if (proctorParams.lookedAway) {
27
27
  initialStats[_defaults.STATS_PARAMS.lookedAwayCount] = _defaults.initialValues.lookedAwayCount;
28
28
  }
29
+ if (proctorParams.pageFocus) {
30
+ initialStats[_defaults.STATS_PARAMS.isPageFocussed] = _defaults.initialValues.pageFocus;
31
+ }
29
32
  return initialStats;
30
33
  };
31
34
  exports.getInitialStats = getInitialStats;
@@ -53,7 +56,8 @@ const getDataOnBreach = (statistics, currentData, proctorParams) => {
53
56
  isTabSwitched,
54
57
  isFullScreen,
55
58
  lookedAwayCount,
56
- isWebcamDataNotReliable
59
+ isWebcamDataNotReliable,
60
+ isPageFocussed
57
61
  } = currentData;
58
62
  const timestamp = Date.now();
59
63
  const data = statistics.current;
@@ -87,6 +91,16 @@ const getDataOnBreach = (statistics, currentData, proctorParams) => {
87
91
  })
88
92
  };
89
93
  }
94
+ const isPageFocusParam = _defaults.STATS_PARAMS.isPageFocussed;
95
+ if (proctorParams.pageFocus && !isPageFocussed && data[isPageFocusParam]) {
96
+ return {
97
+ breachedParam: isPageFocusParam,
98
+ timestamp,
99
+ data: _objectSpread(_objectSpread({}, data), {}, {
100
+ [isPageFocusParam]: isPageFocussed
101
+ })
102
+ };
103
+ }
90
104
  const fullscreenExitParam = _defaults.STATS_PARAMS.isFullscreen;
91
105
  if (proctorParams.fullscreenExit && !isFullScreen && data[fullscreenExitParam]) {
92
106
  return {
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.updateVideoPermissions = exports.updateStatistics = exports.updateAudioPermissions = exports.setupScreensharePermission = exports.resetWebcamReference = exports.resetScreenshotReference = exports.isWebcamVideoValid = exports.getVideoPermissionQuery = exports.getVideoPermission = exports.getGlancePercentage = exports.getAudioVideoPermission = exports.getAudioPermissionQuery = exports.getAudioPermission = exports.collectScreenshare = exports.captureWebcamSnapshot = exports.captureScreenshot = void 0;
7
+ require("core-js/modules/es.regexp.exec.js");
8
+ require("core-js/modules/es.string.split.js");
7
9
  require("core-js/modules/es.array-buffer.slice.js");
8
10
  require("core-js/modules/es.typed-array.uint8-array.js");
9
11
  require("core-js/modules/es.typed-array.fill.js");
@@ -21,7 +23,8 @@ const updateStatistics = (statistics, currentStats, proctorParams) => {
21
23
  isFullScreen,
22
24
  lookedAwayCount,
23
25
  userCount,
24
- isWebcamDataReliable
26
+ isWebcamDataReliable,
27
+ isPageFocussed
25
28
  } = currentStats;
26
29
  if (proctorParams.tabSwitch) {
27
30
  statistics.current[_defaults.STATS_PARAMS.isTabSwitched] = isTabSwitched;
@@ -35,6 +38,9 @@ const updateStatistics = (statistics, currentStats, proctorParams) => {
35
38
  if (proctorParams.people) {
36
39
  statistics.current[_defaults.STATS_PARAMS.userCountMax] = Math.max(userCount, statistics.current[_defaults.STATS_PARAMS.userCountMax]);
37
40
  }
41
+ if (proctorParams.pageFocus) {
42
+ statistics.current[_defaults.STATS_PARAMS.isPageFocussed] = isPageFocussed;
43
+ }
38
44
  statistics.current.IS_WEBCAM_DATA_RELIABLE = isWebcamDataReliable;
39
45
  };
40
46
  exports.updateStatistics = updateStatistics;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newtonschool/react_proctoring_library",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "description": "Used to proctor online tests",
5
5
  "author": "ayushkagrawal,shreyachandra,weastel",
6
6
  "main": "dist/index.js",
@@ -13,12 +13,12 @@
13
13
  ""
14
14
  ],
15
15
  "dependencies": {
16
- "@tensorflow-models/coco-ssd": "^2.2.2",
17
- "@tensorflow/tfjs": "^3.9.0",
18
- "bootstrap": "^5.1.3",
19
- "core-js": "^3.22.7",
20
- "react-bootstrap": "^2.0.4",
21
- "react-webcam": "^6.0.0"
16
+ "@tensorflow-models/coco-ssd": "2.2.2",
17
+ "@tensorflow/tfjs": "3.9.0",
18
+ "bootstrap": "5.1.3",
19
+ "core-js": "3.22.7",
20
+ "react-bootstrap": "2.0.4",
21
+ "react-webcam": "6.0.0"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "react": ">=16.8.0",
@@ -48,9 +48,9 @@
48
48
  ]
49
49
  },
50
50
  "devDependencies": {
51
- "@babel/cli": "^7.16.7",
52
- "@babel/core": "^7.16.7",
53
- "@babel/preset-env": "^7.16.7",
51
+ "@babel/cli": "7.16.7",
52
+ "@babel/core": "7.16.7",
53
+ "@babel/preset-env": "7.16.7",
54
54
  "react-scripts": ">=5.0.0"
55
55
  }
56
56
  }