@newtonschool/react_proctoring_library 0.0.128 → 0.0.129
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.
|
@@ -21,9 +21,9 @@ const SecondaryDevice = _ref => {
|
|
|
21
21
|
permissionSetter
|
|
22
22
|
} = (0, _react.useContext)(proctoredContext);
|
|
23
23
|
const setSecondaryDevicePermission = permissionSetter.secondaryDevice;
|
|
24
|
-
const [primaryDeviceOnline, setPrimaryDeviceOnline] = (0, _react.useState)(
|
|
25
|
-
const [secondaryDeviceOnline, setSecondaryDeviceOnline] = (0, _react.useState)(
|
|
26
|
-
const [secondaryDeviceAllPermissionGranted, setSecondaryDeviceAllPermissionGranted] = (0, _react.useState)(
|
|
24
|
+
const [primaryDeviceOnline, setPrimaryDeviceOnline] = (0, _react.useState)(true);
|
|
25
|
+
const [secondaryDeviceOnline, setSecondaryDeviceOnline] = (0, _react.useState)(true);
|
|
26
|
+
const [secondaryDeviceAllPermissionGranted, setSecondaryDeviceAllPermissionGranted] = (0, _react.useState)(true);
|
|
27
27
|
const allPermissionGranted = (0, _permission.hasAllPermissions)((0, _breachUtils.getRequiredPermissionsFromProctorParams)(proctorParams), permissions);
|
|
28
28
|
(0, _react.useEffect)(() => {
|
|
29
29
|
const cleanup = (0, _proctoringStatusUtils.setupDeviceStatusListeners)({
|
|
@@ -51,7 +51,7 @@ const SecondaryDevice = _ref => {
|
|
|
51
51
|
if (isSecondaryDevice) {
|
|
52
52
|
setSecondaryDevicePermission(secondaryDeviceOnline);
|
|
53
53
|
} else {
|
|
54
|
-
setSecondaryDevicePermission(
|
|
54
|
+
setSecondaryDevicePermission(secondaryDeviceOnline && secondaryDeviceAllPermissionGranted);
|
|
55
55
|
}
|
|
56
56
|
}, [isSecondaryDevice, primaryDeviceOnline, secondaryDeviceOnline, secondaryDeviceAllPermissionGranted, setSecondaryDevicePermission]);
|
|
57
57
|
return null;
|
|
@@ -136,6 +136,34 @@ const setupDeviceStatusListeners = _ref2 => {
|
|
|
136
136
|
}).catch(err => {
|
|
137
137
|
console.error('::[proctoringStatusUtils] Failed to mark current device disconnected:', err);
|
|
138
138
|
});
|
|
139
|
+
|
|
140
|
+
// Get initial values and update callbacks immediately
|
|
141
|
+
const applyPrimarySnapshot = snapshot => {
|
|
142
|
+
var _snapshot$val, _snapshot$val2;
|
|
143
|
+
const val = (_snapshot$val = snapshot === null || snapshot === void 0 ? void 0 : (_snapshot$val2 = snapshot.val) === null || _snapshot$val2 === void 0 ? void 0 : _snapshot$val2.call(snapshot)) !== null && _snapshot$val !== void 0 ? _snapshot$val : snapshot;
|
|
144
|
+
onPrimaryDeviceStatusChange(Boolean(val === null || val === void 0 ? void 0 : val.connected));
|
|
145
|
+
};
|
|
146
|
+
const applySecondarySnapshot = snapshot => {
|
|
147
|
+
var _snapshot$val3, _snapshot$val4;
|
|
148
|
+
const val = (_snapshot$val3 = snapshot === null || snapshot === void 0 ? void 0 : (_snapshot$val4 = snapshot.val) === null || _snapshot$val4 === void 0 ? void 0 : _snapshot$val4.call(snapshot)) !== null && _snapshot$val3 !== void 0 ? _snapshot$val3 : snapshot;
|
|
149
|
+
onSecondaryDeviceStatusChange(Boolean(val === null || val === void 0 ? void 0 : val.connected), val === null || val === void 0 ? void 0 : val.allPermissionGranted);
|
|
150
|
+
};
|
|
151
|
+
if (typeof (primaryDeviceStatusRef === null || primaryDeviceStatusRef === void 0 ? void 0 : primaryDeviceStatusRef.get) === 'function') {
|
|
152
|
+
primaryDeviceStatusRef.get().then(applyPrimarySnapshot).catch(() => {});
|
|
153
|
+
}
|
|
154
|
+
if (typeof (secondaryDeviceStatusRef === null || secondaryDeviceStatusRef === void 0 ? void 0 : secondaryDeviceStatusRef.get) === 'function') {
|
|
155
|
+
secondaryDeviceStatusRef.get().then(applySecondarySnapshot).catch(() => {});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Subscribe to updates
|
|
159
|
+
const unsubscribePrimary = onValue(primaryDeviceStatusRef, snapshot => {
|
|
160
|
+
applyPrimarySnapshot(snapshot);
|
|
161
|
+
});
|
|
162
|
+
const unsubscribeSecondary = onValue(secondaryDeviceStatusRef, snapshot => {
|
|
163
|
+
applySecondarySnapshot(snapshot);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Start heartbeat interval
|
|
139
167
|
let heartbeatIntervalId = null;
|
|
140
168
|
if (typeof window !== 'undefined' && typeof setInterval === 'function') {
|
|
141
169
|
heartbeatIntervalId = setInterval(() => {
|
|
@@ -166,14 +194,6 @@ const setupDeviceStatusListeners = _ref2 => {
|
|
|
166
194
|
});
|
|
167
195
|
}, HEARTBEAT_INTERVAL_MS);
|
|
168
196
|
}
|
|
169
|
-
const unsubscribePrimary = onValue(primaryDeviceStatusRef, snapshot => {
|
|
170
|
-
const val = snapshot.val();
|
|
171
|
-
onPrimaryDeviceStatusChange(Boolean(val === null || val === void 0 ? void 0 : val.connected));
|
|
172
|
-
});
|
|
173
|
-
const unsubscribeSecondary = onValue(secondaryDeviceStatusRef, snapshot => {
|
|
174
|
-
const val = snapshot.val();
|
|
175
|
-
onSecondaryDeviceStatusChange(Boolean(val === null || val === void 0 ? void 0 : val.connected), val === null || val === void 0 ? void 0 : val.allPermissionGranted);
|
|
176
|
-
});
|
|
177
197
|
return () => {
|
|
178
198
|
unsubscribePrimary();
|
|
179
199
|
unsubscribeSecondary();
|