@newtonschool/react_proctoring_library 0.0.12 → 0.0.13
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/ProctorApp.js +12 -8
- package/dist/components/activity-tracker/index.js +1 -0
- package/dist/constants/defaults.js +1 -1
- package/dist/hooks/useWebcamData.js +2 -8
- package/dist/utils/breachUtils.js +9 -3
- package/dist/utils/index.js +6 -0
- package/dist/utils/webcamMicrophoneUtils.js +16 -3
- package/package.json +1 -1
|
@@ -27,6 +27,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
27
27
|
|
|
28
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; }
|
|
29
29
|
|
|
30
|
+
const isWebcamProcessingReliable = (0, _utils.isGPUAvailable)();
|
|
31
|
+
|
|
30
32
|
const ProctorApp = _ref => {
|
|
31
33
|
let {
|
|
32
34
|
proctoringIdentifier,
|
|
@@ -58,17 +60,19 @@ const ProctorApp = _ref => {
|
|
|
58
60
|
(0, _utils.removeStatsFromLocalStorage)(proctoringIdentifier);
|
|
59
61
|
}, [proctoringIdentifier]);
|
|
60
62
|
(0, _react.useEffect)(() => {
|
|
63
|
+
const currentStats = {
|
|
64
|
+
userCount,
|
|
65
|
+
tabSwitchCount,
|
|
66
|
+
fullScreenExitCount,
|
|
67
|
+
lookedAwayCount,
|
|
68
|
+
isWebcamDataReliable: isWebcamProcessingReliable
|
|
69
|
+
};
|
|
70
|
+
|
|
61
71
|
if (shouldSendDataOnBreach) {
|
|
62
|
-
(0, _utils.sendDataOnBreach)(statistics,
|
|
63
|
-
userCount,
|
|
64
|
-
tabSwitchCount,
|
|
65
|
-
fullScreenExitCount,
|
|
66
|
-
lookedAwayCount,
|
|
67
|
-
isWebcamDataReliable
|
|
68
|
-
}, proctoringIdentifier, sendData);
|
|
72
|
+
(0, _utils.sendDataOnBreach)(statistics, currentStats, proctoringIdentifier, sendData, webcamReference);
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
(0, _utils.updateStatistics)(statistics,
|
|
75
|
+
(0, _utils.updateStatistics)(statistics, currentStats);
|
|
72
76
|
(0, _utils.addOrUpdateStatsToLocalStorage)(proctoringIdentifier, statistics.current);
|
|
73
77
|
}, [userCount, tabSwitchCount, fullScreenExitCount, lookedAwayCount, isWebcamDataReliable, proctoringIdentifier, sendData, shouldSendDataOnBreach]);
|
|
74
78
|
|
|
@@ -59,6 +59,7 @@ const ActivityTracker = _ref => {
|
|
|
59
59
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactWebcam.default, {
|
|
60
60
|
audio: true,
|
|
61
61
|
muted: true,
|
|
62
|
+
screenshotFormat: "image/jpeg",
|
|
62
63
|
ref: webcamReference,
|
|
63
64
|
onUserMedia: stream => {
|
|
64
65
|
if (!isChrome) {
|
|
@@ -38,5 +38,5 @@ const glancePercentageToPass = 60;
|
|
|
38
38
|
exports.glancePercentageToPass = glancePercentageToPass;
|
|
39
39
|
const evaluateVideoIntervalInSeconds = 1;
|
|
40
40
|
exports.evaluateVideoIntervalInSeconds = evaluateVideoIntervalInSeconds;
|
|
41
|
-
const gpuTypes = ["apple", "amd", "radeon", "nvidia", "geforce"];
|
|
41
|
+
const gpuTypes = ["intel", "apple", "amd", "radeon", "nvidia", "geforce"];
|
|
42
42
|
exports.gpuTypes = gpuTypes;
|
|
@@ -42,18 +42,12 @@ const getIsWatching = async (network, video) => {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
const deviceHasGPU = (0, _utils.isGPUAvailable)();
|
|
46
|
-
|
|
47
45
|
function useWebcamData(webcamReference, canvasReference) {
|
|
48
46
|
const [userCount, setUserCount] = (0, _react.useState)(_defaults.initialValues.userCount);
|
|
49
47
|
const [isWatching, setIsWatching] = (0, _react.useState)(_defaults.initialValues.isWatching);
|
|
50
48
|
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
|
-
}, []);
|
|
55
49
|
(0, _react.useEffect)(() => {
|
|
56
|
-
if (
|
|
50
|
+
if ((0, _utils.isGPUAvailable)()) {
|
|
57
51
|
const loadBodyPixModel = async () => {
|
|
58
52
|
try {
|
|
59
53
|
const network = await bodyPix.load();
|
|
@@ -95,5 +89,5 @@ function useWebcamData(webcamReference, canvasReference) {
|
|
|
95
89
|
setLookedAwayCount(lookedAwayCount => lookedAwayCount + 1);
|
|
96
90
|
}
|
|
97
91
|
}, [isWatching]);
|
|
98
|
-
return [userCount, lookedAwayCount
|
|
92
|
+
return [userCount, lookedAwayCount];
|
|
99
93
|
}
|
|
@@ -5,13 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.sendDataOnBreach = void 0;
|
|
7
7
|
|
|
8
|
+
var _ = require(".");
|
|
9
|
+
|
|
8
10
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
11
|
|
|
10
12
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
13
|
|
|
12
14
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
15
|
|
|
14
|
-
const sendDataOnBreach = (statistics, currentData, proctoringIdentifier, sendData) => {
|
|
16
|
+
const sendDataOnBreach = (statistics, currentData, proctoringIdentifier, sendData, webcamReference) => {
|
|
15
17
|
const {
|
|
16
18
|
userCount,
|
|
17
19
|
tabSwitchCount,
|
|
@@ -34,13 +36,15 @@ const sendDataOnBreach = (statistics, currentData, proctoringIdentifier, sendDat
|
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
if (data.USER_COUNT_MAX < userCount) {
|
|
39
|
+
const webcamSnapshot = (0, _.captureWebcamSnapshot)(webcamReference);
|
|
37
40
|
sendData({
|
|
38
41
|
proctoringIdentifier,
|
|
39
42
|
breach: "USER_COUNT_MAX",
|
|
40
43
|
timestamp,
|
|
41
44
|
data: _objectSpread(_objectSpread({}, data), {}, {
|
|
42
45
|
USER_COUNT_MAX: userCount
|
|
43
|
-
})
|
|
46
|
+
}),
|
|
47
|
+
webcamSnapshot
|
|
44
48
|
});
|
|
45
49
|
}
|
|
46
50
|
|
|
@@ -67,13 +71,15 @@ const sendDataOnBreach = (statistics, currentData, proctoringIdentifier, sendDat
|
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
if (data.LOOKED_AWAY_COUNT !== lookedAwayCount) {
|
|
74
|
+
const webcamSnapshot = (0, _.captureWebcamSnapshot)(webcamReference);
|
|
70
75
|
sendData({
|
|
71
76
|
proctoringIdentifier,
|
|
72
77
|
breach: "LOOKED_AWAY_COUNT",
|
|
73
78
|
timestamp,
|
|
74
79
|
data: _objectSpread(_objectSpread({}, data), {}, {
|
|
75
80
|
LOOKED_AWAY_COUNT: lookedAwayCount
|
|
76
|
-
})
|
|
81
|
+
}),
|
|
82
|
+
webcamSnapshot
|
|
77
83
|
});
|
|
78
84
|
}
|
|
79
85
|
};
|
package/dist/utils/index.js
CHANGED
|
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "addOrUpdateStatsToLocalStorage", {
|
|
|
9
9
|
return _localStorageUtils.addOrUpdateStatsToLocalStorage;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "captureWebcamSnapshot", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _webcamMicrophoneUtils.captureWebcamSnapshot;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
Object.defineProperty(exports, "getAudioPermission", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function get() {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.updateVideoPermissions = exports.updateStatistics = exports.updateAudioPermissions = exports.isWebcamVideoValid = exports.getVideoPermissionQuery = exports.getVideoPermission = exports.getGlancePercentage = exports.getAudioVideoPermission = exports.getAudioPermissionQuery = exports.getAudioPermission = void 0;
|
|
6
|
+
exports.updateVideoPermissions = exports.updateStatistics = exports.updateAudioPermissions = exports.isWebcamVideoValid = exports.getVideoPermissionQuery = exports.getVideoPermission = exports.getGlancePercentage = exports.getAudioVideoPermission = exports.getAudioPermissionQuery = exports.getAudioPermission = exports.captureWebcamSnapshot = void 0;
|
|
7
7
|
|
|
8
8
|
var _ = require(".");
|
|
9
9
|
|
|
@@ -11,7 +11,14 @@ const isWebcamVideoValid = webcamReference => webcamReference !== null && webcam
|
|
|
11
11
|
|
|
12
12
|
exports.isWebcamVideoValid = isWebcamVideoValid;
|
|
13
13
|
|
|
14
|
-
const updateStatistics = (statistics,
|
|
14
|
+
const updateStatistics = (statistics, currentStats) => {
|
|
15
|
+
const {
|
|
16
|
+
tabSwitchCount,
|
|
17
|
+
fullScreenExitCount,
|
|
18
|
+
lookedAwayCount,
|
|
19
|
+
userCount,
|
|
20
|
+
isWebcamDataReliable
|
|
21
|
+
} = currentStats;
|
|
15
22
|
statistics.current.TAB_SWITCH_COUNT = tabSwitchCount;
|
|
16
23
|
statistics.current.FULLSCREEN_EXIT_COUNT = fullScreenExitCount;
|
|
17
24
|
statistics.current.LOOKED_AWAY_COUNT = lookedAwayCount;
|
|
@@ -113,4 +120,10 @@ const getAudioPermissionQuery = () => navigator.permissions.query({
|
|
|
113
120
|
name: "microphone"
|
|
114
121
|
});
|
|
115
122
|
|
|
116
|
-
exports.getAudioPermissionQuery = getAudioPermissionQuery;
|
|
123
|
+
exports.getAudioPermissionQuery = getAudioPermissionQuery;
|
|
124
|
+
|
|
125
|
+
const captureWebcamSnapshot = webcamReference => {
|
|
126
|
+
return webcamReference.current.getScreenshot();
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
exports.captureWebcamSnapshot = captureWebcamSnapshot;
|