@aws-amplify/ui-react-liveness 3.6.4 → 3.6.6

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.
@@ -810,9 +810,12 @@ const livenessMachine = createMachine({
810
810
  const { videoConstraints } = context.videoAssociatedParams;
811
811
  const { componentProps } = context;
812
812
  let targetDeviceId;
813
+ // Determine if the deviceId was explicitly provided via props (strict match)
814
+ // or retrieved from localStorage (preferred but not required)
815
+ const isExplicitDeviceId = !!componentProps?.config?.deviceId;
813
816
  let cameraNotFound = false;
814
- if (componentProps?.config?.deviceId) {
815
- targetDeviceId = componentProps.config.deviceId;
817
+ if (isExplicitDeviceId) {
818
+ targetDeviceId = componentProps?.config?.deviceId;
816
819
  }
817
820
  else {
818
821
  targetDeviceId = getLastSelectedCameraId() ?? undefined;
@@ -822,7 +825,11 @@ const livenessMachine = createMachine({
822
825
  video: {
823
826
  ...videoConstraints,
824
827
  ...(targetDeviceId
825
- ? { deviceId: { exact: targetDeviceId } }
828
+ ? {
829
+ deviceId: isExplicitDeviceId
830
+ ? { exact: targetDeviceId }
831
+ : { ideal: targetDeviceId },
832
+ }
826
833
  : {}),
827
834
  },
828
835
  audio: false,
@@ -881,9 +888,15 @@ const livenessMachine = createMachine({
881
888
  selectedDeviceId: initialStreamDeviceId,
882
889
  selectableDevices: realVideoDevices,
883
890
  };
884
- // If a specific camera was requested but not found, trigger a specific error
891
+ // If a previously-saved camera was not found, clear the stale ID and continue.
892
+ // Only throw an error if the deviceId was explicitly provided via props.
885
893
  if (cameraNotFound) {
886
- throw new Error(LivenessErrorState.DEFAULT_CAMERA_NOT_FOUND_ERROR);
894
+ if (isExplicitDeviceId) {
895
+ throw new Error(LivenessErrorState.DEFAULT_CAMERA_NOT_FOUND_ERROR);
896
+ }
897
+ else {
898
+ localStorage.removeItem(CAMERA_ID_KEY);
899
+ }
887
900
  }
888
901
  return result;
889
902
  },
@@ -156,13 +156,21 @@ class CustomWebSocketFetchHandler {
156
156
  socket.close();
157
157
  reject(error);
158
158
  };
159
- socket.onclose = () => {
159
+ socket.onclose = (event) => {
160
160
  this.removeNotUsableSockets(socket.url);
161
161
  if (socketErrorOccurred)
162
162
  return;
163
163
  if (streamError) {
164
164
  reject(streamError);
165
165
  }
166
+ else if (event.code !== WS_CLOSURE_CODE.SUCCESS_CODE &&
167
+ event.code !== 1001) {
168
+ // Server closed the connection with an abnormal code (e.g. 4001
169
+ // StreamIdleTimeout, 4003 SessionExpired, 1006 abnormal closure).
170
+ reject(new Error(`Server ended the connection unexpectedly (code ${event.code}` +
171
+ (event.reason ? `: ${event.reason}` : '') +
172
+ ')'));
173
+ }
166
174
  else {
167
175
  resolve({
168
176
  done: true,
@@ -1,3 +1,3 @@
1
- const VERSION = '3.6.4';
1
+ const VERSION = '3.6.6';
2
2
 
3
3
  export { VERSION };
package/dist/index.js CHANGED
@@ -1227,7 +1227,7 @@ function createRequestStreamGenerator(stream) {
1227
1227
  };
1228
1228
  }
1229
1229
 
1230
- const VERSION = '3.6.4';
1230
+ const VERSION = '3.6.6';
1231
1231
 
1232
1232
  const BASE_USER_AGENT = `ui-react-liveness/${VERSION}`;
1233
1233
  const getLivenessUserAgent = () => {
@@ -1386,13 +1386,21 @@ class CustomWebSocketFetchHandler {
1386
1386
  socket.close();
1387
1387
  reject(error);
1388
1388
  };
1389
- socket.onclose = () => {
1389
+ socket.onclose = (event) => {
1390
1390
  this.removeNotUsableSockets(socket.url);
1391
1391
  if (socketErrorOccurred)
1392
1392
  return;
1393
1393
  if (streamError) {
1394
1394
  reject(streamError);
1395
1395
  }
1396
+ else if (event.code !== WS_CLOSURE_CODE.SUCCESS_CODE &&
1397
+ event.code !== 1001) {
1398
+ // Server closed the connection with an abnormal code (e.g. 4001
1399
+ // StreamIdleTimeout, 4003 SessionExpired, 1006 abnormal closure).
1400
+ reject(new Error(`Server ended the connection unexpectedly (code ${event.code}` +
1401
+ (event.reason ? `: ${event.reason}` : '') +
1402
+ ')'));
1403
+ }
1396
1404
  else {
1397
1405
  resolve({
1398
1406
  done: true,
@@ -2572,9 +2580,12 @@ const livenessMachine = xstate.createMachine({
2572
2580
  const { videoConstraints } = context.videoAssociatedParams;
2573
2581
  const { componentProps } = context;
2574
2582
  let targetDeviceId;
2583
+ // Determine if the deviceId was explicitly provided via props (strict match)
2584
+ // or retrieved from localStorage (preferred but not required)
2585
+ const isExplicitDeviceId = !!componentProps?.config?.deviceId;
2575
2586
  let cameraNotFound = false;
2576
- if (componentProps?.config?.deviceId) {
2577
- targetDeviceId = componentProps.config.deviceId;
2587
+ if (isExplicitDeviceId) {
2588
+ targetDeviceId = componentProps?.config?.deviceId;
2578
2589
  }
2579
2590
  else {
2580
2591
  targetDeviceId = getLastSelectedCameraId() ?? undefined;
@@ -2584,7 +2595,11 @@ const livenessMachine = xstate.createMachine({
2584
2595
  video: {
2585
2596
  ...videoConstraints,
2586
2597
  ...(targetDeviceId
2587
- ? { deviceId: { exact: targetDeviceId } }
2598
+ ? {
2599
+ deviceId: isExplicitDeviceId
2600
+ ? { exact: targetDeviceId }
2601
+ : { ideal: targetDeviceId },
2602
+ }
2588
2603
  : {}),
2589
2604
  },
2590
2605
  audio: false,
@@ -2643,9 +2658,15 @@ const livenessMachine = xstate.createMachine({
2643
2658
  selectedDeviceId: initialStreamDeviceId,
2644
2659
  selectableDevices: realVideoDevices,
2645
2660
  };
2646
- // If a specific camera was requested but not found, trigger a specific error
2661
+ // If a previously-saved camera was not found, clear the stale ID and continue.
2662
+ // Only throw an error if the deviceId was explicitly provided via props.
2647
2663
  if (cameraNotFound) {
2648
- throw new Error(LivenessErrorState.DEFAULT_CAMERA_NOT_FOUND_ERROR);
2664
+ if (isExplicitDeviceId) {
2665
+ throw new Error(LivenessErrorState.DEFAULT_CAMERA_NOT_FOUND_ERROR);
2666
+ }
2667
+ else {
2668
+ localStorage.removeItem(CAMERA_ID_KEY);
2669
+ }
2649
2670
  }
2650
2671
  return result;
2651
2672
  },
@@ -1 +1 @@
1
- export declare const VERSION = "3.6.4";
1
+ export declare const VERSION = "3.6.6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/ui-react-liveness",
3
- "version": "3.6.4",
3
+ "version": "3.6.6",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "exports": {
@@ -49,8 +49,8 @@
49
49
  "react-dom": "^16.14 || ^17 || ^18 || ^19"
50
50
  },
51
51
  "dependencies": {
52
- "@aws-amplify/ui": "6.15.3",
53
- "@aws-amplify/ui-react": "6.15.3",
52
+ "@aws-amplify/ui": "6.15.4",
53
+ "@aws-amplify/ui-react": "6.15.4",
54
54
  "@aws-sdk/client-rekognitionstreaming": "3.967.0",
55
55
  "@aws-sdk/util-format-url": "3.965.0",
56
56
  "@smithy/eventstream-serde-browser": "^4.0.4",
@@ -65,7 +65,7 @@
65
65
  "@tensorflow/tfjs-core": "4.11.0",
66
66
  "@xstate/react": "^3.2.2",
67
67
  "tslib": "^2.5.2",
68
- "uuid": "^11.1.0",
68
+ "uuid": "^11.1.1",
69
69
  "xstate": "^4.33.6"
70
70
  },
71
71
  "devDependencies": {