@newtonschool/react_proctoring_library 0.0.76 → 0.0.78

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.
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = exports.ProctorApp = void 0;
9
9
  require("core-js/modules/web.dom-collections.iterator.js");
10
+ require("core-js/modules/es.promise.js");
10
11
  var _react = _interopRequireWildcard(require("react"));
11
12
  require("./index.scss");
12
13
  var _permissions = require("../permissions");
@@ -64,12 +65,14 @@ const ProctorApp = _ref => {
64
65
  const CustomPermissionView = customPermissionView;
65
66
  const proctorParams = (0, _react.useMemo)(() => _objectSpread(_objectSpread({}, _defaults.defaultConfig), config.proctorParams), [config.proctorParams]);
66
67
  const shouldShowProctoredComponent = (0, _breachUtils.showProctoredComponent)(proctorParams, permissions);
67
- const askPermission = (0, _react.useCallback)(requiredPermissions => {
68
+ const askPermission = (0, _react.useCallback)(async requiredPermissions => {
69
+ const allPromises = [];
68
70
  requiredPermissions.forEach(element => {
69
71
  if (!permissions[element] && askPermissionAction[element]) {
70
- askPermissionAction[element]();
72
+ allPromises.push(askPermissionAction[element]());
71
73
  }
72
74
  });
75
+ await Promise.all(allPromises);
73
76
  }, [permissions, askPermissionAction]);
74
77
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
75
78
  className: "".concat(proctorParams.copyPasteProctoring ? 'disable-copy-paste fullwidth fullheight' : 'fullwidth fullheight'),
@@ -43,6 +43,7 @@ const ProctoredContextApp = _ref => {
43
43
  screenshare: null
44
44
  });
45
45
  const [screensharePermission, setScreensharePermission] = (0, _react.useState)();
46
+ const [_, setUpdateId] = (0, _react.useState)(0);
46
47
  const webcamReference = (0, _react.useRef)(null);
47
48
  const screenshareReference = (0, _react.useRef)(null);
48
49
  const [screenshareStream, setScreenshareStream] = (0, _react.useState)(null);
@@ -57,6 +58,9 @@ const ProctoredContextApp = _ref => {
57
58
  fullscreen: isFullscreen,
58
59
  screenshare: screensharePermission
59
60
  }), [videoPermission, audioPermisison, isFullscreen, screensharePermission]);
61
+ const forceUpdate = () => {
62
+ setUpdateId(oldId => oldId + 1);
63
+ };
60
64
  const endTest = () => {
61
65
  if (isElectronApp) {
62
66
  window.electron.actions.stopProctoring();
@@ -91,7 +95,8 @@ const ProctoredContextApp = _ref => {
91
95
  webcamReference,
92
96
  screenshareReference
93
97
  },
94
- screenshareStream
98
+ screenshareStream,
99
+ forceUpdate
95
100
  }),
96
101
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ElectronContext.ElectronContextProvider, {
97
102
  value: isElectronApp,
@@ -29,7 +29,7 @@ function ElectronScreenShare(_ref) {
29
29
  (0, _react.useEffect)(() => {
30
30
  setAskPermissionAction(oldAskPermissionAction => _objectSpread(_objectSpread({}, oldAskPermissionAction), {}, {
31
31
  screenshare: async () => {
32
- device.setScreenShareDeviceId(false);
32
+ device.setScreenShareDeviceId(undefined);
33
33
  setPermissionErrors(oldErrors => _objectSpread(_objectSpread({}, oldErrors || {}), {}, {
34
34
  screenshare: null
35
35
  }));
@@ -89,18 +89,16 @@ function ElectronScreenShare(_ref) {
89
89
  }
90
90
  }, [streamDeviceId, config]);
91
91
  (0, _react.useEffect)(() => {
92
- if (streamDeviceId) {
93
- const permissionSetter = permission => {
94
- setScreensharePermission(permission);
95
- };
96
- window.electron.states.isScreenShareRecordingStarted(streamDeviceId).then(recordingStarted => {
97
- permissionSetter(recordingStarted);
98
- });
99
- const id = window.electron.listener.screenShareRecordingStatusChanged(streamDeviceId, permissionSetter);
100
- return () => {
101
- window.electron.listener.removeListener(id, permissionSetter);
102
- };
103
- }
92
+ const permissionSetter = permission => {
93
+ setScreensharePermission(permission);
94
+ };
95
+ window.electron.states.isScreenShareRecordingStarted(streamDeviceId).then(recordingStarted => {
96
+ permissionSetter(recordingStarted);
97
+ });
98
+ const id = window.electron.listener.screenShareRecordingStatusChanged(streamDeviceId, permissionSetter);
99
+ return () => {
100
+ window.electron.listener.removeListener(id, permissionSetter);
101
+ };
104
102
  }, [streamDeviceId]);
105
103
  return null;
106
104
  }
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = ElectronWebCam;
8
8
  require("core-js/modules/es.array.includes.js");
9
9
  require("core-js/modules/es.string.includes.js");
10
- require("core-js/modules/web.dom-collections.iterator.js");
11
10
  require("core-js/modules/es.promise.js");
12
11
  var _react = require("react");
13
12
  var _reactWebcam = _interopRequireDefault(require("react-webcam"));
@@ -34,10 +33,11 @@ function ElectronWebCam(_ref) {
34
33
  const {
35
34
  permissionSetter,
36
35
  references,
36
+ permissions,
37
37
  setPermissionErrors,
38
- device
38
+ device,
39
+ forceUpdate
39
40
  } = (0, _react.useContext)(proctoredContext);
40
- const [permissionGrantedInElectron, setPermissionGrantedInElectron] = (0, _react.useState)(false);
41
41
  const setVideoPermission = permissionSetter.video;
42
42
  const webcamReference = references.webcamReference;
43
43
  const {
@@ -45,7 +45,6 @@ function ElectronWebCam(_ref) {
45
45
  recurringFetchInterval = 30000
46
46
  } = config;
47
47
  const deviceId = device === null || device === void 0 ? void 0 : device.webCamDeviceId;
48
- const [retry, setRetry] = (0, _react.useState)(0);
49
48
  (0, _react.useEffect)(() => {
50
49
  setAskPermissionAction(oldAskPermissionAction => _objectSpread(_objectSpread({}, oldAskPermissionAction), {}, {
51
50
  video: async () => {
@@ -94,7 +93,7 @@ function ElectronWebCam(_ref) {
94
93
  fileUploadConfig: config.fileUploadConfig
95
94
  });
96
95
  }
97
- setPermissionGrantedInElectron(true);
96
+ setVideoPermission(true);
98
97
  } catch (error) {
99
98
  setPermissionErrors(oldErrors => _objectSpread(_objectSpread({}, oldErrors || {}), {}, {
100
99
  video: (error === null || error === void 0 ? void 0 : error.message) || 'Error while taking webcam snapshot'
@@ -108,10 +107,10 @@ function ElectronWebCam(_ref) {
108
107
  (0, _react.useEffect)(() => {
109
108
  if (deviceId) {
110
109
  const permissionSetter = permission => {
111
- setPermissionGrantedInElectron(permission);
110
+ setVideoPermission(permission);
112
111
  };
113
112
  window.electron.states.isWebCamRecordingStarted(deviceId).then(permission => {
114
- setPermissionGrantedInElectron(permission);
113
+ setVideoPermission(true);
115
114
  });
116
115
  const id = window.electron.listener.webCamSnapshotRecordingStatusChanged(deviceId, permissionSetter);
117
116
  return () => {
@@ -119,27 +118,17 @@ function ElectronWebCam(_ref) {
119
118
  };
120
119
  }
121
120
  }, [deviceId]);
122
- (0, _react.useEffect)(() => {
123
- if (!permissionGrantedInElectron) {
124
- setVideoPermission(false);
125
- }
126
- }, [permissionGrantedInElectron]);
127
- if (!permissionGrantedInElectron) {
121
+ if (!permissions.video) {
128
122
  return;
129
123
  }
130
124
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactWebcam.default, {
131
125
  audio: false,
132
126
  screenshotFormat: "image/jpeg",
133
127
  onUserMedia: () => {
134
- setVideoPermission(true);
135
- },
136
- onUserMediaError: () => {
137
- if (retry < 3) {
138
- setRetry(retry + 1);
139
- }
128
+ forceUpdate(true);
140
129
  },
141
130
  ref: webcamReference,
142
131
  className: "captured-video-canvas hide",
143
132
  id: 'WEBCAM_REFERENCE_ID'
144
- }, "".concat(deviceId, "-").concat(retry));
133
+ });
145
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newtonschool/react_proctoring_library",
3
- "version": "0.0.76",
3
+ "version": "0.0.78",
4
4
  "description": "Used to proctor online tests",
5
5
  "author": "ayushkagrawal,shreyachandra,weastel",
6
6
  "main": "dist/index.js",