@monkvision/camera-web 4.0.0

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.
Files changed (76) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +182 -0
  3. package/lib/Camera/Camera.d.ts +51 -0
  4. package/lib/Camera/Camera.js +69 -0
  5. package/lib/Camera/Camera.js.map +1 -0
  6. package/lib/Camera/Camera.styles.d.ts +2 -0
  7. package/lib/Camera/Camera.styles.js +21 -0
  8. package/lib/Camera/Camera.styles.js.map +1 -0
  9. package/lib/Camera/CameraHUD.types.d.ts +62 -0
  10. package/lib/Camera/CameraHUD.types.js +3 -0
  11. package/lib/Camera/CameraHUD.types.js.map +1 -0
  12. package/lib/Camera/hooks/index.d.ts +7 -0
  13. package/lib/Camera/hooks/index.js +26 -0
  14. package/lib/Camera/hooks/index.js.map +1 -0
  15. package/lib/Camera/hooks/useCameraCanvas.d.ts +37 -0
  16. package/lib/Camera/hooks/useCameraCanvas.js +58 -0
  17. package/lib/Camera/hooks/useCameraCanvas.js.map +1 -0
  18. package/lib/Camera/hooks/useCameraPreview.d.ts +22 -0
  19. package/lib/Camera/hooks/useCameraPreview.js +57 -0
  20. package/lib/Camera/hooks/useCameraPreview.js.map +1 -0
  21. package/lib/Camera/hooks/useCameraScreenshot.d.ts +31 -0
  22. package/lib/Camera/hooks/useCameraScreenshot.js +66 -0
  23. package/lib/Camera/hooks/useCameraScreenshot.js.map +1 -0
  24. package/lib/Camera/hooks/useCompression.d.ts +24 -0
  25. package/lib/Camera/hooks/useCompression.js +126 -0
  26. package/lib/Camera/hooks/useCompression.js.map +1 -0
  27. package/lib/Camera/hooks/useTakePicture.d.ts +32 -0
  28. package/lib/Camera/hooks/useTakePicture.js +100 -0
  29. package/lib/Camera/hooks/useTakePicture.js.map +1 -0
  30. package/lib/Camera/hooks/useUserMedia.d.ts +122 -0
  31. package/lib/Camera/hooks/useUserMedia.js +294 -0
  32. package/lib/Camera/hooks/useUserMedia.js.map +1 -0
  33. package/lib/Camera/hooks/utils/analyzeCameraDevices.d.ts +17 -0
  34. package/lib/Camera/hooks/utils/analyzeCameraDevices.js +75 -0
  35. package/lib/Camera/hooks/utils/analyzeCameraDevices.js.map +1 -0
  36. package/lib/Camera/hooks/utils/getCanvasHandle.d.ts +18 -0
  37. package/lib/Camera/hooks/utils/getCanvasHandle.js +29 -0
  38. package/lib/Camera/hooks/utils/getCanvasHandle.js.map +1 -0
  39. package/lib/Camera/hooks/utils/getMediaContraints.d.ts +46 -0
  40. package/lib/Camera/hooks/utils/getMediaContraints.js +62 -0
  41. package/lib/Camera/hooks/utils/getMediaContraints.js.map +1 -0
  42. package/lib/Camera/hooks/utils/index.d.ts +3 -0
  43. package/lib/Camera/hooks/utils/index.js +20 -0
  44. package/lib/Camera/hooks/utils/index.js.map +1 -0
  45. package/lib/Camera/index.d.ts +4 -0
  46. package/lib/Camera/index.js +9 -0
  47. package/lib/Camera/index.js.map +1 -0
  48. package/lib/Camera/monitoring.d.ts +34 -0
  49. package/lib/Camera/monitoring.js +30 -0
  50. package/lib/Camera/monitoring.js.map +1 -0
  51. package/lib/SimpleCameraHUD/SimpleCameraHUD.d.ts +24 -0
  52. package/lib/SimpleCameraHUD/SimpleCameraHUD.js +37 -0
  53. package/lib/SimpleCameraHUD/SimpleCameraHUD.js.map +1 -0
  54. package/lib/SimpleCameraHUD/SimpleCameraHUD.styles.d.ts +2 -0
  55. package/lib/SimpleCameraHUD/SimpleCameraHUD.styles.js +62 -0
  56. package/lib/SimpleCameraHUD/SimpleCameraHUD.styles.js.map +1 -0
  57. package/lib/SimpleCameraHUD/index.d.ts +1 -0
  58. package/lib/SimpleCameraHUD/index.js +6 -0
  59. package/lib/SimpleCameraHUD/index.js.map +1 -0
  60. package/lib/i18n.d.ts +5 -0
  61. package/lib/i18n.js +24 -0
  62. package/lib/i18n.js.map +1 -0
  63. package/lib/index.d.ts +4 -0
  64. package/lib/index.js +21 -0
  65. package/lib/index.js.map +1 -0
  66. package/lib/translations/de.json +3 -0
  67. package/lib/translations/en.json +3 -0
  68. package/lib/translations/fr.json +3 -0
  69. package/lib/translations/nl.json +3 -0
  70. package/lib/utils/errors.utils.d.ts +7 -0
  71. package/lib/utils/errors.utils.js +42 -0
  72. package/lib/utils/errors.utils.js.map +1 -0
  73. package/lib/utils/index.d.ts +1 -0
  74. package/lib/utils/index.js +18 -0
  75. package/lib/utils/index.js.map +1 -0
  76. package/package.json +90 -0
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __importDefault = (this && this.__importDefault) || function (mod) {
65
+ return (mod && mod.__esModule) ? mod : { "default": mod };
66
+ };
67
+ Object.defineProperty(exports, "__esModule", { value: true });
68
+ exports.useUserMedia = exports.UserMediaErrorType = exports.InvalidStreamErrorName = void 0;
69
+ var monitoring_1 = require("@monkvision/monitoring");
70
+ var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
71
+ var react_1 = require("react");
72
+ var common_1 = require("@monkvision/common");
73
+ var utils_1 = require("./utils");
74
+ /**
75
+ * Enumeration of the different Native error names that can happen when a stream is invalid.
76
+ */
77
+ var InvalidStreamErrorName;
78
+ (function (InvalidStreamErrorName) {
79
+ /**
80
+ * The stream had no video track.
81
+ */
82
+ InvalidStreamErrorName["NO_VIDEO_TRACK"] = "NoVideoTrack";
83
+ /**
84
+ * The stream had too many video tracks (more than one).
85
+ */
86
+ InvalidStreamErrorName["TOO_MANY_VIDEO_TRACKS"] = "TooManyVideoTracks";
87
+ /**
88
+ * The stream's video track had no dimensions.
89
+ */
90
+ InvalidStreamErrorName["NO_DIMENSIONS"] = "NoDimensions";
91
+ })(InvalidStreamErrorName = exports.InvalidStreamErrorName || (exports.InvalidStreamErrorName = {}));
92
+ var InvalidStreamError = /** @class */ (function (_super) {
93
+ __extends(InvalidStreamError, _super);
94
+ function InvalidStreamError(message, name) {
95
+ var _this = _super.call(this, message) || this;
96
+ _this.name = name;
97
+ return _this;
98
+ }
99
+ return InvalidStreamError;
100
+ }(Error));
101
+ /**
102
+ * The type of errors that the `useUserMedia` hook can return.
103
+ *
104
+ * @see useUserMedia
105
+ */
106
+ var UserMediaErrorType;
107
+ (function (UserMediaErrorType) {
108
+ /**
109
+ * The camera stream couldn't be fetched because the web page does not have the permissions to access the camera.
110
+ */
111
+ UserMediaErrorType["NOT_ALLOWED"] = "not_allowed";
112
+ /**
113
+ * The camera stream was successfully fetched, but it could be processed. This error can happen for the following
114
+ * reasons :
115
+ * - The stream did not contain any video track, or contained multiple ones.
116
+ * - The stream's video track did not have any width or height property defined.
117
+ */
118
+ UserMediaErrorType["INVALID_STREAM"] = "invalid_stream";
119
+ /**
120
+ * The camera stream was successfully fetched, but was made inactive for some unknown reason. Some known reasons that
121
+ * could be causing this error are :
122
+ * - The user revoked the camera access rights of the webpage while the stream was running.
123
+ * - On Safari, making a call to `navigator.mediaDevices.getUserMedia` will close all other existing streams on the
124
+ * web page. When using the Monk Camera package, you need to make sure that your app does not call `getUserMedia`
125
+ * while the camera stream is running. You can take a look at
126
+ * [this page](https://webrtchacks.com/guide-to-safari-webrtc/) for more reading about this behaviour.
127
+ */
128
+ UserMediaErrorType["STREAM_INACTIVE"] = "stream_inactive";
129
+ /**
130
+ * Any other error.
131
+ */
132
+ UserMediaErrorType["OTHER"] = "other";
133
+ })(UserMediaErrorType = exports.UserMediaErrorType || (exports.UserMediaErrorType = {}));
134
+ function getStreamVideoTrackSettings(stream) {
135
+ var videoTracks = stream.getVideoTracks();
136
+ if (videoTracks.length === 0) {
137
+ throw new InvalidStreamError('Unable to set up the Monk camera screenshoter because the video stream does contain any video tracks.', InvalidStreamErrorName.NO_VIDEO_TRACK);
138
+ }
139
+ if (videoTracks.length > 1) {
140
+ throw new InvalidStreamError('Unable to set up the Monk camera screenshoter because the video stream contains multiple video tracks.', InvalidStreamErrorName.TOO_MANY_VIDEO_TRACKS);
141
+ }
142
+ return stream.getVideoTracks()[0].getSettings();
143
+ }
144
+ function getStreamDeviceId(stream) {
145
+ var _a;
146
+ var settings = getStreamVideoTrackSettings(stream);
147
+ return (_a = settings.deviceId) !== null && _a !== void 0 ? _a : null;
148
+ }
149
+ function swapDimensions(dimensions) {
150
+ return {
151
+ width: dimensions.height,
152
+ height: dimensions.width,
153
+ };
154
+ }
155
+ function getStreamDimensions(stream, checkOrientation) {
156
+ var _a = getStreamVideoTrackSettings(stream), width = _a.width, height = _a.height;
157
+ if (!width || !height) {
158
+ throw new InvalidStreamError('Unable to set up the Monk camera screenshoter because the video stream does not have the properties width and height defined.', InvalidStreamErrorName.NO_DIMENSIONS);
159
+ }
160
+ var dimensions = { width: width, height: height };
161
+ if (!(0, common_1.isMobileDevice)() || !checkOrientation) {
162
+ return dimensions;
163
+ }
164
+ var isStreamInPortrait = width < height;
165
+ var isDeviceInPortrait = window.matchMedia('(orientation: portrait)').matches;
166
+ return isStreamInPortrait !== isDeviceInPortrait ? swapDimensions(dimensions) : dimensions;
167
+ }
168
+ /**
169
+ * React hook that wraps the `navigator.mediaDevices.getUserMedia` browser function in order to add React logic layers
170
+ * and utility tools :
171
+ * - Creates an effect for `getUserMedia` that will be run everytime some state parameters are updated.
172
+ * - Will call `track.applyConstraints` when the video contstraints are updated in order to update the video stream.
173
+ * - Makes sure that the `getUserMedia` is only called when it needs to be using memoized state.
174
+ * - Provides various utilities such as error catching, loading information and a retry on failure feature.
175
+ *
176
+ * @param constraints The same media constraints you would pass to the `getUserMedia` function. Note that this hook has
177
+ * been designed for video only, so audio constraints could provoke unexpected behaviour.
178
+ * @param videoRef The ref to the video element displaying the camera preview stream.
179
+ * @return The result of this hook contains the resulting video stream, an error object if there has been an error, a
180
+ * loading indicator and a retry function that tries to get a camera stream again. See the `UserMediaResult` interface
181
+ * for more information.
182
+ * @see UserMediaResult
183
+ */
184
+ function useUserMedia(constraints, videoRef) {
185
+ var _this = this;
186
+ var _a = (0, react_1.useState)(null), stream = _a[0], setStream = _a[1];
187
+ var _b = (0, react_1.useState)(null), dimensions = _b[0], setDimensions = _b[1];
188
+ var _c = (0, react_1.useState)(false), isLoading = _c[0], setIsLoading = _c[1];
189
+ var _d = (0, react_1.useState)(null), error = _d[0], setError = _d[1];
190
+ var _e = (0, react_1.useState)([]), availableCameraDevices = _e[0], setAvailableCameraDevices = _e[1];
191
+ var _f = (0, react_1.useState)(null), selectedCameraDeviceId = _f[0], setSelectedCameraDeviceId = _f[1];
192
+ var _g = (0, react_1.useState)(null), lastConstraintsApplied = _g[0], setLastConstraintsApplied = _g[1];
193
+ var handleError = (0, monitoring_1.useMonitoring)().handleError;
194
+ var isActive = (0, react_1.useRef)(true);
195
+ (0, react_1.useEffect)(function () {
196
+ return function () {
197
+ isActive.current = false;
198
+ };
199
+ }, []);
200
+ var handleGetUserMediaError = function (err) {
201
+ var type = UserMediaErrorType.OTHER;
202
+ if (err instanceof Error && err.name === 'NotAllowedError') {
203
+ type = UserMediaErrorType.NOT_ALLOWED;
204
+ }
205
+ else if (err instanceof Error &&
206
+ Object.values(InvalidStreamErrorName).includes(err.name)) {
207
+ type = UserMediaErrorType.INVALID_STREAM;
208
+ }
209
+ setError({ type: type, nativeError: err });
210
+ setStream(null);
211
+ setIsLoading(false);
212
+ };
213
+ var onStreamInactive = function () {
214
+ setError({
215
+ type: UserMediaErrorType.STREAM_INACTIVE,
216
+ nativeError: new Error('The camera stream was closed.'),
217
+ });
218
+ setIsLoading(false);
219
+ };
220
+ var retry = (0, react_1.useCallback)(function () {
221
+ if (error && !isLoading) {
222
+ setError(null);
223
+ setStream(null);
224
+ setIsLoading(false);
225
+ setLastConstraintsApplied(null);
226
+ }
227
+ }, [error, isLoading]);
228
+ (0, react_1.useEffect)(function () {
229
+ if (error || isLoading || (0, fast_deep_equal_1.default)(lastConstraintsApplied, constraints)) {
230
+ return;
231
+ }
232
+ setLastConstraintsApplied(constraints);
233
+ var getUserMedia = function () { return __awaiter(_this, void 0, void 0, function () {
234
+ var deviceDetails, updatedConstraints, str, err_1;
235
+ return __generator(this, function (_a) {
236
+ switch (_a.label) {
237
+ case 0:
238
+ _a.trys.push([0, 3, , 4]);
239
+ setIsLoading(true);
240
+ if (stream) {
241
+ stream.removeEventListener('inactive', onStreamInactive);
242
+ stream.getTracks().forEach(function (track) { return track.stop(); });
243
+ }
244
+ return [4 /*yield*/, (0, utils_1.analyzeCameraDevices)(constraints)];
245
+ case 1:
246
+ deviceDetails = _a.sent();
247
+ updatedConstraints = __assign(__assign({}, constraints), { video: __assign(__assign({}, (constraints ? constraints.video : {})), { deviceId: { exact: deviceDetails.validDeviceIds } }) });
248
+ return [4 /*yield*/, navigator.mediaDevices.getUserMedia(updatedConstraints)];
249
+ case 2:
250
+ str = _a.sent();
251
+ str === null || str === void 0 ? void 0 : str.addEventListener('inactive', onStreamInactive);
252
+ if (isActive.current) {
253
+ setStream(str);
254
+ setDimensions(getStreamDimensions(str, true));
255
+ setIsLoading(false);
256
+ setAvailableCameraDevices(deviceDetails.availableDevices);
257
+ setSelectedCameraDeviceId(getStreamDeviceId(str));
258
+ }
259
+ return [3 /*break*/, 4];
260
+ case 3:
261
+ err_1 = _a.sent();
262
+ if (isActive.current) {
263
+ handleGetUserMediaError(err_1);
264
+ throw err_1;
265
+ }
266
+ return [3 /*break*/, 4];
267
+ case 4: return [2 /*return*/];
268
+ }
269
+ });
270
+ }); };
271
+ getUserMedia().catch(handleError);
272
+ }, [constraints, stream, error, isLoading, lastConstraintsApplied]);
273
+ (0, react_1.useEffect)(function () {
274
+ if (stream && videoRef.current) {
275
+ // eslint-disable-next-line no-param-reassign
276
+ videoRef.current.onresize = function () {
277
+ if (isActive.current) {
278
+ setDimensions(getStreamDimensions(stream, false));
279
+ }
280
+ };
281
+ }
282
+ }, [stream]);
283
+ return (0, common_1.useObjectMemo)({
284
+ stream: stream,
285
+ dimensions: dimensions,
286
+ error: error,
287
+ retry: retry,
288
+ isLoading: isLoading,
289
+ availableCameraDevices: availableCameraDevices,
290
+ selectedCameraDeviceId: selectedCameraDeviceId,
291
+ });
292
+ }
293
+ exports.useUserMedia = useUserMedia;
294
+ //# sourceMappingURL=useUserMedia.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUserMedia.js","sourceRoot":"","sources":["../../../src/Camera/hooks/useUserMedia.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuD;AACvD,oEAAwC;AACxC,+BAA4E;AAE5E,6CAAmE;AACnE,iCAA+C;AAE/C;;GAEG;AACH,IAAY,sBAaX;AAbD,WAAY,sBAAsB;IAChC;;OAEG;IACH,yDAA+B,CAAA;IAC/B;;OAEG;IACH,sEAA4C,CAAA;IAC5C;;OAEG;IACH,wDAA8B,CAAA;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
3
+ */
4
+ export interface CameraDevicesDetails {
5
+ /**
6
+ * The list of all available videoinput camera devices on the user's phone.
7
+ */
8
+ availableDevices: MediaDeviceInfo[];
9
+ /**
10
+ * The list of valid camera device IDs that can be used to take pictures.
11
+ */
12
+ validDeviceIds: string[];
13
+ }
14
+ /**
15
+ * Analyzes the available camera devices on the current user's phone.
16
+ */
17
+ export declare function analyzeCameraDevices(constraints: MediaStreamConstraints): Promise<CameraDevicesDetails>;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.analyzeCameraDevices = void 0;
40
+ function isVideoRecordingDevice(device) {
41
+ return device.kind === 'videoinput';
42
+ }
43
+ function isValidCamera(device) {
44
+ return (!device.label.includes('Wide') &&
45
+ !device.label.includes('Telephoto') &&
46
+ !device.label.includes('Triple') &&
47
+ !device.label.includes('Dual') &&
48
+ !device.label.includes('Ultra'));
49
+ }
50
+ /**
51
+ * Analyzes the available camera devices on the current user's phone.
52
+ */
53
+ function analyzeCameraDevices(constraints) {
54
+ return __awaiter(this, void 0, void 0, function () {
55
+ var str, allDevices, availableDevices, validDeviceIds;
56
+ return __generator(this, function (_a) {
57
+ switch (_a.label) {
58
+ case 0: return [4 /*yield*/, navigator.mediaDevices.getUserMedia(constraints)];
59
+ case 1:
60
+ str = _a.sent();
61
+ return [4 /*yield*/, navigator.mediaDevices.enumerateDevices()];
62
+ case 2:
63
+ allDevices = _a.sent();
64
+ availableDevices = allDevices.filter(function (deviceInfo) { return isVideoRecordingDevice(deviceInfo); });
65
+ validDeviceIds = availableDevices
66
+ .filter(function (deviceInfo) { return isValidCamera(deviceInfo); })
67
+ .map(function (deviceInfo) { return deviceInfo.deviceId; });
68
+ str.getTracks().forEach(function (track) { return track.stop(); });
69
+ return [2 /*return*/, { availableDevices: availableDevices, validDeviceIds: validDeviceIds }];
70
+ }
71
+ });
72
+ });
73
+ }
74
+ exports.analyzeCameraDevices = analyzeCameraDevices;
75
+ //# sourceMappingURL=analyzeCameraDevices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzeCameraDevices.js","sourceRoot":"","sources":["../../../../src/Camera/hooks/utils/analyzeCameraDevices.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,sBAAsB,CAAC,MAAuB;IACrD,OAAO,MAAM,CAAC,IAAI,KAAK,YAAY,CAAC;AACtC,CAAC;AAED,SAAS,aAAa,CAAC,MAAuB;IAC5C,OAAO,CACL,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC9B,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC;QACnC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAChC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC9B,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAChC,CAAC;AACJ,CAAC;AAgBD;;GAEG;AACH,SAAsB,oBAAoB,CACxC,WAAmC;;;;;wBAEvB,qBAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,EAAA;;oBAA5D,GAAG,GAAG,SAAsD;oBAC/C,qBAAM,SAAS,CAAC,YAAY,CAAC,gBAAgB,EAAE,EAAA;;oBAA5D,UAAU,GAAG,SAA+C;oBAC5D,gBAAgB,GAAG,UAAU,CAAC,MAAM,CAAC,UAAC,UAAU,IAAK,OAAA,sBAAsB,CAAC,UAAU,CAAC,EAAlC,CAAkC,CAAC,CAAC;oBACzF,cAAc,GAAG,gBAAgB;yBACpC,MAAM,CAAC,UAAC,UAAU,IAAK,OAAA,aAAa,CAAC,UAAU,CAAC,EAAzB,CAAyB,CAAC;yBACjD,GAAG,CAAC,UAAC,UAAU,IAAK,OAAA,UAAU,CAAC,QAAQ,EAAnB,CAAmB,CAAC,CAAC;oBAE5C,GAAG,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,IAAI,EAAE,EAAZ,CAAY,CAAC,CAAC;oBACjD,sBAAO,EAAE,gBAAgB,kBAAA,EAAE,cAAc,gBAAA,EAAE,EAAC;;;;CAC7C;AAZD,oDAYC"}
@@ -0,0 +1,18 @@
1
+ import { RefObject } from 'react';
2
+ /**
3
+ * A handle used to manipulate a canvas element.
4
+ */
5
+ export interface CanvasHandle {
6
+ /**
7
+ * The HTML canvas element.
8
+ */
9
+ canvas: HTMLCanvasElement;
10
+ /**
11
+ * A 2D context created to draw on the canvas.
12
+ */
13
+ context: CanvasRenderingContext2D;
14
+ }
15
+ /**
16
+ * Utility function used to retreive a canvas handle or throw if it is not available.
17
+ */
18
+ export declare function getCanvasHandle(ref: RefObject<HTMLCanvasElement>, onError?: (err: Error) => void): CanvasHandle;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCanvasHandle = void 0;
4
+ /**
5
+ * Utility function used to retreive a canvas handle or throw if it is not available.
6
+ */
7
+ function getCanvasHandle(ref, onError) {
8
+ if (!ref.current) {
9
+ var err = new Error('Unable to process the camera picture because the canvas element is null.');
10
+ if (onError) {
11
+ onError(err);
12
+ }
13
+ throw err;
14
+ }
15
+ var context = ref.current.getContext('2d', {
16
+ alpha: false,
17
+ willReadFrequently: true,
18
+ });
19
+ if (!context) {
20
+ var err = new Error('Unable to process the camera picture because the canvas context is null.');
21
+ if (onError) {
22
+ onError(err);
23
+ }
24
+ throw err;
25
+ }
26
+ return { canvas: ref.current, context: context };
27
+ }
28
+ exports.getCanvasHandle = getCanvasHandle;
29
+ //# sourceMappingURL=getCanvasHandle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCanvasHandle.js","sourceRoot":"","sources":["../../../../src/Camera/hooks/utils/getCanvasHandle.ts"],"names":[],"mappings":";;;AAgBA;;GAEG;AACH,SAAgB,eAAe,CAC7B,GAAiC,EACjC,OAA8B;IAE9B,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;QAChB,IAAM,GAAG,GAAG,IAAI,KAAK,CACnB,0EAA0E,CAC3E,CAAC;QACF,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,GAAG,CAAC,CAAC;SACd;QACD,MAAM,GAAG,CAAC;KACX;IACD,IAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE;QAC3C,KAAK,EAAE,KAAK;QACZ,kBAAkB,EAAE,IAAI;KACzB,CAAC,CAAC;IACH,IAAI,CAAC,OAAO,EAAE;QACZ,IAAM,GAAG,GAAG,IAAI,KAAK,CACnB,0EAA0E,CAC3E,CAAC;QACF,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,GAAG,CAAC,CAAC;SACd;QACD,MAAM,GAAG,CAAC;KACX;IACD,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,SAAA,EAAE,CAAC;AAC1C,CAAC;AA3BD,0CA2BC"}
@@ -0,0 +1,46 @@
1
+ import { CameraResolution, PixelDimensions } from '@monkvision/types';
2
+ /**
3
+ * Enumeration of the facing modes for the camera constraints.
4
+ */
5
+ export declare enum CameraFacingMode {
6
+ /**
7
+ * User-facing camera (front camera).
8
+ */
9
+ USER = "user",
10
+ /**
11
+ * Enironment-facing camera (back camera).
12
+ */
13
+ ENVIRONMENT = "environment"
14
+ }
15
+ /**
16
+ * Specifications for the camera stream that the Monk `Camera` component should fetch from the device.
17
+ */
18
+ export interface CameraConfig {
19
+ /**
20
+ * Specifies which camera to use if the devices has a front and a rear camera. If the device does not have a camera
21
+ * meeting the requirements, the closest one will be used.
22
+ */
23
+ facingMode: CameraFacingMode;
24
+ /**
25
+ * Resolution quality for the camera. If no camera on the device meets the requirements, the closest match will be
26
+ * used. Notes :
27
+ * - The Monk Camera package will always try to fetch a stream with a 16:9 resolution format.
28
+ * - The implementation of the algorithm used to choose the closest camera can differ between browsers, and if the
29
+ * exact requirements can't be met, the resulting stream's quality can differ between browsers.
30
+ */
31
+ resolution: CameraResolution;
32
+ }
33
+ /**
34
+ * Utility function that returns the dimensions in pixels of the given `CameraResolution`.
35
+ */
36
+ export declare function getResolutionDimensions(resolution: CameraResolution, isPortrait?: boolean): PixelDimensions;
37
+ /**
38
+ * This function is used by the Monk Camera package in order to add a layer of abstraction to the media constraints
39
+ * passed to the `useUserMedia` hook. It takes an optional `CameraOptions` parameter and creates a
40
+ * `MediaStreamConstraints` corresponding to the given options. The default option for each `CameraOptions` field can be
41
+ * found in their respsective tsdoc descriptions, refer to the `CameraOptions` interface for more details.
42
+ *
43
+ * @see CameraConfig
44
+ * @see useUserMedia
45
+ */
46
+ export declare function getMediaConstraints(config: CameraConfig): MediaStreamConstraints;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getMediaConstraints = exports.getResolutionDimensions = exports.CameraFacingMode = void 0;
5
+ var types_1 = require("@monkvision/types");
6
+ /**
7
+ * Enumeration of the facing modes for the camera constraints.
8
+ */
9
+ var CameraFacingMode;
10
+ (function (CameraFacingMode) {
11
+ /**
12
+ * User-facing camera (front camera).
13
+ */
14
+ CameraFacingMode["USER"] = "user";
15
+ /**
16
+ * Enironment-facing camera (back camera).
17
+ */
18
+ CameraFacingMode["ENVIRONMENT"] = "environment";
19
+ })(CameraFacingMode = exports.CameraFacingMode || (exports.CameraFacingMode = {}));
20
+ var CAMERA_RESOLUTION_DIMENSIONS = (_a = {},
21
+ _a[types_1.CameraResolution.QNHD_180P] = { width: 320, height: 180 },
22
+ _a[types_1.CameraResolution.NHD_360P] = { width: 640, height: 360 },
23
+ _a[types_1.CameraResolution.HD_720P] = { width: 1280, height: 720 },
24
+ _a[types_1.CameraResolution.FHD_1080P] = { width: 1920, height: 1080 },
25
+ _a[types_1.CameraResolution.QHD_2K] = { width: 2560, height: 1440 },
26
+ _a[types_1.CameraResolution.UHD_4K] = { width: 3840, height: 2160 },
27
+ _a);
28
+ /**
29
+ * Utility function that returns the dimensions in pixels of the given `CameraResolution`.
30
+ */
31
+ function getResolutionDimensions(resolution, isPortrait) {
32
+ if (isPortrait === void 0) { isPortrait = false; }
33
+ var dimensions = CAMERA_RESOLUTION_DIMENSIONS[resolution];
34
+ return {
35
+ width: isPortrait ? dimensions.height : dimensions.width,
36
+ height: isPortrait ? dimensions.width : dimensions.height,
37
+ };
38
+ }
39
+ exports.getResolutionDimensions = getResolutionDimensions;
40
+ /**
41
+ * This function is used by the Monk Camera package in order to add a layer of abstraction to the media constraints
42
+ * passed to the `useUserMedia` hook. It takes an optional `CameraOptions` parameter and creates a
43
+ * `MediaStreamConstraints` corresponding to the given options. The default option for each `CameraOptions` field can be
44
+ * found in their respsective tsdoc descriptions, refer to the `CameraOptions` interface for more details.
45
+ *
46
+ * @see CameraConfig
47
+ * @see useUserMedia
48
+ */
49
+ function getMediaConstraints(config) {
50
+ var _a = getResolutionDimensions(config.resolution), width = _a.width, height = _a.height;
51
+ var video = {
52
+ width: { ideal: width },
53
+ height: { ideal: height },
54
+ facingMode: config.facingMode,
55
+ };
56
+ return {
57
+ audio: false,
58
+ video: video,
59
+ };
60
+ }
61
+ exports.getMediaConstraints = getMediaConstraints;
62
+ //# sourceMappingURL=getMediaContraints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMediaContraints.js","sourceRoot":"","sources":["../../../../src/Camera/hooks/utils/getMediaContraints.ts"],"names":[],"mappings":";;;;AAAA,2CAAsE;AAEtE;;GAEG;AACH,IAAY,gBASX;AATD,WAAY,gBAAgB;IAC1B;;OAEG;IACH,iCAAa,CAAA;IACb;;OAE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,KAAK,GAA0B;QACnC,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;QACvB,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;QACzB,UAAU,EAAE,MAAM,CAAC,UAAU;KAC9B,CAAC;IAEF,OAAO;QACL,KAAK,EAAE,KAAK;QACZ,KAAK,OAAA;KACN,CAAC;AACJ,CAAC;AAbD,kDAaC"}
@@ -0,0 +1,3 @@
1
+ export * from './getCanvasHandle';
2
+ export * from './getMediaContraints';
3
+ export * from './analyzeCameraDevices';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./getCanvasHandle"), exports);
18
+ __exportStar(require("./getMediaContraints"), exports);
19
+ __exportStar(require("./analyzeCameraDevices"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/Camera/hooks/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,uDAAqC;AACrC,yDAAuC"}
@@ -0,0 +1,4 @@
1
+ export { Camera, type CameraProps } from './Camera';
2
+ export { type CameraConfig, CameraFacingMode, type UserMediaError, UserMediaErrorType, } from './hooks';
3
+ export { type CameraEventHandlers, type CameraHUDComponent, type CameraHUDProps, type CameraHandle, } from './CameraHUD.types';
4
+ export { type CameraMonitoringConfig } from './monitoring';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserMediaErrorType = exports.CameraFacingMode = exports.Camera = void 0;
4
+ var Camera_1 = require("./Camera");
5
+ Object.defineProperty(exports, "Camera", { enumerable: true, get: function () { return Camera_1.Camera; } });
6
+ var hooks_1 = require("./hooks");
7
+ Object.defineProperty(exports, "CameraFacingMode", { enumerable: true, get: function () { return hooks_1.CameraFacingMode; } });
8
+ Object.defineProperty(exports, "UserMediaErrorType", { enumerable: true, get: function () { return hooks_1.UserMediaErrorType; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Camera/index.ts"],"names":[],"mappings":";;;AAAA,mCAAoD;AAA3C,gGAAA,MAAM,OAAA;AACf,iCAKiB;AAHf,yGAAA,gBAAgB,OAAA;AAEhB,2GAAA,kBAAkB,OAAA"}