@newtonschool/react_proctoring_library 0.0.10 → 0.0.11
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.
|
@@ -43,7 +43,6 @@ const ProctorApp = _ref => {
|
|
|
43
43
|
const webcamReference = (0, _react.useRef)(null);
|
|
44
44
|
const canvasReference = (0, _react.useRef)(null);
|
|
45
45
|
const statistics = (0, _react.useRef)(_defaults.INITIAL_STATISTICS);
|
|
46
|
-
const gpuAvailable = (0, _utils.isGPUAvailable)();
|
|
47
46
|
const [audioPermission, setAudioPermission] = (0, _react.useState)(false);
|
|
48
47
|
const [videoPermission, setVideoPermission] = (0, _react.useState)(false);
|
|
49
48
|
const firstFullScreenDone = (0, _react.useRef)(false);
|
|
@@ -52,10 +51,10 @@ const ProctorApp = _ref => {
|
|
|
52
51
|
setFullscreen,
|
|
53
52
|
fullScreenExitCount
|
|
54
53
|
} = (0, _hooks.useFullscreenData)(firstFullScreenDone);
|
|
55
|
-
const [userCount, lookedAwayCount] =
|
|
54
|
+
const [userCount, lookedAwayCount] = (0, _useWebcamData.default)(webcamReference, canvasReference);
|
|
56
55
|
const tabSwitchCount = (0, _hooks.useTabSwitchCount)(firstFullScreenDone);
|
|
57
56
|
(0, _react.useEffect)(() => {
|
|
58
|
-
if (
|
|
57
|
+
if (shouldSendDataOnBreach && (userCount < 0 || lookedAwayCount < 0)) {
|
|
59
58
|
(0, _utils.sendDataOnBreach)(statistics, {
|
|
60
59
|
userCount,
|
|
61
60
|
tabSwitchCount,
|
|
@@ -42,45 +42,49 @@ const getIsWatching = async (network, video) => {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
const gpuAvailable = (0, _utils.isGPUAvailable)();
|
|
46
|
+
|
|
45
47
|
function useWebcamData(webcamReference, canvasReference) {
|
|
46
|
-
const [userCount, setUserCount] = (0, _react.useState)(_defaults.initialValues.userCount);
|
|
47
|
-
const [isWatching, setIsWatching] = (0, _react.useState)(_defaults.initialValues.isWatching);
|
|
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
50
|
const [lookedAwayCount, setLookedAwayCount] = (0, _react.useState)(_defaults.initialValues.lookedAwayCount);
|
|
49
51
|
(0, _react.useEffect)(() => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
52
|
+
if (gpuAvailable) {
|
|
53
|
+
const loadBodyPixModel = async () => {
|
|
54
|
+
try {
|
|
55
|
+
const network = await bodyPix.load();
|
|
56
|
+
setInterval(async () => {
|
|
57
|
+
if ((0, _utils.isWebcamVideoValid)(webcamReference)) {
|
|
58
|
+
var _users$length;
|
|
59
|
+
|
|
60
|
+
const video = webcamReference.current.video;
|
|
61
|
+
const {
|
|
62
|
+
videoWidth,
|
|
63
|
+
videoHeight
|
|
64
|
+
} = video;
|
|
65
|
+
video.width = videoWidth;
|
|
66
|
+
video.height = videoHeight;
|
|
67
|
+
canvasReference.current.width = videoWidth;
|
|
68
|
+
canvasReference.current.height = videoHeight;
|
|
69
|
+
const users = await getUsers(network, video);
|
|
70
|
+
const count = (_users$length = users === null || users === void 0 ? void 0 : users.length) !== null && _users$length !== void 0 ? _users$length : 0;
|
|
71
|
+
setUserCount(count);
|
|
72
|
+
|
|
73
|
+
if (count) {
|
|
74
|
+
setIsWatching(getIsWatching(network, video));
|
|
75
|
+
} else {
|
|
76
|
+
setIsWatching(false);
|
|
77
|
+
}
|
|
74
78
|
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
}, _defaults.evaluateVideoIntervalInSeconds * 1000);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.log("Error Trace:", err);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
loadBodyPixModel();
|
|
87
|
+
}
|
|
84
88
|
}, [webcamReference, canvasReference]);
|
|
85
89
|
(0, _react.useEffect)(() => {
|
|
86
90
|
if (!isWatching) {
|
package/dist/utils/gpuUtils.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isGPUAvailable = void 0;
|
|
7
|
+
|
|
3
8
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
4
9
|
|
|
5
10
|
require("core-js/modules/es.array.includes.js");
|
|
@@ -19,4 +24,6 @@ const isGPUAvailable = () => {
|
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
return false;
|
|
22
|
-
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.isGPUAvailable = isGPUAvailable;
|