@newtonschool/react_proctoring_library 0.0.80 → 0.0.82
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/dist/components/webcam-activity-tracker/electron.js +7 -2
- package/dist/constants/defaults.js +9 -3
- package/dist/hooks/electron/useIllegalKeysCombination.js +25 -0
- package/dist/hooks/useGenericIllegalKeysCombination.js +14 -0
- package/dist/hooks/useGenericSleepDetected.js +22 -0
- package/dist/hooks/useTrackBreachParameters.js +13 -1
- package/dist/utils/breachUtils.js +31 -1
- package/dist/utils/webcamMicrophoneUtils.js +9 -1
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ require("core-js/modules/es.string.includes.js");
|
|
|
10
10
|
require("core-js/modules/es.promise.js");
|
|
11
11
|
var _react = require("react");
|
|
12
12
|
var _reactWebcam = _interopRequireDefault(require("react-webcam"));
|
|
13
|
+
var _useSleepDetetected = require("../../hooks/useSleepDetetected");
|
|
13
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -19,10 +20,13 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
19
20
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
21
|
const getMacBookDevice = function getMacBookDevice() {
|
|
21
22
|
let devices = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
23
|
+
if (!devices) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
22
26
|
if (devices.length === 1) {
|
|
23
27
|
return devices[0];
|
|
24
28
|
}
|
|
25
|
-
return devices.find(device => device.label.includes('FaceTime HD Camera'));
|
|
29
|
+
return devices.find(device => device.label.includes('FaceTime HD Camera')) || devices[0];
|
|
26
30
|
};
|
|
27
31
|
function ElectronWebCam(_ref) {
|
|
28
32
|
let {
|
|
@@ -45,6 +49,7 @@ function ElectronWebCam(_ref) {
|
|
|
45
49
|
recurringFetchInterval = 30000
|
|
46
50
|
} = config;
|
|
47
51
|
const deviceId = device === null || device === void 0 ? void 0 : device.webCamDeviceId;
|
|
52
|
+
const deviceWentToSleepCount = (0, _useSleepDetetected.useSleepDetected)();
|
|
48
53
|
(0, _react.useEffect)(() => {
|
|
49
54
|
setAskPermissionAction(oldAskPermissionAction => _objectSpread(_objectSpread({}, oldAskPermissionAction), {}, {
|
|
50
55
|
video: async () => {
|
|
@@ -103,7 +108,7 @@ function ElectronWebCam(_ref) {
|
|
|
103
108
|
if (deviceId) {
|
|
104
109
|
startWebCamSnapshot();
|
|
105
110
|
}
|
|
106
|
-
}, [config.fileUploadConfig, deviceId, recurring, recurringFetchInterval, device.webCamDeviceId]);
|
|
111
|
+
}, [config.fileUploadConfig, deviceId, recurring, recurringFetchInterval, device.webCamDeviceId, deviceWentToSleepCount]);
|
|
107
112
|
(0, _react.useEffect)(() => {
|
|
108
113
|
if (deviceId) {
|
|
109
114
|
const permissionSetter = permission => {
|
|
@@ -19,18 +19,24 @@ const initialValues = exports.initialValues = {
|
|
|
19
19
|
isWatching: true,
|
|
20
20
|
canOpenFullScreen: false,
|
|
21
21
|
isFullscreen: false,
|
|
22
|
-
firstTimeFullScreen: true
|
|
22
|
+
firstTimeFullScreen: true,
|
|
23
|
+
illegalKeysCombinationDetected: 0,
|
|
24
|
+
sleepDetected: 0
|
|
23
25
|
};
|
|
24
26
|
const STATS_PARAMS = exports.STATS_PARAMS = {
|
|
25
27
|
isTabSwitched: 'IS_TAB_SWITCHED',
|
|
26
28
|
isPageFocussed: 'PAGE_FOCUS',
|
|
27
29
|
isFullscreen: 'IS_FULLSCREEN',
|
|
28
|
-
isWebcamNotReliable: 'IS_WEBCAM_DATA_NOT_RELIABLE'
|
|
30
|
+
isWebcamNotReliable: 'IS_WEBCAM_DATA_NOT_RELIABLE',
|
|
31
|
+
illegalKeysCombinationDetected: 'ILLEGAL_KEY_COMBINATION_DETECTED',
|
|
32
|
+
sleepDetected: 'SLEEP_DETECTED'
|
|
29
33
|
};
|
|
30
34
|
const INITIAL_STATISTICS = exports.INITIAL_STATISTICS = {
|
|
31
35
|
[STATS_PARAMS.isTabSwitched]: initialValues.isTabSwitched,
|
|
32
36
|
[STATS_PARAMS.isFullscreen]: initialValues.isFullscreen,
|
|
33
|
-
[STATS_PARAMS.isWebcamNotReliable]: initialValues.isWebcamDataNotReliable
|
|
37
|
+
[STATS_PARAMS.isWebcamNotReliable]: initialValues.isWebcamDataNotReliable,
|
|
38
|
+
[STATS_PARAMS.illegalKeysCombinationDetected]: initialValues.illegalKeysCombinationDetected,
|
|
39
|
+
[STATS_PARAMS.sleepDetected]: initialValues.sleepDetected
|
|
34
40
|
};
|
|
35
41
|
const proctorParamsToPermission = exports.proctorParamsToPermission = {
|
|
36
42
|
fullscreenExit: 'fullscreen',
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useIllegalKeysCombination = useIllegalKeysCombination;
|
|
7
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _ElectronContext = require("../../contexts/ElectronContext");
|
|
10
|
+
function useIllegalKeysCombination() {
|
|
11
|
+
const [keysClickedCount, setKeysClickedCount] = (0, _react.useState)(0);
|
|
12
|
+
const isElectronApp = (0, _react.useContext)(_ElectronContext.ElectronContext);
|
|
13
|
+
(0, _react.useEffect)(() => {
|
|
14
|
+
if (isElectronApp) {
|
|
15
|
+
const illegalKeysClickHandler = () => {
|
|
16
|
+
setKeysClickedCount(count => count + 1);
|
|
17
|
+
};
|
|
18
|
+
const signal = window.electron.listener.illegalKeysCombinationDetected(illegalKeysClickHandler);
|
|
19
|
+
return () => {
|
|
20
|
+
window.electron.listener.removeListener(signal, illegalKeysClickHandler);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}, [isElectronApp]);
|
|
24
|
+
return keysClickedCount;
|
|
25
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useGenericIllegalKeysCombinationDetected;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _ElectronContext = require("../contexts/ElectronContext");
|
|
9
|
+
var _useIllegalKeysCombination = require("./electron/useIllegalKeysCombination");
|
|
10
|
+
function useGenericIllegalKeysCombinationDetected() {
|
|
11
|
+
const isElectronApp = (0, _react.useContext)(_ElectronContext.ElectronContext);
|
|
12
|
+
const illegalKeysCombinationKeyCount = (0, _useIllegalKeysCombination.useIllegalKeysCombination)();
|
|
13
|
+
return isElectronApp ? illegalKeysCombinationKeyCount : 0;
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useGenericSleepDetected;
|
|
7
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
function useGenericSleepDetected() {
|
|
10
|
+
const [deviceWentToSleepCount, setDeviceWentToSleepCount] = (0, _react.useState)(0);
|
|
11
|
+
(0, _react.useEffect)(() => {
|
|
12
|
+
var lastTime = new Date().getTime();
|
|
13
|
+
setInterval(function () {
|
|
14
|
+
var currentTime = new Date().getTime();
|
|
15
|
+
if (currentTime > lastTime + 2000 * 2) {
|
|
16
|
+
setDeviceWentToSleepCount(cnt => cnt + 1);
|
|
17
|
+
}
|
|
18
|
+
lastTime = currentTime;
|
|
19
|
+
}, 2000);
|
|
20
|
+
}, []);
|
|
21
|
+
return deviceWentToSleepCount;
|
|
22
|
+
}
|
|
@@ -8,6 +8,8 @@ var _react = require("react");
|
|
|
8
8
|
var _breachUtils = require("../utils/breachUtils");
|
|
9
9
|
var _useGenericPageVisibility = _interopRequireDefault(require("./useGenericPageVisibility"));
|
|
10
10
|
var _utils = require("../utils");
|
|
11
|
+
var _useGenericSleepDetected = _interopRequireDefault(require("./useGenericSleepDetected"));
|
|
12
|
+
var _useGenericIllegalKeysCombination = _interopRequireDefault(require("./useGenericIllegalKeysCombination"));
|
|
11
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
14
|
const isWebcamProcessingReliable = (0, _utils.isGPUAvailable)();
|
|
13
15
|
const useTrackBreachParameters = _ref => {
|
|
@@ -26,6 +28,10 @@ const useTrackBreachParameters = _ref => {
|
|
|
26
28
|
const recurringFetchIntervalRef = (0, _react.useRef)(null);
|
|
27
29
|
const isTabSwitched = !(0, _useGenericPageVisibility.default)(proctorParams.tabSwitch);
|
|
28
30
|
const isPageFocussed = (0, _useGenericPageVisibility.default)(proctorParams.pageFocus);
|
|
31
|
+
const illegalKeysCombinationCount = (0, _useGenericIllegalKeysCombination.default)();
|
|
32
|
+
const previousIllegalKeysCombinationCount = (0, _react.useRef)(0);
|
|
33
|
+
const sleepCount = (0, _useGenericSleepDetected.default)();
|
|
34
|
+
const previousSleepCount = (0, _react.useRef)(0);
|
|
29
35
|
const sendProctoredParamValues = (0, _react.useCallback)(function () {
|
|
30
36
|
let isBreach = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
31
37
|
let breachParam = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
@@ -49,6 +55,10 @@ const useTrackBreachParameters = _ref => {
|
|
|
49
55
|
(0, _react.useEffect)(() => {
|
|
50
56
|
const currentStats = {
|
|
51
57
|
isTabSwitched,
|
|
58
|
+
illegalKeysCombinationCount,
|
|
59
|
+
isIllegalKeysCombinationDetected: illegalKeysCombinationCount > previousIllegalKeysCombinationCount.current,
|
|
60
|
+
sleepCount,
|
|
61
|
+
isSleepDetected: sleepCount > previousSleepCount.current,
|
|
52
62
|
isFullScreen: permissions.fullscreen,
|
|
53
63
|
isWebcamDataNotReliable: !isWebcamProcessingReliable,
|
|
54
64
|
isPageFocussed
|
|
@@ -58,6 +68,8 @@ const useTrackBreachParameters = _ref => {
|
|
|
58
68
|
if (breachData) {
|
|
59
69
|
sendProctoredParamValues(true, breachData.breachedParam);
|
|
60
70
|
}
|
|
61
|
-
|
|
71
|
+
previousIllegalKeysCombinationCount.current = illegalKeysCombinationCount;
|
|
72
|
+
previousSleepCount.current = sleepCount;
|
|
73
|
+
}, [illegalKeysCombinationCount, sleepCount, isTabSwitched, isPageFocussed, permissions.fullscreen, sendProctoredParamValues, proctorParams]);
|
|
62
74
|
};
|
|
63
75
|
exports.useTrackBreachParameters = useTrackBreachParameters;
|
|
@@ -23,6 +23,12 @@ const getInitialStats = proctorParams => {
|
|
|
23
23
|
if (proctorParams.pageFocus) {
|
|
24
24
|
initialStats[_defaults.STATS_PARAMS.isPageFocussed] = _defaults.initialValues.pageFocus;
|
|
25
25
|
}
|
|
26
|
+
if (proctorParams.illegalKeysCombinationDetected) {
|
|
27
|
+
initialStats[_defaults.STATS_PARAMS.illegalKeysCombinationDetected] = _defaults.initialValues.illegalKeysCombinationDetected;
|
|
28
|
+
}
|
|
29
|
+
if (proctorParams.sleepDetected) {
|
|
30
|
+
initialStats[_defaults.STATS_PARAMS.sleepDetected] = _defaults.initialValues.sleepDetected;
|
|
31
|
+
}
|
|
26
32
|
return initialStats;
|
|
27
33
|
};
|
|
28
34
|
exports.getInitialStats = getInitialStats;
|
|
@@ -49,7 +55,11 @@ const getDataOnBreach = (statistics, currentData, proctorParams) => {
|
|
|
49
55
|
isTabSwitched,
|
|
50
56
|
isFullScreen,
|
|
51
57
|
isWebcamDataNotReliable,
|
|
52
|
-
isPageFocussed
|
|
58
|
+
isPageFocussed,
|
|
59
|
+
illegalKeysCombinationCount,
|
|
60
|
+
isIllegalKeysCombinationDetected,
|
|
61
|
+
sleepCount,
|
|
62
|
+
isSleepDetected
|
|
53
63
|
} = currentData;
|
|
54
64
|
const timestamp = Date.now();
|
|
55
65
|
const data = statistics.current;
|
|
@@ -63,6 +73,26 @@ const getDataOnBreach = (statistics, currentData, proctorParams) => {
|
|
|
63
73
|
})
|
|
64
74
|
};
|
|
65
75
|
}
|
|
76
|
+
const illegalKeyCombinationDetectedParam = _defaults.STATS_PARAMS.illegalKeysCombinationDetected;
|
|
77
|
+
if (proctorParams.illegalKeysCombinationDetected && isIllegalKeysCombinationDetected && !data[illegalKeyCombinationDetectedParam]) {
|
|
78
|
+
return {
|
|
79
|
+
breachedParam: illegalKeyCombinationDetectedParam,
|
|
80
|
+
timestamp,
|
|
81
|
+
data: _objectSpread(_objectSpread({}, data), {}, {
|
|
82
|
+
[illegalKeyCombinationDetectedParam]: illegalKeysCombinationCount
|
|
83
|
+
})
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const sleepDetectedParam = _defaults.STATS_PARAMS.sleepDetected;
|
|
87
|
+
if (proctorParams.sleepDetected && isSleepDetected && !data[sleepDetectedParam]) {
|
|
88
|
+
return {
|
|
89
|
+
breachedParam: sleepDetectedParam,
|
|
90
|
+
timestamp,
|
|
91
|
+
data: _objectSpread(_objectSpread({}, data), {}, {
|
|
92
|
+
[sleepDetectedParam]: sleepCount
|
|
93
|
+
})
|
|
94
|
+
};
|
|
95
|
+
}
|
|
66
96
|
const isTabSwitchedParam = _defaults.STATS_PARAMS.isTabSwitched;
|
|
67
97
|
if (proctorParams.tabSwitch && isTabSwitched && !data[isTabSwitchedParam]) {
|
|
68
98
|
return {
|
|
@@ -22,7 +22,9 @@ const updateStatistics = (statistics, currentStats, proctorParams) => {
|
|
|
22
22
|
isTabSwitched,
|
|
23
23
|
isFullScreen,
|
|
24
24
|
isWebcamDataReliable,
|
|
25
|
-
isPageFocussed
|
|
25
|
+
isPageFocussed,
|
|
26
|
+
isIllegalKeysCombinationDetected,
|
|
27
|
+
isSleepDetected
|
|
26
28
|
} = currentStats;
|
|
27
29
|
if (proctorParams.tabSwitch) {
|
|
28
30
|
statistics.current[_defaults.STATS_PARAMS.isTabSwitched] = isTabSwitched;
|
|
@@ -33,6 +35,12 @@ const updateStatistics = (statistics, currentStats, proctorParams) => {
|
|
|
33
35
|
if (proctorParams.pageFocus) {
|
|
34
36
|
statistics.current[_defaults.STATS_PARAMS.isPageFocussed] = isPageFocussed;
|
|
35
37
|
}
|
|
38
|
+
if (proctorParams.illegalKeysCombinationDetected) {
|
|
39
|
+
statistics.current[_defaults.STATS_PARAMS.illegalKeysCombinationDetected] = isIllegalKeysCombinationDetected;
|
|
40
|
+
}
|
|
41
|
+
if (proctorParams.sleepDetected) {
|
|
42
|
+
statistics.current[_defaults.STATS_PARAMS.sleepDetected] = isSleepDetected;
|
|
43
|
+
}
|
|
36
44
|
statistics.current.IS_WEBCAM_DATA_RELIABLE = isWebcamDataReliable;
|
|
37
45
|
};
|
|
38
46
|
exports.updateStatistics = updateStatistics;
|