@newtonschool/react_proctoring_library 0.0.74 → 0.0.75
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.
|
@@ -5,11 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = ElectronWebCam;
|
|
8
|
-
require("core-js/modules/es.promise.js");
|
|
9
|
-
require("core-js/modules/es.weak-map.js");
|
|
10
8
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
9
|
+
require("core-js/modules/es.promise.js");
|
|
11
10
|
var _react = require("react");
|
|
12
|
-
var
|
|
11
|
+
var _reactWebcam = _interopRequireDefault(require("react-webcam"));
|
|
13
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
14
|
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; }
|
|
@@ -17,9 +16,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
17
16
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
18
17
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
19
18
|
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
|
-
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); }
|
|
21
|
-
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 && {}.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; }
|
|
22
|
-
const Webcam = (0, _loadable.default)(() => Promise.resolve().then(() => _interopRequireWildcard(require('react-webcam'))));
|
|
23
19
|
function ElectronWebCam(_ref) {
|
|
24
20
|
let {
|
|
25
21
|
setAskPermissionAction,
|
|
@@ -29,19 +25,19 @@ function ElectronWebCam(_ref) {
|
|
|
29
25
|
} = _ref;
|
|
30
26
|
const {
|
|
31
27
|
permissionSetter,
|
|
32
|
-
permissions,
|
|
33
28
|
references,
|
|
34
29
|
setPermissionErrors,
|
|
35
30
|
device
|
|
36
31
|
} = (0, _react.useContext)(proctoredContext);
|
|
32
|
+
const [permissionGrantedInElectron, setPermissionGrantedInElectron] = (0, _react.useState)(false);
|
|
37
33
|
const setVideoPermission = permissionSetter.video;
|
|
38
|
-
const isVideoTurnedOn = permissions.video;
|
|
39
34
|
const webcamReference = references.webcamReference;
|
|
40
35
|
const {
|
|
41
36
|
recurring = false,
|
|
42
37
|
recurringFetchInterval = 30000
|
|
43
38
|
} = config;
|
|
44
39
|
const deviceId = device === null || device === void 0 ? void 0 : device.webCamDeviceId;
|
|
40
|
+
const [retry, setRetry] = (0, _react.useState)(0);
|
|
45
41
|
(0, _react.useEffect)(() => {
|
|
46
42
|
setAskPermissionAction(oldAskPermissionAction => _objectSpread(_objectSpread({}, oldAskPermissionAction), {}, {
|
|
47
43
|
video: async () => {
|
|
@@ -61,14 +57,6 @@ function ElectronWebCam(_ref) {
|
|
|
61
57
|
const permissionGranted = await window.electron.actions.startWebCamRecording(devices[0].deviceId);
|
|
62
58
|
if (permissionGranted) {
|
|
63
59
|
device.setWebCamDeviceId(devices[0].deviceId);
|
|
64
|
-
navigator.mediaDevices.getUserMedia({
|
|
65
|
-
video: true
|
|
66
|
-
}).then(streams => {
|
|
67
|
-
const stream = streams.getVideoTracks()[0];
|
|
68
|
-
webcamReference.current = {
|
|
69
|
-
stream
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
60
|
} else {
|
|
73
61
|
throw new Error('Error starting webcam recording');
|
|
74
62
|
}
|
|
@@ -94,7 +82,7 @@ function ElectronWebCam(_ref) {
|
|
|
94
82
|
fileUploadConfig: config.fileUploadConfig
|
|
95
83
|
});
|
|
96
84
|
}
|
|
97
|
-
|
|
85
|
+
setPermissionGrantedInElectron(true);
|
|
98
86
|
} catch (error) {
|
|
99
87
|
setPermissionErrors(oldErrors => _objectSpread(_objectSpread({}, oldErrors || {}), {}, {
|
|
100
88
|
video: (error === null || error === void 0 ? void 0 : error.message) || 'Error while taking webcam snapshot'
|
|
@@ -104,14 +92,14 @@ function ElectronWebCam(_ref) {
|
|
|
104
92
|
if (deviceId) {
|
|
105
93
|
startWebCamSnapshot();
|
|
106
94
|
}
|
|
107
|
-
}, [config.fileUploadConfig, deviceId, recurring, recurringFetchInterval,
|
|
95
|
+
}, [config.fileUploadConfig, deviceId, recurring, recurringFetchInterval, device.webCamDeviceId]);
|
|
108
96
|
(0, _react.useEffect)(() => {
|
|
109
97
|
if (deviceId) {
|
|
110
98
|
const permissionSetter = permission => {
|
|
111
|
-
|
|
99
|
+
setPermissionGrantedInElectron(permission);
|
|
112
100
|
};
|
|
113
101
|
window.electron.states.isWebCamRecordingStarted(deviceId).then(permission => {
|
|
114
|
-
|
|
102
|
+
setPermissionGrantedInElectron(permission);
|
|
115
103
|
});
|
|
116
104
|
const id = window.electron.listener.webCamSnapshotRecordingStatusChanged(deviceId, permissionSetter);
|
|
117
105
|
return () => {
|
|
@@ -119,13 +107,27 @@ function ElectronWebCam(_ref) {
|
|
|
119
107
|
};
|
|
120
108
|
}
|
|
121
109
|
}, [deviceId]);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
110
|
+
(0, _react.useEffect)(() => {
|
|
111
|
+
if (!permissionGrantedInElectron) {
|
|
112
|
+
setVideoPermission(false);
|
|
113
|
+
}
|
|
114
|
+
}, [permissionGrantedInElectron]);
|
|
115
|
+
if (!permissionGrantedInElectron) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactWebcam.default, {
|
|
119
|
+
audio: false,
|
|
120
|
+
screenshotFormat: "image/jpeg",
|
|
121
|
+
onUserMedia: () => {
|
|
122
|
+
setVideoPermission(true);
|
|
123
|
+
},
|
|
124
|
+
onUserMediaError: () => {
|
|
125
|
+
if (retry < 3) {
|
|
126
|
+
setRetry(retry + 1);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
ref: webcamReference,
|
|
130
|
+
className: "captured-video-canvas hide",
|
|
131
|
+
id: 'WEBCAM_REFERENCE_ID'
|
|
132
|
+
}, "".concat(deviceId, "-").concat(retry));
|
|
131
133
|
}
|
|
@@ -24,6 +24,15 @@ function useKishokMode(_ref) {
|
|
|
24
24
|
isFullscreen
|
|
25
25
|
} = (0, _useGenericFullScreenData.default)(isElectronApp);
|
|
26
26
|
const shouldShowProctoredComponent = (0, _breachUtils.showProctoredComponent)(proctorParams, permissions);
|
|
27
|
+
const [isDocumentFocused, setIsDocumentFocused] = (0, _react.useState)(true);
|
|
28
|
+
(0, _react.useEffect)(() => {
|
|
29
|
+
window.addEventListener('focus', () => {
|
|
30
|
+
setIsDocumentFocused(true);
|
|
31
|
+
});
|
|
32
|
+
window.addEventListener('blur', () => {
|
|
33
|
+
setIsDocumentFocused(false);
|
|
34
|
+
});
|
|
35
|
+
}, []);
|
|
27
36
|
(0, _react.useEffect)(() => {
|
|
28
37
|
const updateOnlineStatus = () => {
|
|
29
38
|
setConnectedToInternet(window.navigator.onLine);
|
|
@@ -33,11 +42,11 @@ function useKishokMode(_ref) {
|
|
|
33
42
|
updateOnlineStatus();
|
|
34
43
|
}, []);
|
|
35
44
|
(0, _react.useEffect)(() => {
|
|
36
|
-
if (typeof window !== 'undefined' && shouldShowProctoredComponent && isFullscreen && isElectronApp && connectedToInternet) {
|
|
45
|
+
if (typeof window !== 'undefined' && shouldShowProctoredComponent && isFullscreen && isElectronApp && connectedToInternet && isDocumentFocused) {
|
|
37
46
|
window.electron.actions.enableKioskMode();
|
|
38
47
|
} else {
|
|
39
48
|
var _window$electron, _window$electron$acti;
|
|
40
49
|
(_window$electron = window.electron) === null || _window$electron === void 0 ? void 0 : (_window$electron$acti = _window$electron.actions) === null || _window$electron$acti === void 0 ? void 0 : _window$electron$acti.disableKioskMode();
|
|
41
50
|
}
|
|
42
|
-
}, [isFullscreen, shouldShowProctoredComponent, isElectronApp]);
|
|
51
|
+
}, [isFullscreen, shouldShowProctoredComponent, isElectronApp, isDocumentFocused]);
|
|
43
52
|
}
|