@newtonschool/react_proctoring_library 0.0.59 → 0.0.61
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/proctor-app/index.js +2 -6
- package/dist/constants/defaults.js +0 -9
- package/dist/constants/text.js +21 -22
- package/dist/hooks/useFullScreenData.js +4 -3
- package/dist/utils/breachUtils.js +1 -29
- package/dist/utils/webcamMicrophoneUtils.js +0 -8
- package/package.json +1 -3
- package/dist/hooks/useWebcamData.js +0 -69
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
require("core-js/modules/es.object.assign.js");
|
|
4
4
|
require("core-js/modules/es.weak-map.js");
|
|
5
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
5
6
|
Object.defineProperty(exports, "__esModule", {
|
|
6
7
|
value: true
|
|
7
8
|
});
|
|
8
9
|
exports.default = exports.ProctorApp = void 0;
|
|
9
10
|
require("core-js/modules/es.promise.js");
|
|
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
13
|
var _useWakeUpLock = require("../../hooks/useWakeUpLock");
|
|
@@ -15,7 +15,6 @@ require("./index.scss");
|
|
|
15
15
|
var _utils = require("../../utils");
|
|
16
16
|
var _hooks = require("../../hooks");
|
|
17
17
|
var _permissions = require("../permissions");
|
|
18
|
-
var _useWebcamData = _interopRequireDefault(require("../../hooks/useWebcamData"));
|
|
19
18
|
var _breachUtils = require("../../utils/breachUtils");
|
|
20
19
|
var _webcamMicrophoneUtils = require("../../utils/webcamMicrophoneUtils");
|
|
21
20
|
var _defaults = require("../../constants/defaults");
|
|
@@ -92,7 +91,6 @@ const ProctorApp = _ref => {
|
|
|
92
91
|
let breachParam = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
93
92
|
getProctorParamValues(proctoringIdentifier, statistics.current, isBreach, breachParam);
|
|
94
93
|
}, [proctoringIdentifier, getProctorParamValues]);
|
|
95
|
-
const [userCount, lookedAwayCount] = (0, _useWebcamData.default)(references.webcamReference, references.canvasReference, proctorParams);
|
|
96
94
|
const isTabSwitched = !(0, _hooks.usePageVisibility)(proctorParams.tabSwitch);
|
|
97
95
|
const isPageFocussed = (0, _useIsPageFocussed.default)(proctorParams.pageFocus);
|
|
98
96
|
(0, _react.useEffect)(() => {
|
|
@@ -109,10 +107,8 @@ const ProctorApp = _ref => {
|
|
|
109
107
|
}, [recurring, recurringFetchInterval, sendProctoredParamValues, sendWebcamSnapshot, sendScreengrab]);
|
|
110
108
|
(0, _react.useEffect)(() => {
|
|
111
109
|
const currentStats = {
|
|
112
|
-
userCount,
|
|
113
110
|
isTabSwitched,
|
|
114
111
|
isFullScreen: permissions.fullscreen,
|
|
115
|
-
lookedAwayCount,
|
|
116
112
|
isWebcamDataNotReliable: !isWebcamProcessingReliable,
|
|
117
113
|
isPageFocussed
|
|
118
114
|
};
|
|
@@ -123,7 +119,7 @@ const ProctorApp = _ref => {
|
|
|
123
119
|
sendWebcamSnapshot(true, breachData.breachedParam);
|
|
124
120
|
sendScreengrab(true, breachData.breachedParam);
|
|
125
121
|
}
|
|
126
|
-
}, [
|
|
122
|
+
}, [isTabSwitched, isPageFocussed, permissions.fullscreen, sendProctoredParamValues, sendWebcamSnapshot, sendScreengrab, proctorParams]);
|
|
127
123
|
const shouldShowProctoredComponent = (0, _breachUtils.showProctoredComponent)(proctorParams, permissions);
|
|
128
124
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
129
125
|
className: "".concat(proctorParams.copyPasteProctoring ? 'disable-copy-paste fullwidth fullheight' : 'fullwidth fullheight')
|
|
@@ -5,10 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.proctorParamsToPermission = exports.initialValues = exports.gpuTypes = exports.evaluateVideoIntervalInSeconds = exports.defaultConfig = exports.STATS_PARAMS = exports.INITIAL_STATISTICS = void 0;
|
|
7
7
|
const defaultConfig = exports.defaultConfig = {
|
|
8
|
-
people: true,
|
|
9
8
|
tabSwitch: true,
|
|
10
9
|
fullscreenExit: true,
|
|
11
|
-
lookedAway: true,
|
|
12
10
|
webcamSnapshots: true,
|
|
13
11
|
screenshareSnapshots: true,
|
|
14
12
|
copyPasteProctoring: true,
|
|
@@ -17,32 +15,25 @@ const defaultConfig = exports.defaultConfig = {
|
|
|
17
15
|
const initialValues = exports.initialValues = {
|
|
18
16
|
isTabSwitched: false,
|
|
19
17
|
pageFocus: true,
|
|
20
|
-
userCount: 0,
|
|
21
18
|
isWebcamDataNotReliable: true,
|
|
22
19
|
isWatching: true,
|
|
23
20
|
canOpenFullScreen: false,
|
|
24
21
|
isFullscreen: false,
|
|
25
|
-
lookedAwayCount: 0,
|
|
26
22
|
firstTimeFullScreen: true
|
|
27
23
|
};
|
|
28
24
|
const STATS_PARAMS = exports.STATS_PARAMS = {
|
|
29
25
|
isTabSwitched: 'IS_TAB_SWITCHED',
|
|
30
26
|
isPageFocussed: 'PAGE_FOCUS',
|
|
31
27
|
isFullscreen: 'IS_FULLSCREEN',
|
|
32
|
-
lookedAwayCount: 'LOOKED_AWAY_COUNT',
|
|
33
|
-
userCountMax: 'USER_COUNT_MAX',
|
|
34
28
|
isWebcamNotReliable: 'IS_WEBCAM_DATA_NOT_RELIABLE'
|
|
35
29
|
};
|
|
36
30
|
const INITIAL_STATISTICS = exports.INITIAL_STATISTICS = {
|
|
37
31
|
[STATS_PARAMS.isTabSwitched]: initialValues.isTabSwitched,
|
|
38
32
|
[STATS_PARAMS.isFullscreen]: initialValues.isFullscreen,
|
|
39
|
-
[STATS_PARAMS.lookedAwayCount]: initialValues.lookedAwayCount,
|
|
40
|
-
[STATS_PARAMS.userCountMax]: initialValues.userCount,
|
|
41
33
|
[STATS_PARAMS.isWebcamNotReliable]: initialValues.isWebcamDataNotReliable
|
|
42
34
|
};
|
|
43
35
|
const proctorParamsToPermission = exports.proctorParamsToPermission = {
|
|
44
36
|
fullscreenExit: 'fullscreen',
|
|
45
|
-
lookedAway: 'video',
|
|
46
37
|
webcamSnapshots: 'video',
|
|
47
38
|
screenshareSnapshots: 'screenshare'
|
|
48
39
|
};
|
package/dist/constants/text.js
CHANGED
|
@@ -3,31 +3,30 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.WATCHING_SCREEN = exports.VIDEO_UNSUPPORTED_IN_BROWSER = exports.
|
|
7
|
-
const WATCHING_SCREEN = exports.WATCHING_SCREEN =
|
|
8
|
-
const NOT_WATCHING_SCREEN = exports.NOT_WATCHING_SCREEN =
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const REQUEST_VIDEO_AUDIO_PERMISSIONS_HEADING = exports.REQUEST_VIDEO_AUDIO_PERMISSIONS_HEADING = "To access this page, you will need to give us video and audio permissions";
|
|
6
|
+
exports.WATCHING_SCREEN = exports.VIDEO_UNSUPPORTED_IN_BROWSER = exports.REQUEST_VIDEO_AUDIO_PERMISSIONS_HEADING = exports.REQUEST_VIDEO_AUDIO_PERMISSIONS_DESC = exports.REQUEST_PERMISSION = exports.PERMISSION_VIDEO = exports.PERMISSION_TITLE = exports.PERMISSION_SCREENSHARE = exports.PERMISSION_GENERIC = exports.PERMISSION_FULLSCREEN = exports.PERMISSION_AUDIO_VIDEO = exports.PERMISSION_AUDIO = exports.NO_CAMERA_AVAILABLE = exports.NO_AUDIO_DEVICE_AVAILABLE = exports.NOT_WATCHING_SCREEN = exports.MESSAGE = exports.FULLSCREEN_ERROR_MESSAGE = exports.DENY_FULLSCREEN = exports.CAMERA_UNAVAILABLE_INSECURE_CONN = exports.BROWSER_BLOCKED_PERMISSION_RESOLVED_RECHECK = exports.BROWSER_BLOCKED_PERMISSION_NEXT_STEP = exports.BROWSER_BLOCKED_PERMISSION_DIRECTION = exports.BROWSER_BLOCKED_PERMISSION_DIALOG = exports.BROWSER_BLOCKED_PERMISSION = exports.ALLOW_SCREENSHARE = exports.ALLOW_FULLSCREEN = void 0;
|
|
7
|
+
const WATCHING_SCREEN = exports.WATCHING_SCREEN = 'You are watching the screen';
|
|
8
|
+
const NOT_WATCHING_SCREEN = exports.NOT_WATCHING_SCREEN = 'You are not watching the screen';
|
|
9
|
+
const PERMISSION_TITLE = exports.PERMISSION_TITLE = 'Permissions';
|
|
10
|
+
const MESSAGE = exports.MESSAGE = 'This screen can only be accessed in fullscreen mode. Please allow us to switch your screen to fullscreen mode for continuous access of the screen.';
|
|
11
|
+
const FULLSCREEN_ERROR_MESSAGE = exports.FULLSCREEN_ERROR_MESSAGE = 'This screen is only accessible in fullscreen mode';
|
|
12
|
+
const DENY_FULLSCREEN = exports.DENY_FULLSCREEN = 'Deny';
|
|
13
|
+
const ALLOW_FULLSCREEN = exports.ALLOW_FULLSCREEN = 'Switch to Fullscreen';
|
|
14
|
+
const ALLOW_SCREENSHARE = exports.ALLOW_SCREENSHARE = 'Share Screen';
|
|
15
|
+
const NO_CAMERA_AVAILABLE = exports.NO_CAMERA_AVAILABLE = 'No Camera available for use.';
|
|
16
|
+
const NO_AUDIO_DEVICE_AVAILABLE = exports.NO_AUDIO_DEVICE_AVAILABLE = 'No audio device available for use';
|
|
17
|
+
const CAMERA_UNAVAILABLE_INSECURE_CONN = exports.CAMERA_UNAVAILABLE_INSECURE_CONN = 'Camera can only be used in secure connection. Please check that you are in https mode';
|
|
18
|
+
const VIDEO_UNSUPPORTED_IN_BROWSER = exports.VIDEO_UNSUPPORTED_IN_BROWSER = 'This page requires a browser, such as Google Chrome or Firefox, that supports the video tag.';
|
|
19
|
+
const BROWSER_BLOCKED_PERMISSION = exports.BROWSER_BLOCKED_PERMISSION = 'It seems your browser is blocked from accessing your camera and microphone.';
|
|
20
|
+
const REQUEST_VIDEO_AUDIO_PERMISSIONS_HEADING = exports.REQUEST_VIDEO_AUDIO_PERMISSIONS_HEADING = 'To access this page, you will need to give us video and audio permissions';
|
|
22
21
|
const REQUEST_VIDEO_AUDIO_PERMISSIONS_DESC = exports.REQUEST_VIDEO_AUDIO_PERMISSIONS_DESC = "Without these permissions, you won't be able to access the screen";
|
|
23
|
-
const REQUEST_PERMISSION = exports.REQUEST_PERMISSION =
|
|
24
|
-
const BROWSER_BLOCKED_PERMISSION_DIRECTION = exports.BROWSER_BLOCKED_PERMISSION_DIRECTION =
|
|
25
|
-
const BROWSER_BLOCKED_PERMISSION_DIALOG = exports.BROWSER_BLOCKED_PERMISSION_DIALOG =
|
|
26
|
-
const BROWSER_BLOCKED_PERMISSION_NEXT_STEP = exports.BROWSER_BLOCKED_PERMISSION_NEXT_STEP =
|
|
22
|
+
const REQUEST_PERMISSION = exports.REQUEST_PERMISSION = 'Request Permission';
|
|
23
|
+
const BROWSER_BLOCKED_PERMISSION_DIRECTION = exports.BROWSER_BLOCKED_PERMISSION_DIRECTION = 'Somewhere near right corner of url bar you will find icon like below, please click it.';
|
|
24
|
+
const BROWSER_BLOCKED_PERMISSION_DIALOG = exports.BROWSER_BLOCKED_PERMISSION_DIALOG = 'It will open dialog box like the one shown below, please allow us the permissions.';
|
|
25
|
+
const BROWSER_BLOCKED_PERMISSION_NEXT_STEP = exports.BROWSER_BLOCKED_PERMISSION_NEXT_STEP = 'Click on the button below, after completing above steps.';
|
|
27
26
|
const BROWSER_BLOCKED_PERMISSION_RESOLVED_RECHECK = exports.BROWSER_BLOCKED_PERMISSION_RESOLVED_RECHECK = "I've given permission, Check Again";
|
|
28
27
|
const PERMISSION_GENERIC = exports.PERMISSION_GENERIC = "This screen requires following permissions for continuous access. Without these permissions, you won't be able to access the screen.";
|
|
29
|
-
const PERMISSION_FULLSCREEN = exports.PERMISSION_FULLSCREEN =
|
|
28
|
+
const PERMISSION_FULLSCREEN = exports.PERMISSION_FULLSCREEN = 'Please allow us to switch your screen to fullscreen mode.';
|
|
30
29
|
const PERMISSION_AUDIO_VIDEO = exports.PERMISSION_AUDIO_VIDEO = "Your browser or system settings have disallowed Microphone and Camera permissions. Please permit this website to access microphone and camera. Refresh after you've given the permission to access the screen";
|
|
31
30
|
const PERMISSION_VIDEO = exports.PERMISSION_VIDEO = "Your browser or system settings have disallowed Camera permissions. Please permit this website to access the camera. Refresh after you've given the permission to access the screen";
|
|
32
31
|
const PERMISSION_AUDIO = exports.PERMISSION_AUDIO = "Your browser or system settings have disallowed Microphone permissions. Please permit this website to access the microphone. Refresh after you've given the permission to access the screen";
|
|
33
|
-
const PERMISSION_SCREENSHARE = exports.PERMISSION_SCREENSHARE =
|
|
32
|
+
const PERMISSION_SCREENSHARE = exports.PERMISSION_SCREENSHARE = 'Please share your entire screen';
|
|
@@ -12,12 +12,13 @@ function useFullscreenData(isProctorParam) {
|
|
|
12
12
|
const fullScreenElement = (0, _react.useRef)(document.documentElement);
|
|
13
13
|
const [isFullscreen, setIsFullscreen] = (0, _react.useState)(document[browserFullscreenElementProp] != null);
|
|
14
14
|
const setFullscreen = () => {
|
|
15
|
+
var _fullScreenElement$cu, _fullScreenElement$cu2, _fullScreenElement$cu3, _fullScreenElement$cu4, _fullScreenElement$cu5, _fullScreenElement$cu6;
|
|
15
16
|
if (!fullScreenElement || !fullScreenElement.current) {
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
18
|
-
fullScreenElement.current.requestFullscreen({
|
|
19
|
-
navigationUI:
|
|
20
|
-
}).then(() => {
|
|
19
|
+
(((_fullScreenElement$cu = (_fullScreenElement$cu2 = fullScreenElement.current).requestFullscreen) === null || _fullScreenElement$cu === void 0 ? void 0 : _fullScreenElement$cu.call(_fullScreenElement$cu2, {
|
|
20
|
+
navigationUI: 'hide'
|
|
21
|
+
})) || ((_fullScreenElement$cu3 = (_fullScreenElement$cu4 = fullScreenElement.current).mozRequestFullscreen) === null || _fullScreenElement$cu3 === void 0 ? void 0 : _fullScreenElement$cu3.call(_fullScreenElement$cu4)) || ((_fullScreenElement$cu5 = (_fullScreenElement$cu6 = fullScreenElement.current).webkitRequestFullscreen) === null || _fullScreenElement$cu5 === void 0 ? void 0 : _fullScreenElement$cu5.call(_fullScreenElement$cu6))).then(() => {
|
|
21
22
|
setIsFullscreen(document[browserFullscreenElementProp] != null);
|
|
22
23
|
}).catch(err => {
|
|
23
24
|
setIsFullscreen(false);
|
|
@@ -14,18 +14,12 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
|
14
14
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
15
|
const getInitialStats = proctorParams => {
|
|
16
16
|
const initialStats = {};
|
|
17
|
-
if (proctorParams.people) {
|
|
18
|
-
initialStats[_defaults.STATS_PARAMS.userCountMax] = _defaults.initialValues.userCount;
|
|
19
|
-
}
|
|
20
17
|
if (proctorParams.tabSwitch) {
|
|
21
18
|
initialStats[_defaults.STATS_PARAMS.isTabSwitched] = _defaults.initialValues.isTabSwitched;
|
|
22
19
|
}
|
|
23
20
|
if (proctorParams.fullscreenExit) {
|
|
24
21
|
initialStats[_defaults.STATS_PARAMS.isFullscreen] = _defaults.initialValues.isFullscreen;
|
|
25
22
|
}
|
|
26
|
-
if (proctorParams.lookedAway) {
|
|
27
|
-
initialStats[_defaults.STATS_PARAMS.lookedAwayCount] = _defaults.initialValues.lookedAwayCount;
|
|
28
|
-
}
|
|
29
23
|
if (proctorParams.pageFocus) {
|
|
30
24
|
initialStats[_defaults.STATS_PARAMS.isPageFocussed] = _defaults.initialValues.pageFocus;
|
|
31
25
|
}
|
|
@@ -42,7 +36,7 @@ const getRequiredPermissionsFromProctorParams = proctorParams => {
|
|
|
42
36
|
return requiredPermissions;
|
|
43
37
|
};
|
|
44
38
|
exports.getRequiredPermissionsFromProctorParams = getRequiredPermissionsFromProctorParams;
|
|
45
|
-
const isWebcamRequired = proctorParams => proctorParams.
|
|
39
|
+
const isWebcamRequired = proctorParams => proctorParams.webcamSnapshots;
|
|
46
40
|
exports.isWebcamRequired = isWebcamRequired;
|
|
47
41
|
const isAudioRequired = () => false;
|
|
48
42
|
exports.isAudioRequired = isAudioRequired;
|
|
@@ -52,10 +46,8 @@ const showProctoredComponent = (proctorParams, permissions) => {
|
|
|
52
46
|
exports.showProctoredComponent = showProctoredComponent;
|
|
53
47
|
const getDataOnBreach = (statistics, currentData, proctorParams) => {
|
|
54
48
|
const {
|
|
55
|
-
userCount,
|
|
56
49
|
isTabSwitched,
|
|
57
50
|
isFullScreen,
|
|
58
|
-
lookedAwayCount,
|
|
59
51
|
isWebcamDataNotReliable,
|
|
60
52
|
isPageFocussed
|
|
61
53
|
} = currentData;
|
|
@@ -71,16 +63,6 @@ const getDataOnBreach = (statistics, currentData, proctorParams) => {
|
|
|
71
63
|
})
|
|
72
64
|
};
|
|
73
65
|
}
|
|
74
|
-
const userCountMaxParam = _defaults.STATS_PARAMS.userCountMax;
|
|
75
|
-
if (proctorParams.people && data[userCountMaxParam] < userCount) {
|
|
76
|
-
return {
|
|
77
|
-
breachedParam: userCountMaxParam,
|
|
78
|
-
timestamp,
|
|
79
|
-
data: _objectSpread(_objectSpread({}, data), {}, {
|
|
80
|
-
[userCountMaxParam]: userCount
|
|
81
|
-
})
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
66
|
const isTabSwitchedParam = _defaults.STATS_PARAMS.isTabSwitched;
|
|
85
67
|
if (proctorParams.tabSwitch && isTabSwitched && !data[isTabSwitchedParam]) {
|
|
86
68
|
return {
|
|
@@ -111,15 +93,5 @@ const getDataOnBreach = (statistics, currentData, proctorParams) => {
|
|
|
111
93
|
})
|
|
112
94
|
};
|
|
113
95
|
}
|
|
114
|
-
const lookedAwayParam = _defaults.STATS_PARAMS.lookedAwayCount;
|
|
115
|
-
if (proctorParams.lookedAway && data[lookedAwayParam] !== lookedAwayCount) {
|
|
116
|
-
return {
|
|
117
|
-
breachedParam: lookedAwayParam,
|
|
118
|
-
timestamp,
|
|
119
|
-
data: _objectSpread(_objectSpread({}, data), {}, {
|
|
120
|
-
[lookedAwayParam]: lookedAwayCount
|
|
121
|
-
})
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
96
|
};
|
|
125
97
|
exports.getDataOnBreach = getDataOnBreach;
|
|
@@ -21,8 +21,6 @@ const updateStatistics = (statistics, currentStats, proctorParams) => {
|
|
|
21
21
|
const {
|
|
22
22
|
isTabSwitched,
|
|
23
23
|
isFullScreen,
|
|
24
|
-
lookedAwayCount,
|
|
25
|
-
userCount,
|
|
26
24
|
isWebcamDataReliable,
|
|
27
25
|
isPageFocussed
|
|
28
26
|
} = currentStats;
|
|
@@ -32,12 +30,6 @@ const updateStatistics = (statistics, currentStats, proctorParams) => {
|
|
|
32
30
|
if (proctorParams.fullscreenExit) {
|
|
33
31
|
statistics.current[_defaults.STATS_PARAMS.isFullscreen] = isFullScreen;
|
|
34
32
|
}
|
|
35
|
-
if (proctorParams.lookedAway) {
|
|
36
|
-
statistics.current[_defaults.STATS_PARAMS.lookedAwayCount] = lookedAwayCount;
|
|
37
|
-
}
|
|
38
|
-
if (proctorParams.people) {
|
|
39
|
-
statistics.current[_defaults.STATS_PARAMS.userCountMax] = Math.max(userCount, statistics.current[_defaults.STATS_PARAMS.userCountMax]);
|
|
40
|
-
}
|
|
41
33
|
if (proctorParams.pageFocus) {
|
|
42
34
|
statistics.current[_defaults.STATS_PARAMS.isPageFocussed] = isPageFocussed;
|
|
43
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newtonschool/react_proctoring_library",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61",
|
|
4
4
|
"description": "Used to proctor online tests",
|
|
5
5
|
"author": "ayushkagrawal,shreyachandra,weastel",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
""
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@tensorflow-models/coco-ssd": "2.2.2",
|
|
17
|
-
"@tensorflow/tfjs": "3.9.0",
|
|
18
16
|
"bootstrap": "5.1.3",
|
|
19
17
|
"core-js": "3.22.7",
|
|
20
18
|
"react-bootstrap": "2.0.4",
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/es.weak-map.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = useWebcamData;
|
|
8
|
-
require("core-js/modules/es.promise.js");
|
|
9
|
-
require("core-js/modules/web.dom-collections.iterator.js");
|
|
10
|
-
var _react = require("react");
|
|
11
|
-
var cocoSsd = _interopRequireWildcard(require("@tensorflow-models/coco-ssd"));
|
|
12
|
-
var tf = _interopRequireWildcard(require("@tensorflow/tfjs"));
|
|
13
|
-
var _utils = require("../utils");
|
|
14
|
-
var _defaults = require("../constants/defaults");
|
|
15
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
16
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
-
const getUserCount = async (model, image) => {
|
|
18
|
-
try {
|
|
19
|
-
let predictions = await model.detect(image);
|
|
20
|
-
let numOfUsers = 0;
|
|
21
|
-
predictions.forEach(prediction => {
|
|
22
|
-
if (prediction.class === 'person') {
|
|
23
|
-
numOfUsers += 1;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return numOfUsers;
|
|
27
|
-
} catch (err) {}
|
|
28
|
-
};
|
|
29
|
-
function useWebcamData(webcamReference, canvasReference, proctorParams) {
|
|
30
|
-
const [userCount, setUserCount] = (0, _react.useState)(_defaults.initialValues.userCount);
|
|
31
|
-
const isWatching = (0, _react.useState)(_defaults.initialValues.isWatching);
|
|
32
|
-
const [lookedAwayCount, setLookedAwayCount] = (0, _react.useState)(_defaults.initialValues.lookedAwayCount);
|
|
33
|
-
(0, _react.useEffect)(() => {
|
|
34
|
-
if (proctorParams.people && proctorParams.lookedAwayCount && (0, _utils.isGPUAvailable)()) {
|
|
35
|
-
const loadCocoSSDModel = async () => {
|
|
36
|
-
try {
|
|
37
|
-
const model = await cocoSsd.load();
|
|
38
|
-
setInterval(async () => {
|
|
39
|
-
if ((0, _utils.isWebcamVideoValid)(webcamReference)) {
|
|
40
|
-
const video = webcamReference.current.video;
|
|
41
|
-
const {
|
|
42
|
-
videoWidth,
|
|
43
|
-
videoHeight
|
|
44
|
-
} = video;
|
|
45
|
-
const b64Snapshot = webcamReference.current.getScreenshot();
|
|
46
|
-
const webcamSnapShot = new Image(videoWidth, videoHeight);
|
|
47
|
-
webcamSnapShot.src = b64Snapshot;
|
|
48
|
-
webcamSnapShot.onload = async () => {
|
|
49
|
-
const count = await getUserCount(model, webcamSnapShot);
|
|
50
|
-
setUserCount(count);
|
|
51
|
-
};
|
|
52
|
-
canvasReference.current.width = videoWidth;
|
|
53
|
-
canvasReference.current.height = videoHeight;
|
|
54
|
-
}
|
|
55
|
-
}, _defaults.evaluateVideoIntervalInSeconds * 1000);
|
|
56
|
-
} catch (err) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
loadCocoSSDModel();
|
|
61
|
-
}
|
|
62
|
-
}, [webcamReference, canvasReference, proctorParams.webcamSnapshots, proctorParams.people, proctorParams.lookedAwayCount]);
|
|
63
|
-
(0, _react.useEffect)(() => {
|
|
64
|
-
if (!isWatching) {
|
|
65
|
-
setLookedAwayCount(lookedAwayCount => lookedAwayCount + 1);
|
|
66
|
-
}
|
|
67
|
-
}, [isWatching]);
|
|
68
|
-
return [userCount, lookedAwayCount];
|
|
69
|
-
}
|