@newtonschool/react_proctoring_library 0.0.54 → 0.0.56

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.
@@ -10,6 +10,7 @@ require("core-js/modules/es.promise.js");
10
10
  require("core-js/modules/web.dom-collections.iterator.js");
11
11
  require("core-js/modules/es.symbol.description.js");
12
12
  var _react = _interopRequireWildcard(require("react"));
13
+ var _useWakeUpLock = require("../../hooks/useWakeUpLock");
13
14
  require("./index.scss");
14
15
  var _utils = require("../../utils");
15
16
  var _hooks = require("../../hooks");
@@ -22,6 +23,7 @@ var _webcamActivityTracker = _interopRequireDefault(require("../webcam-activity-
22
23
  var _browserUtils = require("../../utils/browserUtils");
23
24
  var _screenshareActivityTracker = require("../screenshare-activity-tracker");
24
25
  var _dom = require("../../constants/dom");
26
+ var _useIsPageFocussed = _interopRequireDefault(require("../../hooks/useIsPageFocussed"));
25
27
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
28
  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
29
  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; }
@@ -53,6 +55,14 @@ const ProctorApp = _ref => {
53
55
  permissionSetter,
54
56
  screenshareStream
55
57
  } = context;
58
+ const {
59
+ acquireWakeUpLock,
60
+ releaseWakeUpLock
61
+ } = (0, _useWakeUpLock.useWakeUpLock)();
62
+ (0, _react.useEffect)(() => {
63
+ acquireWakeUpLock();
64
+ return releaseWakeUpLock;
65
+ }, []);
56
66
  const CustomPermissionView = customPermissionView;
57
67
  const proctorParams = (0, _react.useMemo)(() => _objectSpread(_objectSpread({}, _defaults.defaultConfig), config.proctorParams), [config.proctorParams]);
58
68
  const statistics = (0, _react.useRef)((0, _breachUtils.getInitialStats)(proctorParams));
@@ -84,6 +94,7 @@ const ProctorApp = _ref => {
84
94
  }, [proctoringIdentifier, getProctorParamValues]);
85
95
  const [userCount, lookedAwayCount] = (0, _useWebcamData.default)(references.webcamReference, references.canvasReference, proctorParams);
86
96
  const isTabSwitched = !(0, _hooks.usePageVisibility)(proctorParams.tabSwitch);
97
+ const isPageFocussed = (0, _useIsPageFocussed.default)(proctorParams.pageFocus);
87
98
  (0, _react.useEffect)(() => {
88
99
  if (recurring) {
89
100
  recurringFetchIntervalRef.current = setInterval(() => {
@@ -102,7 +113,8 @@ const ProctorApp = _ref => {
102
113
  isTabSwitched,
103
114
  isFullScreen: permissions.fullscreen,
104
115
  lookedAwayCount,
105
- isWebcamDataNotReliable: !isWebcamProcessingReliable
116
+ isWebcamDataNotReliable: !isWebcamProcessingReliable,
117
+ isPageFocussed
106
118
  };
107
119
  const breachData = (0, _breachUtils.getDataOnBreach)(statistics, currentStats, proctorParams);
108
120
  (0, _utils.updateStatistics)(statistics, currentStats, proctorParams);
@@ -111,7 +123,7 @@ const ProctorApp = _ref => {
111
123
  sendWebcamSnapshot(true, breachData.breachedParam);
112
124
  sendScreengrab(true, breachData.breachedParam);
113
125
  }
114
- }, [userCount, isTabSwitched, permissions.fullscreen, lookedAwayCount, sendProctoredParamValues, sendWebcamSnapshot, sendScreengrab, proctorParams]);
126
+ }, [userCount, isTabSwitched, isPageFocussed, permissions.fullscreen, lookedAwayCount, sendProctoredParamValues, sendWebcamSnapshot, sendScreengrab, proctorParams]);
115
127
  const shouldShowProctoredComponent = (0, _breachUtils.showProctoredComponent)(proctorParams, permissions);
116
128
  return /*#__PURE__*/_react.default.createElement("div", {
117
129
  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
  }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useWakeUpLock = void 0;
7
+ require("core-js/modules/es.promise.js");
8
+ var _react = require("react");
9
+ const useWakeUpLock = () => {
10
+ const wakeLock = (0, _react.useRef)();
11
+ const canWakeLock = () => 'wakeLock' in navigator;
12
+ const acquireWakeUpLock = async () => {
13
+ try {
14
+ if (!canWakeLock()) return;
15
+ wakeLock.current = await navigator.wakeLock.request();
16
+ } catch (e) {
17
+ // pass
18
+ }
19
+ };
20
+ function releaseWakeUpLock() {
21
+ try {
22
+ if (wakeLock.current) {
23
+ wakeLock.current.release();
24
+ wakeLock.current = null;
25
+ }
26
+ } catch (_unused) {
27
+ // pass
28
+ }
29
+ }
30
+ return {
31
+ acquireWakeUpLock,
32
+ releaseWakeUpLock
33
+ };
34
+ };
35
+ exports.useWakeUpLock = useWakeUpLock;
@@ -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 {
@@ -23,7 +23,8 @@ const updateStatistics = (statistics, currentStats, proctorParams) => {
23
23
  isFullScreen,
24
24
  lookedAwayCount,
25
25
  userCount,
26
- isWebcamDataReliable
26
+ isWebcamDataReliable,
27
+ isPageFocussed
27
28
  } = currentStats;
28
29
  if (proctorParams.tabSwitch) {
29
30
  statistics.current[_defaults.STATS_PARAMS.isTabSwitched] = isTabSwitched;
@@ -37,6 +38,9 @@ const updateStatistics = (statistics, currentStats, proctorParams) => {
37
38
  if (proctorParams.people) {
38
39
  statistics.current[_defaults.STATS_PARAMS.userCountMax] = Math.max(userCount, statistics.current[_defaults.STATS_PARAMS.userCountMax]);
39
40
  }
41
+ if (proctorParams.pageFocus) {
42
+ statistics.current[_defaults.STATS_PARAMS.isPageFocussed] = isPageFocussed;
43
+ }
40
44
  statistics.current.IS_WEBCAM_DATA_RELIABLE = isWebcamDataReliable;
41
45
  };
42
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.54",
3
+ "version": "0.0.56",
4
4
  "description": "Used to proctor online tests",
5
5
  "author": "ayushkagrawal,shreyachandra,weastel",
6
6
  "main": "dist/index.js",