@monkvision/camera-web 4.0.11 → 4.0.13
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.
|
@@ -26,6 +26,17 @@ export declare enum UserMediaErrorType {
|
|
|
26
26
|
/**
|
|
27
27
|
* The camera stream couldn't be fetched because the web page does not have the permissions to access the camera.
|
|
28
28
|
*/
|
|
29
|
+
WEBPAGE_NOT_ALLOWED = "webpage_not_allowed",
|
|
30
|
+
/**
|
|
31
|
+
* The camera stream couldn't be fetched because the camera permissions are not granted to the browser in the device
|
|
32
|
+
* settings.
|
|
33
|
+
*/
|
|
34
|
+
BROWSER_NOT_ALLOWED = "browser_not_allowed",
|
|
35
|
+
/**
|
|
36
|
+
* The camera stream couldn't be fetched, but the app is unable to know if it is because of the website or
|
|
37
|
+
* the browser not being allowed to have camera permission access. This error is usually returned on Firefox and
|
|
38
|
+
* other similar browsers where `navigator.permissions.query` is not supported for videoinput devices.
|
|
39
|
+
*/
|
|
29
40
|
NOT_ALLOWED = "not_allowed",
|
|
30
41
|
/**
|
|
31
42
|
* The camera stream was successfully fetched, but it could be processed. This error can happen for the following
|
|
@@ -108,6 +108,17 @@ var UserMediaErrorType;
|
|
|
108
108
|
/**
|
|
109
109
|
* The camera stream couldn't be fetched because the web page does not have the permissions to access the camera.
|
|
110
110
|
*/
|
|
111
|
+
UserMediaErrorType["WEBPAGE_NOT_ALLOWED"] = "webpage_not_allowed";
|
|
112
|
+
/**
|
|
113
|
+
* The camera stream couldn't be fetched because the camera permissions are not granted to the browser in the device
|
|
114
|
+
* settings.
|
|
115
|
+
*/
|
|
116
|
+
UserMediaErrorType["BROWSER_NOT_ALLOWED"] = "browser_not_allowed";
|
|
117
|
+
/**
|
|
118
|
+
* The camera stream couldn't be fetched, but the app is unable to know if it is because of the website or
|
|
119
|
+
* the browser not being allowed to have camera permission access. This error is usually returned on Firefox and
|
|
120
|
+
* other similar browsers where `navigator.permissions.query` is not supported for videoinput devices.
|
|
121
|
+
*/
|
|
111
122
|
UserMediaErrorType["NOT_ALLOWED"] = "not_allowed";
|
|
112
123
|
/**
|
|
113
124
|
* The camera stream was successfully fetched, but it could be processed. This error can happen for the following
|
|
@@ -192,6 +203,7 @@ function useUserMedia(constraints, videoRef) {
|
|
|
192
203
|
var _g = (0, react_1.useState)(null), lastConstraintsApplied = _g[0], setLastConstraintsApplied = _g[1];
|
|
193
204
|
var handleError = (0, monitoring_1.useMonitoring)().handleError;
|
|
194
205
|
var isActive = (0, react_1.useRef)(true);
|
|
206
|
+
var cameraPermissionState = null;
|
|
195
207
|
(0, react_1.useEffect)(function () {
|
|
196
208
|
return function () {
|
|
197
209
|
isActive.current = false;
|
|
@@ -200,7 +212,16 @@ function useUserMedia(constraints, videoRef) {
|
|
|
200
212
|
var handleGetUserMediaError = function (err) {
|
|
201
213
|
var type = UserMediaErrorType.OTHER;
|
|
202
214
|
if (err instanceof Error && err.name === 'NotAllowedError') {
|
|
203
|
-
|
|
215
|
+
switch (cameraPermissionState) {
|
|
216
|
+
case 'denied':
|
|
217
|
+
type = UserMediaErrorType.WEBPAGE_NOT_ALLOWED;
|
|
218
|
+
break;
|
|
219
|
+
case 'granted':
|
|
220
|
+
type = UserMediaErrorType.BROWSER_NOT_ALLOWED;
|
|
221
|
+
break;
|
|
222
|
+
default:
|
|
223
|
+
type = UserMediaErrorType.NOT_ALLOWED;
|
|
224
|
+
}
|
|
204
225
|
}
|
|
205
226
|
else if (err instanceof Error &&
|
|
206
227
|
Object.values(InvalidStreamErrorName).includes(err.name)) {
|
|
@@ -231,11 +252,10 @@ function useUserMedia(constraints, videoRef) {
|
|
|
231
252
|
}
|
|
232
253
|
setLastConstraintsApplied(constraints);
|
|
233
254
|
var getUserMedia = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
234
|
-
var deviceDetails, updatedConstraints, str
|
|
255
|
+
var deviceDetails, updatedConstraints, str;
|
|
235
256
|
return __generator(this, function (_a) {
|
|
236
257
|
switch (_a.label) {
|
|
237
258
|
case 0:
|
|
238
|
-
_a.trys.push([0, 3, , 4]);
|
|
239
259
|
setIsLoading(true);
|
|
240
260
|
if (stream) {
|
|
241
261
|
stream.removeEventListener('inactive', onStreamInactive);
|
|
@@ -256,19 +276,47 @@ function useUserMedia(constraints, videoRef) {
|
|
|
256
276
|
setAvailableCameraDevices(deviceDetails.availableDevices);
|
|
257
277
|
setSelectedCameraDeviceId(getStreamDeviceId(str));
|
|
258
278
|
}
|
|
259
|
-
return [
|
|
260
|
-
|
|
279
|
+
return [2 /*return*/];
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}); };
|
|
283
|
+
var getCameraPermissionState = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
284
|
+
var err_1;
|
|
285
|
+
return __generator(this, function (_a) {
|
|
286
|
+
switch (_a.label) {
|
|
287
|
+
case 0:
|
|
288
|
+
_a.trys.push([0, 2, , 3]);
|
|
289
|
+
return [4 /*yield*/, navigator.permissions.query({
|
|
290
|
+
name: 'camera',
|
|
291
|
+
})];
|
|
292
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
293
|
+
case 2:
|
|
261
294
|
err_1 = _a.sent();
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
throw err_1;
|
|
265
|
-
}
|
|
266
|
-
return [3 /*break*/, 4];
|
|
267
|
-
case 4: return [2 /*return*/];
|
|
295
|
+
return [2 /*return*/, null];
|
|
296
|
+
case 3: return [2 /*return*/];
|
|
268
297
|
}
|
|
269
298
|
});
|
|
270
299
|
}); };
|
|
271
|
-
getUserMedia()
|
|
300
|
+
getUserMedia()
|
|
301
|
+
.catch(function (err) {
|
|
302
|
+
return Promise.all([err, getCameraPermissionState()]);
|
|
303
|
+
})
|
|
304
|
+
.then(function (result) {
|
|
305
|
+
if (!result) {
|
|
306
|
+
return Promise.all([null, getCameraPermissionState()]);
|
|
307
|
+
}
|
|
308
|
+
return result;
|
|
309
|
+
})
|
|
310
|
+
.then(function (_a) {
|
|
311
|
+
var _b;
|
|
312
|
+
var err = _a[0], cameraPermission = _a[1];
|
|
313
|
+
cameraPermissionState = (_b = cameraPermission === null || cameraPermission === void 0 ? void 0 : cameraPermission.state) !== null && _b !== void 0 ? _b : null;
|
|
314
|
+
if (err && isActive.current) {
|
|
315
|
+
handleGetUserMediaError(err);
|
|
316
|
+
throw err;
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
.catch(handleError);
|
|
272
320
|
}, [constraints, stream, error, isLoading, lastConstraintsApplied]);
|
|
273
321
|
(0, react_1.useEffect)(function () {
|
|
274
322
|
if (stream && videoRef.current) {
|
|
@@ -23,7 +23,7 @@ var utils_1 = require("../utils");
|
|
|
23
23
|
* The basic Camera HUD provided by the Monk camera package. It displays a button to take pictures, as well as error
|
|
24
24
|
* messages (and a retry button) in case of errors with the Camera stream.
|
|
25
25
|
*/
|
|
26
|
-
exports.SimpleCameraHUD = (0, common_1.i18nWrap)(function (_a) {
|
|
26
|
+
exports.SimpleCameraHUD = (0, common_1.i18nWrap)(function SimpleCameraHUD(_a) {
|
|
27
27
|
var _b;
|
|
28
28
|
var cameraPreview = _a.cameraPreview, handle = _a.handle, lang = _a.lang;
|
|
29
29
|
(0, common_1.useI18nSync)(lang);
|
|
@@ -15,6 +15,20 @@ function getCameraErrorLabel(error) {
|
|
|
15
15
|
de: 'Die Kameravorschau ist nicht verfügbar, da für die Seite kein Kamerazugriff gewährt wurde.',
|
|
16
16
|
nl: 'De cameravoorbeeld is niet beschikbaar omdat er geen toegang tot de camera is verleend aan de pagina.',
|
|
17
17
|
};
|
|
18
|
+
case Camera_1.UserMediaErrorType.WEBPAGE_NOT_ALLOWED:
|
|
19
|
+
return {
|
|
20
|
+
en: 'Unable to get camera access. Make sure to press “Allow” when asked to grant camera permission for this web page.',
|
|
21
|
+
fr: "Impossible d'accéder à la caméra. Veuillez vous assurer d'appuyer sur “Autoriser” lorsqu'on vous propose d'autoriser l'accès à la caméra pour cette page web.",
|
|
22
|
+
de: 'Die Kamera kann nicht zugelassen werden. Stellen Sie sicher, dass Sie auf „Zulassen“ drücken, wenn Sie aufgefordert werden, die Kamera für diese Webseite zuzulassen.',
|
|
23
|
+
nl: 'Kan geen toestemming krijgen voor de camera. Zorg ervoor dat u op “Toestaan” drukt wanneer u wordt gevraagd om toestemming te geven voor het gebruik van de camera op deze webpagina.',
|
|
24
|
+
};
|
|
25
|
+
case Camera_1.UserMediaErrorType.BROWSER_NOT_ALLOWED:
|
|
26
|
+
return {
|
|
27
|
+
en: "Unable to get camera access. Make sure to grant camera access to your current internet browser in your device's settings.",
|
|
28
|
+
fr: "Impossible d'accéder à la caméra. Veuillez vous assurer d'autoriser l'accès à la caméra pour ce navigateur internet dans les paramètres de votre téléphone.",
|
|
29
|
+
de: 'Der Zugriff auf die Kamera ist nicht möglich. Stellen Sie sicher, dass Sie in den Einstellungen Ihres Geräts den Kamerazugriff für Ihren aktuellen Internetbrowser zulassen.',
|
|
30
|
+
nl: 'Kan geen cameratoegang krijgen. Zorg ervoor dat u de camera toegang verleent tot uw huidige internet browser in de instellingen van uw apparaat.',
|
|
31
|
+
};
|
|
18
32
|
case Camera_1.UserMediaErrorType.STREAM_INACTIVE:
|
|
19
33
|
return {
|
|
20
34
|
en: 'The camera video stream was closed unexpectedly.',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkvision/camera-web",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.13",
|
|
4
4
|
"license": "BSD-3-Clause-Clear",
|
|
5
5
|
"packageManager": "yarn@3.2.4",
|
|
6
6
|
"description": "MonkJs camera package for React (web) used to display a camera preview and take pictures",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"lint:fix": "yarn run prettier:fix && yarn run eslint:fix"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@monkvision/common": "4.0.
|
|
32
|
-
"@monkvision/common-ui-web": "4.0.
|
|
33
|
-
"@monkvision/monitoring": "4.0.
|
|
31
|
+
"@monkvision/common": "4.0.13",
|
|
32
|
+
"@monkvision/common-ui-web": "4.0.13",
|
|
33
|
+
"@monkvision/monitoring": "4.0.13",
|
|
34
34
|
"fast-deep-equal": "^3.1.3",
|
|
35
35
|
"i18next": "^23.4.5",
|
|
36
36
|
"react-i18next": "^13.2.0"
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"react-router-dom": "^6.22.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@monkvision/eslint-config-base": "4.0.
|
|
46
|
-
"@monkvision/eslint-config-typescript": "4.0.
|
|
47
|
-
"@monkvision/eslint-config-typescript-react": "4.0.
|
|
48
|
-
"@monkvision/jest-config": "4.0.
|
|
49
|
-
"@monkvision/prettier-config": "4.0.
|
|
50
|
-
"@monkvision/test-utils": "4.0.
|
|
51
|
-
"@monkvision/typescript-config": "4.0.
|
|
45
|
+
"@monkvision/eslint-config-base": "4.0.13",
|
|
46
|
+
"@monkvision/eslint-config-typescript": "4.0.13",
|
|
47
|
+
"@monkvision/eslint-config-typescript-react": "4.0.13",
|
|
48
|
+
"@monkvision/jest-config": "4.0.13",
|
|
49
|
+
"@monkvision/prettier-config": "4.0.13",
|
|
50
|
+
"@monkvision/test-utils": "4.0.13",
|
|
51
|
+
"@monkvision/typescript-config": "4.0.13",
|
|
52
52
|
"@testing-library/react": "^12.1.5",
|
|
53
53
|
"@testing-library/react-hooks": "^8.0.1",
|
|
54
54
|
"@types/fscreen": "^1.0.1",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"url": "https://github.com/monkvision/monkjs/issues"
|
|
91
91
|
},
|
|
92
92
|
"homepage": "https://github.com/monkvision/monkjs",
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "aaed1ea6df50b958aa5b3bba3765235847ad895e"
|
|
94
94
|
}
|