datakeen-session-react 1.1.201 → 1.1.202-dev.2

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.
@@ -1,4 +1,5 @@
1
1
  import { __awaiter, __generator, __assign } from '../node_modules/tslib/tslib.es6.js';
2
+ import { isBelowHd } from '../utils/cameraResolution.js';
2
3
  import { professionalImageQuality } from './professionalImageQuality.js';
3
4
 
4
5
  // Permit to enable development mode to test without a camera
@@ -121,18 +122,18 @@ var CameraService = /** @class */ (function () {
121
122
  };
122
123
  CameraService.prototype._doStartCamera = function (videoElement, options) {
123
124
  return __awaiter(this, void 0, void 0, function () {
124
- var facingMode, preferImageCapture, desiredWidth, desiredHeight, videoConstraints, stream, err_2, errorMessage;
125
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
126
- return __generator(this, function (_o) {
127
- switch (_o.label) {
125
+ var facingMode, preferImageCapture, desiredWidth, desiredHeight, videoConstraints, stream, retriedWithHd, err_2, errorMessage;
126
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
127
+ return __generator(this, function (_t) {
128
+ switch (_t.label) {
128
129
  case 0:
129
130
  facingMode = (_b = options.facingMode) !== null && _b !== void 0 ? _b : "environment";
130
131
  preferImageCapture = (_c = options.preferImageCapture) !== null && _c !== void 0 ? _c : true;
131
132
  desiredWidth = (_e = (_d = options.idealResolution) === null || _d === void 0 ? void 0 : _d.width) !== null && _e !== void 0 ? _e : DEFAULT_RESOLUTION.width;
132
133
  desiredHeight = (_g = (_f = options.idealResolution) === null || _f === void 0 ? void 0 : _f.height) !== null && _g !== void 0 ? _g : DEFAULT_RESOLUTION.height;
133
- _o.label = 1;
134
+ _t.label = 1;
134
135
  case 1:
135
- _o.trys.push([1, 8, , 9]);
136
+ _t.trys.push([1, 10, , 11]);
136
137
  // Close any existing stream before opening a new one
137
138
  if (this.stream) {
138
139
  this.stream.getTracks().forEach(function (t) { return t.stop(); });
@@ -155,28 +156,45 @@ var CameraService = /** @class */ (function () {
155
156
  video: videoConstraints,
156
157
  })];
157
158
  case 2:
158
- stream = _o.sent();
159
+ stream = _t.sent();
159
160
  this.stream = stream;
160
161
  this.videoTrack = (_j = stream.getVideoTracks()[0]) !== null && _j !== void 0 ? _j : null;
161
162
  this.lastTrackSettings = (_l = (_k = this.videoTrack) === null || _k === void 0 ? void 0 : _k.getSettings()) !== null && _l !== void 0 ? _l : null;
163
+ retriedWithHd = false;
164
+ if (!(isBelowHd((_m = this.lastTrackSettings) !== null && _m !== void 0 ? _m : undefined) && desiredWidth / desiredHeight !== 16 / 9)) return [3 /*break*/, 4];
165
+ retriedWithHd = true;
166
+ stream.getTracks().forEach(function (track) { return track.stop(); });
167
+ this.stream = null;
168
+ this.videoTrack = null;
169
+ this.lastTrackSettings = null;
170
+ return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
171
+ video: __assign(__assign({}, videoConstraints), { width: { ideal: 1920 }, height: { ideal: 1080 } }),
172
+ })];
173
+ case 3:
174
+ stream = _t.sent();
175
+ this.stream = stream;
176
+ this.videoTrack = (_o = stream.getVideoTracks()[0]) !== null && _o !== void 0 ? _o : null;
177
+ this.lastTrackSettings = (_q = (_p = this.videoTrack) === null || _p === void 0 ? void 0 : _p.getSettings()) !== null && _q !== void 0 ? _q : null;
178
+ _t.label = 4;
179
+ case 4:
162
180
  console.debug("[CameraService] Camera opened", {
163
181
  desired: { width: desiredWidth, height: desiredHeight },
164
182
  actual: this.lastTrackSettings,
165
183
  });
166
- if (!this.videoTrack) return [3 /*break*/, 6];
167
- _o.label = 3;
168
- case 3:
169
- _o.trys.push([3, 5, , 6]);
184
+ if (!this.videoTrack) return [3 /*break*/, 8];
185
+ _t.label = 5;
186
+ case 5:
187
+ _t.trys.push([5, 7, , 8]);
170
188
  return [4 /*yield*/, this.videoTrack.applyConstraints({
171
189
  advanced: [{ focusMode: "continuous" }],
172
190
  })];
173
- case 4:
174
- _o.sent();
175
- return [3 /*break*/, 6];
176
- case 5:
177
- _o.sent();
178
- return [3 /*break*/, 6];
179
191
  case 6:
192
+ _t.sent();
193
+ return [3 /*break*/, 8];
194
+ case 7:
195
+ _t.sent();
196
+ return [3 /*break*/, 8];
197
+ case 8:
180
198
  if (supportsImageCapture() && this.videoTrack && preferImageCapture) {
181
199
  try {
182
200
  this.imageCapture = new ImageCapture(this.videoTrack);
@@ -194,15 +212,18 @@ var CameraService = /** @class */ (function () {
194
212
  }
195
213
  videoElement.srcObject = stream;
196
214
  return [4 /*yield*/, this.waitForVideoReady(videoElement)];
197
- case 7:
198
- _o.sent();
215
+ case 9:
216
+ _t.sent();
199
217
  return [2 /*return*/, {
200
218
  success: true,
201
- settings: (_m = this.lastTrackSettings) !== null && _m !== void 0 ? _m : undefined,
219
+ settings: (_r = this.lastTrackSettings) !== null && _r !== void 0 ? _r : undefined,
202
220
  captureMethod: this.captureMethod,
221
+ requested: { w: desiredWidth, h: desiredHeight },
222
+ retriedWithHd: retriedWithHd,
223
+ label: (_s = this.videoTrack) === null || _s === void 0 ? void 0 : _s.label,
203
224
  }];
204
- case 8:
205
- err_2 = _o.sent();
225
+ case 10:
226
+ err_2 = _t.sent();
206
227
  console.error("Erreur lors de l'accès à la caméra:", err_2);
207
228
  errorMessage = "Une erreur inconnue s'est produite lors de l'accès à la caméra.";
208
229
  if (err_2 instanceof DOMException) {
@@ -218,7 +239,7 @@ var CameraService = /** @class */ (function () {
218
239
  }
219
240
  }
220
241
  return [2 /*return*/, { success: false, error: errorMessage }];
221
- case 9: return [2 /*return*/];
242
+ case 11: return [2 /*return*/];
222
243
  }
223
244
  });
224
245
  });
@@ -3,12 +3,21 @@ import { apiService } from './api.js';
3
3
  import { logStatusModified } from './auditTrailService.js';
4
4
  import { clearSessionMemory } from './sessionMemoryStore.js';
5
5
 
6
- /**
7
- * Fetches session data by ID from the Datakeen backend
8
- *
9
- * @param sessionId - The unique identifier of the session
10
- * @returns The session data
11
- */
6
+ /** Reports camera diagnostics without updating local session state. */
7
+ function reportCaptureDiagnostics(sessionId, nodeId, diag) {
8
+ return __awaiter(this, void 0, void 0, function () {
9
+ var _a;
10
+ return __generator(this, function (_b) {
11
+ switch (_b.label) {
12
+ case 0: return [4 /*yield*/, apiService.patch("/session/sdk/".concat(sessionId), { captureDiagnostics: (_a = {}, _a[nodeId] = diag, _a) })];
13
+ case 1:
14
+ _b.sent();
15
+ return [2 /*return*/];
16
+ }
17
+ });
18
+ });
19
+ }
20
+ /** Fetches session data by ID from the Datakeen backend. */
12
21
  var fetchSessionById = function (sessionId) { return __awaiter(void 0, void 0, void 0, function () {
13
22
  var response, error_1;
14
23
  return __generator(this, function (_a) {
@@ -506,4 +515,4 @@ function checkComplementaryMandate(sessionId, nodeId) {
506
515
  return request;
507
516
  }
508
517
 
509
- export { checkComplementaryMandate, clearSessionSensitiveData, fetchSessionById, findOutgoingEdge, getNextStepIndex, getOrderedJourneySteps, getRunPrefillData, hasOutgoingEdgeForHandle, isSessionExpired, reconstructHistoryToStep, reportSelfieFailure, resetNfcScan, sendClientInfo, skipNfcWithReason, storeDocumentOptions, updateSessionContactInfo, updateSessionCurrentStep, updateSessionStatus, updateSessionUserInput };
518
+ export { checkComplementaryMandate, clearSessionSensitiveData, fetchSessionById, findOutgoingEdge, getNextStepIndex, getOrderedJourneySteps, getRunPrefillData, hasOutgoingEdgeForHandle, isSessionExpired, reconstructHistoryToStep, reportCaptureDiagnostics, reportSelfieFailure, resetNfcScan, sendClientInfo, skipNfcWithReason, storeDocumentOptions, updateSessionContactInfo, updateSessionCurrentStep, updateSessionStatus, updateSessionUserInput };
@@ -0,0 +1,9 @@
1
+ var HD_MIN = { long: 1280, short: 720 };
2
+ function isBelowHd(settings) {
3
+ var _a = settings !== null && settings !== void 0 ? settings : {}, width = _a.width, height = _a.height;
4
+ if (!width || !height)
5
+ return false;
6
+ return Math.max(width, height) < HD_MIN.long || Math.min(width, height) < HD_MIN.short;
7
+ }
8
+
9
+ export { HD_MIN, isBelowHd };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datakeen-session-react",
3
- "version": "1.1.201",
3
+ "version": "1.1.202-dev.2",
4
4
  "description": "React SDK component to manage and render Datakeen session experiences easily.",
5
5
  "publishConfig": {
6
6
  "access": "public",