@privateid/ultrapass-web-sdk 1.3.0 → 1.3.1-1300478

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 (230) hide show
  1. package/README.md +75 -75
  2. package/dist/apiUtils.d.ts +46 -46
  3. package/dist/apiUtils.js +922 -921
  4. package/dist/apiUtils.js.map +1 -1
  5. package/dist/application/index.d.ts +7 -7
  6. package/dist/application/index.js +27 -27
  7. package/dist/application/modules/core/document/DocumentService.d.ts +22 -22
  8. package/dist/application/modules/core/document/DocumentService.js +254 -254
  9. package/dist/application/modules/core/document/document.constants.d.ts +15 -15
  10. package/dist/application/modules/core/document/document.constants.js +21 -21
  11. package/dist/application/modules/core/document/document.domain.d.ts +7 -7
  12. package/dist/application/modules/core/document/document.domain.js +1 -1
  13. package/dist/application/modules/core/document/document.types.d.ts +17 -17
  14. package/dist/application/modules/core/document/document.types.js +1 -1
  15. package/dist/application/modules/core/document/document.utils.d.ts +3 -3
  16. package/dist/application/modules/core/document/document.utils.js +58 -58
  17. package/dist/application/modules/core/document/index.d.ts +3 -3
  18. package/dist/application/modules/core/document/index.js +1 -1
  19. package/dist/application/modules/core/face/FaceService.d.ts +33 -33
  20. package/dist/application/modules/core/face/FaceService.js +228 -221
  21. package/dist/application/modules/core/face/FaceService.js.map +1 -1
  22. package/dist/application/modules/core/face/face.constants.d.ts +53 -53
  23. package/dist/application/modules/core/face/face.constants.js +53 -53
  24. package/dist/application/modules/core/face/face.domain.d.ts +10 -10
  25. package/dist/application/modules/core/face/face.domain.js +1 -1
  26. package/dist/application/modules/core/face/face.types.d.ts +41 -38
  27. package/dist/application/modules/core/face/face.types.js +1 -1
  28. package/dist/application/modules/core/face/face.utils.d.ts +15 -15
  29. package/dist/application/modules/core/face/face.utils.js +101 -101
  30. package/dist/application/modules/core/face/index.d.ts +3 -3
  31. package/dist/application/modules/core/face/index.js +1 -1
  32. package/dist/application/modules/global/shared.constants.d.ts +2 -2
  33. package/dist/application/modules/global/shared.constants.js +2 -2
  34. package/dist/application/modules/global/shared.utils.d.ts +25 -25
  35. package/dist/application/modules/global/shared.utils.js +100 -100
  36. package/dist/application/modules/global/shared.utils.js.map +1 -1
  37. package/dist/application/modules/internal/feature-flag/LDFeatureFlagService.d.ts +9 -0
  38. package/dist/application/modules/internal/feature-flag/LDFeatureFlagService.js +32 -0
  39. package/dist/application/modules/internal/feature-flag/LDFeatureFlagService.js.map +1 -0
  40. package/dist/application/modules/internal/feature-flag/feature-flag-init.d.ts +11 -0
  41. package/dist/application/modules/internal/feature-flag/feature-flag-init.js +24 -0
  42. package/dist/application/modules/internal/feature-flag/feature-flag-init.js.map +1 -0
  43. package/dist/application/modules/internal/feature-flag/feature-flag.domain.d.ts +10 -0
  44. package/dist/application/modules/internal/feature-flag/feature-flag.domain.js +7 -0
  45. package/dist/application/modules/internal/feature-flag/feature-flag.domain.js.map +1 -0
  46. package/dist/application/modules/internal/feature-flag/featureFlagInit.d.ts +11 -0
  47. package/dist/application/modules/internal/feature-flag/featureFlagInit.js +44 -0
  48. package/dist/application/modules/internal/feature-flag/featureFlagInit.js.map +1 -0
  49. package/dist/application/modules/internal/feature-flag/index.d.ts +2 -0
  50. package/dist/application/modules/internal/feature-flag/index.js +3 -0
  51. package/dist/application/modules/internal/feature-flag/index.js.map +1 -0
  52. package/dist/application/modules/internal/shared/index.d.ts +2 -0
  53. package/dist/application/modules/internal/shared/index.js +3 -0
  54. package/dist/application/modules/internal/shared/index.js.map +1 -0
  55. package/dist/application/modules/internal/shared/shared.constants.d.ts +2 -0
  56. package/dist/application/modules/internal/shared/shared.constants.js +3 -0
  57. package/dist/application/modules/internal/shared/shared.constants.js.map +1 -0
  58. package/dist/application/modules/internal/shared/shared.utils.d.ts +44 -0
  59. package/dist/application/modules/internal/shared/shared.utils.js +204 -0
  60. package/dist/application/modules/internal/shared/shared.utils.js.map +1 -0
  61. package/dist/application/modules/internal/wasm-orchestrator/WasmOrchestratorService.d.ts +28 -0
  62. package/dist/application/modules/internal/wasm-orchestrator/WasmOrchestratorService.js +380 -0
  63. package/dist/application/modules/internal/wasm-orchestrator/WasmOrchestratorService.js.map +1 -0
  64. package/dist/application/modules/internal/wasm-orchestrator/index.d.ts +6 -0
  65. package/dist/application/modules/internal/wasm-orchestrator/index.js +9 -0
  66. package/dist/application/modules/internal/wasm-orchestrator/index.js.map +1 -0
  67. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.constants.d.ts +28 -0
  68. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.constants.js +35 -0
  69. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.constants.js.map +1 -0
  70. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.domain.d.ts +51 -0
  71. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.domain.js +2 -0
  72. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.domain.js.map +1 -0
  73. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.types.d.ts +142 -0
  74. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.types.js +2 -0
  75. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.types.js.map +1 -0
  76. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.d.ts +86 -0
  77. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.js +201 -0
  78. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.js.map +1 -0
  79. package/dist/application/modules/support/camera/CameraServiceFactory.d.ts +10 -10
  80. package/dist/application/modules/support/camera/CameraServiceFactory.js +33 -33
  81. package/dist/application/modules/support/camera/CameraServiceFactory.js.map +1 -1
  82. package/dist/application/modules/support/camera/camera.constants.d.ts +9 -9
  83. package/dist/application/modules/support/camera/camera.constants.js +48 -48
  84. package/dist/application/modules/support/camera/camera.domain.d.ts +15 -15
  85. package/dist/application/modules/support/camera/camera.domain.js +1 -1
  86. package/dist/application/modules/support/camera/camera.types.d.ts +42 -42
  87. package/dist/application/modules/support/camera/camera.types.js +10 -10
  88. package/dist/application/modules/support/camera/camera.utils.d.ts +157 -157
  89. package/dist/application/modules/support/camera/camera.utils.js +623 -618
  90. package/dist/application/modules/support/camera/camera.utils.js.map +1 -1
  91. package/dist/application/modules/support/camera/index.d.ts +24 -24
  92. package/dist/application/modules/support/camera/index.js +27 -27
  93. package/dist/application/modules/support/camera/services/BaseCameraService.d.ts +41 -41
  94. package/dist/application/modules/support/camera/services/BaseCameraService.js +278 -278
  95. package/dist/application/modules/support/camera/services/DesktopCameraService.d.ts +5 -5
  96. package/dist/application/modules/support/camera/services/DesktopCameraService.js +46 -46
  97. package/dist/application/modules/support/camera/services/DesktopCameraService.js.map +1 -1
  98. package/dist/application/modules/support/camera/services/FirefoxCameraService.d.ts +5 -5
  99. package/dist/application/modules/support/camera/services/FirefoxCameraService.js +46 -46
  100. package/dist/application/modules/support/camera/services/FirefoxCameraService.js.map +1 -1
  101. package/dist/application/modules/support/camera/services/MacSafariCameraService.d.ts +5 -5
  102. package/dist/application/modules/support/camera/services/MacSafariCameraService.js +47 -47
  103. package/dist/application/modules/support/camera/services/MacSafariCameraService.js.map +1 -1
  104. package/dist/application/modules/support/camera/services/MobileCameraService.d.ts +5 -5
  105. package/dist/application/modules/support/camera/services/MobileCameraService.js +133 -131
  106. package/dist/application/modules/support/camera/services/MobileCameraService.js.map +1 -1
  107. package/dist/application/modules/support/engine/EngineService.d.ts +15 -0
  108. package/dist/application/modules/support/engine/EngineService.js +106 -0
  109. package/dist/application/modules/support/engine/EngineService.js.map +1 -0
  110. package/dist/application/modules/support/engine/engine.constants.d.ts +33 -0
  111. package/dist/application/modules/support/engine/engine.constants.js +35 -0
  112. package/dist/application/modules/support/engine/engine.constants.js.map +1 -0
  113. package/dist/application/modules/support/engine/engine.domain.d.ts +23 -0
  114. package/dist/application/modules/support/engine/engine.domain.js +2 -0
  115. package/dist/application/modules/support/engine/engine.domain.js.map +1 -0
  116. package/dist/application/modules/support/engine/engine.types.d.ts +32 -0
  117. package/dist/application/modules/support/engine/engine.types.js +2 -0
  118. package/dist/application/modules/support/engine/engine.types.js.map +1 -0
  119. package/dist/application/modules/support/engine/engine.utils.d.ts +65 -0
  120. package/dist/application/modules/support/engine/engine.utils.js +135 -0
  121. package/dist/application/modules/support/engine/engine.utils.js.map +1 -0
  122. package/dist/application/modules/support/engine/index.d.ts +3 -0
  123. package/dist/application/modules/support/engine/index.js +2 -0
  124. package/dist/application/modules/support/engine/index.js.map +1 -0
  125. package/dist/application/modules/support/permissions/PermissionsService.d.ts +55 -43
  126. package/dist/application/modules/support/permissions/PermissionsService.js +183 -178
  127. package/dist/application/modules/support/permissions/PermissionsService.js.map +1 -1
  128. package/dist/application/modules/support/permissions/index.d.ts +4 -4
  129. package/dist/application/modules/support/permissions/index.js +2 -2
  130. package/dist/application/modules/support/permissions/permission.utils.d.ts +6 -6
  131. package/dist/application/modules/support/permissions/permission.utils.js +33 -33
  132. package/dist/application/modules/support/permissions/permissions.domain.d.ts +6 -6
  133. package/dist/application/modules/support/permissions/permissions.domain.js +1 -1
  134. package/dist/application/modules/support/permissions/permissions.types.d.ts +9 -9
  135. package/dist/application/modules/support/permissions/permissions.types.js +1 -1
  136. package/dist/application/modules/support/wasm/WasmService.d.ts +25 -25
  137. package/dist/application/modules/support/wasm/WasmService.js +156 -155
  138. package/dist/application/modules/support/wasm/WasmService.js.map +1 -1
  139. package/dist/application/modules/support/wasm/index.d.ts +6 -6
  140. package/dist/application/modules/support/wasm/index.js +8 -8
  141. package/dist/application/modules/support/wasm/wasm.constants.d.ts +78 -78
  142. package/dist/application/modules/support/wasm/wasm.constants.js +86 -86
  143. package/dist/application/modules/support/wasm/wasm.domain.d.ts +52 -52
  144. package/dist/application/modules/support/wasm/wasm.domain.js +1 -1
  145. package/dist/application/modules/support/wasm/wasm.types.d.ts +119 -118
  146. package/dist/application/modules/support/wasm/wasm.types.js +1 -1
  147. package/dist/application/modules/support/wasm/wasm.utils.d.ts +88 -88
  148. package/dist/application/modules/support/wasm/wasm.utils.js +243 -243
  149. package/dist/application/modules/support/wasm-orchestrator/WasmOrchestratorService.d.ts +28 -0
  150. package/dist/application/modules/support/wasm-orchestrator/WasmOrchestratorService.js +324 -0
  151. package/dist/application/modules/support/wasm-orchestrator/WasmOrchestratorService.js.map +1 -0
  152. package/dist/application/modules/support/wasm-orchestrator/index.d.ts +6 -0
  153. package/dist/application/modules/support/wasm-orchestrator/index.js +9 -0
  154. package/dist/application/modules/support/wasm-orchestrator/index.js.map +1 -0
  155. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.constants.d.ts +36 -0
  156. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.constants.js +44 -0
  157. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.constants.js.map +1 -0
  158. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.domain.d.ts +47 -0
  159. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.domain.js +2 -0
  160. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.domain.js.map +1 -0
  161. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.types.d.ts +136 -0
  162. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.types.js +2 -0
  163. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.types.js.map +1 -0
  164. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.utils.d.ts +91 -0
  165. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.utils.js +250 -0
  166. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.utils.js.map +1 -0
  167. package/dist/application/workers/index.d.ts +42 -42
  168. package/dist/application/workers/index.js +8 -8
  169. package/dist/application/workers/wasm/WasmWorkerService.d.ts +66 -0
  170. package/dist/application/workers/wasm/WasmWorkerService.js +801 -0
  171. package/dist/application/workers/wasm/WasmWorkerService.js.map +1 -0
  172. package/dist/application/workers/wasm/index.d.ts +4 -0
  173. package/dist/application/workers/wasm/index.js +9 -0
  174. package/dist/application/workers/wasm/index.js.map +1 -0
  175. package/dist/application/workers/wasm/wasm-worker.constants.d.ts +5 -0
  176. package/dist/application/workers/wasm/wasm-worker.constants.js +6 -0
  177. package/dist/application/workers/wasm/wasm-worker.constants.js.map +1 -0
  178. package/dist/application/workers/wasm/wasm-worker.domain.d.ts +99 -0
  179. package/dist/application/workers/wasm/wasm-worker.domain.js +2 -0
  180. package/dist/application/workers/wasm/wasm-worker.domain.js.map +1 -0
  181. package/dist/application/workers/wasm/wasm-worker.types.d.ts +88 -0
  182. package/dist/application/workers/wasm/wasm-worker.types.js +2 -0
  183. package/dist/application/workers/wasm/wasm-worker.types.js.map +1 -0
  184. package/dist/application/workers/wasm/wasm-worker.utils.d.ts +10 -0
  185. package/dist/application/workers/wasm/wasm-worker.utils.js +130 -0
  186. package/dist/application/workers/wasm/wasm-worker.utils.js.map +1 -0
  187. package/dist/buildConfig.d.ts +3 -0
  188. package/dist/buildConfig.js +7 -0
  189. package/dist/buildConfig.js.map +1 -0
  190. package/dist/cameraUtils.d.ts +77 -77
  191. package/dist/cameraUtils.js +361 -360
  192. package/dist/cameraUtils.js.map +1 -1
  193. package/dist/constants.d.ts +9 -9
  194. package/dist/constants.js +13 -12
  195. package/dist/constants.js.map +1 -1
  196. package/dist/createCallback.d.ts +56 -56
  197. package/dist/createCallback.js +332 -330
  198. package/dist/createCallback.js.map +1 -1
  199. package/dist/dbUtils.d.ts +14 -14
  200. package/dist/dbUtils.js +148 -147
  201. package/dist/dbUtils.js.map +1 -1
  202. package/dist/envUtils.d.ts +4 -4
  203. package/dist/envUtils.js +16 -15
  204. package/dist/envUtils.js.map +1 -1
  205. package/dist/faceModule.d.ts +196 -196
  206. package/dist/faceModule.js +978 -981
  207. package/dist/faceModule.js.map +1 -1
  208. package/dist/featureFlagInit.d.ts +11 -0
  209. package/dist/featureFlagInit.js +44 -0
  210. package/dist/featureFlagInit.js.map +1 -0
  211. package/dist/index.d.ts +38 -38
  212. package/dist/index.js +82 -82
  213. package/dist/main.d.ts +30 -24
  214. package/dist/main.js +84 -69
  215. package/dist/main.js.map +1 -1
  216. package/dist/types.d.ts +139 -139
  217. package/dist/types.js +77 -77
  218. package/dist/utils.d.ts +84 -84
  219. package/dist/utils.js +580 -579
  220. package/dist/utils.js.map +1 -1
  221. package/package.json +102 -102
  222. package/wasm/ultra/nosimd/{25.11.13-1357710 → 26.01.08-1300478}/privid_fhe_uber.js +18 -18
  223. package/wasm/ultra/nosimd/{25.11.13-1357710 → 26.01.08-1300478}/privid_fhe_uber.wasm +0 -0
  224. package/wasm/ultra/nosimd/version.json +2 -2
  225. package/wasm/ultra/simd/{25.11.13-1357710 → 26.01.08-1300478}/privid_fhe_uber.js +18 -18
  226. package/wasm/ultra/simd/{25.11.13-1357710 → 26.01.08-1300478}/privid_fhe_uber.wasm +0 -0
  227. package/wasm/ultra/simd/version.json +2 -2
  228. package/workers/comlink.min.js +7 -7
  229. package/workers/comlink.min.js.map +1 -1
  230. package/workers/wasm.worker.js +936 -924
@@ -1,279 +1,279 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- /* eslint-disable import/prefer-default-export */
11
- /* eslint-disable lines-between-class-members */
12
- import { CameraFaceMode, } from '../camera.types';
13
- import { printLogs, setDefaultCameraDeviceId } from '../../../global/shared.utils';
14
- import { isBackCameraLabel, isMobileDevice, startVideo } from '../camera.utils';
15
- export class BaseCameraService {
16
- constructor(permissionsService) {
17
- /** Current video element ID being used for camera stream */
18
- this.videoElementId = null;
19
- /** Selected camera device ID */
20
- this.currentDeviceId = null;
21
- /** Current camera facing mode (front/back) */
22
- this.faceMode = CameraFaceMode.front;
23
- /** Active media stream from the camera */
24
- this.mediaStream = null;
25
- /** List of available media devices (cameras) */
26
- this.mediaDevices = null;
27
- /** Observer to monitor unauthorized video source changes */
28
- this.videoMutationObserver = null;
29
- this.permissionsService = permissionsService;
30
- }
31
- prepareCameraResult(stream, devices, faceMode, videoElementId) {
32
- var _a, _b, _c, _d;
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const tracks = stream.getVideoTracks();
35
- // Validation: check if there are video tracks
36
- if (!tracks || tracks.length === 0) {
37
- printLogs('[BaseCameraService] prepareCameraResult: No video tracks in stream', '', 'ERROR');
38
- throw new Error('NO_VIDEO_TRACKS');
39
- }
40
- const track = tracks[0];
41
- // Validation: check if track is ready
42
- if (track.readyState !== 'live') {
43
- printLogs('[BaseCameraService] prepareCameraResult: Track not ready, waiting...', track.readyState, 'WARN');
44
- // Wait for track to be ready
45
- yield new Promise((resolve) => {
46
- if (track.readyState === 'live') {
47
- resolve();
48
- }
49
- else {
50
- const onReady = () => {
51
- track.removeEventListener('unmute', onReady);
52
- resolve();
53
- };
54
- track.addEventListener('unmute', onReady);
55
- // Safety timeout
56
- setTimeout(() => {
57
- track.removeEventListener('unmute', onReady);
58
- resolve();
59
- }, 2000);
60
- }
61
- });
62
- }
63
- const capabilities = track.getCapabilities ? track.getCapabilities() : null;
64
- let settings = track.getSettings ? track.getSettings() : null;
65
- // On some Android devices, getSettings() might return null initially
66
- // Try to wait and retry getting settings
67
- if (!settings) {
68
- printLogs('[BaseCameraService] prepareCameraResult: Could not get track settings, retrying...', '', 'WARN');
69
- yield new Promise((resolve) => setTimeout(resolve, 500));
70
- settings = track.getSettings ? track.getSettings() : null;
71
- if (!settings) {
72
- // Last resort: create minimal settings object from track properties
73
- printLogs('[BaseCameraService] prepareCameraResult: Still no settings, creating fallback', '', 'WARN');
74
- settings = {
75
- deviceId: this.currentDeviceId || undefined,
76
- width: ((_b = (_a = track.getConstraints) === null || _a === void 0 ? void 0 : _a.call(track)) === null || _b === void 0 ? void 0 : _b.width) || undefined,
77
- height: ((_d = (_c = track.getConstraints) === null || _c === void 0 ? void 0 : _c.call(track)) === null || _d === void 0 ? void 0 : _d.height) || undefined,
78
- facingMode: faceMode === CameraFaceMode.back ? 'environment' : 'user',
79
- };
80
- printLogs('[BaseCameraService] prepareCameraResult: Using fallback settings', settings, 'WARN');
81
- }
82
- }
83
- printLogs('[BaseCameraService] prepareCameraResult settings: ', settings);
84
- if (capabilities) {
85
- printLogs('[BaseCameraService] prepareCameraResult capabilities: ', capabilities);
86
- }
87
- printLogs('[BaseCameraService] prepareCameraResult stream', stream);
88
- yield startVideo(videoElementId, stream);
89
- this.setMediaStream(stream);
90
- this.setMediaDevices(devices);
91
- return {
92
- // TODO: what does this status represents? Should it be `success`?
93
- status: true,
94
- stream,
95
- devices,
96
- faceMode,
97
- settings,
98
- capabilities,
99
- errorMessage: null,
100
- };
101
- });
102
- }
103
- // function to wait until the camera is released before opening it again
104
- static waitForCameraRelease(targetDeviceId, targetFaceMode) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- const isDesktop = !isMobileDevice();
107
- const maxAttempts = isDesktop ? 5 : 10; // desktop can try less times
108
- const delayMs = isDesktop ? 100 : 150; // desktop can use shorter delay
109
- for (let attempt = 0; attempt < maxAttempts; attempt++) {
110
- try {
111
- // build constraints based on target deviceId or faceMode
112
- const testConstraints = {
113
- audio: false,
114
- video: targetDeviceId
115
- ? { deviceId: { exact: targetDeviceId } }
116
- : { facingMode: targetFaceMode === CameraFaceMode.back ? 'environment' : 'user' },
117
- };
118
- printLogs(`[waitForCameraRelease] Attempt ${attempt + 1} - Testing camera availability`, testConstraints);
119
- const testStream = yield navigator.mediaDevices.getUserMedia(testConstraints);
120
- // if succeeded, camera is released
121
- testStream.getTracks().forEach((track) => track.stop());
122
- printLogs(`[waitForCameraRelease] Camera released after ${attempt} attempts`, '');
123
- // Wait a bit more to ensure the track is really closed
124
- yield new Promise((resolve) => setTimeout(resolve, 100));
125
- return;
126
- }
127
- catch (error) {
128
- // Camera still busy, wait and try again
129
- printLogs(`[waitForCameraRelease] Attempt ${attempt + 1}/${maxAttempts} - Camera still busy: ${error.name}`, '');
130
- yield new Promise((resolve) => setTimeout(resolve, delayMs));
131
- }
132
- }
133
- // If reached here, couldn't verify but let's proceed
134
- printLogs('[waitForCameraRelease] Max attempts reached, proceeding anyway', '', 'WARN');
135
- });
136
- }
137
- closeCamera(element) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- try {
140
- // TODO: Control devices, elements and streams only on SDK side to avoid issues with multiple SDK instances
141
- const video = element || this.getVideoElementId();
142
- const videoEl = document.getElementById(video);
143
- const streamFromElement = videoEl === null || videoEl === void 0 ? void 0 : videoEl.srcObject;
144
- printLogs('[BaseCameraService] closeCamera streamFromElement:', this.mediaStream);
145
- if (streamFromElement) {
146
- const tracks = streamFromElement.getTracks();
147
- tracks.forEach((track) => {
148
- printLogs('[BaseCameraService] closeCamera Stopping track:', track.label);
149
- track.stop();
150
- });
151
- videoEl.srcObject = null;
152
- // Wait for all tracks to finish stopping
153
- yield Promise.all(tracks.map((track) => new Promise((resolve) => {
154
- if (track.readyState === 'ended') {
155
- resolve();
156
- }
157
- else {
158
- // eslint-disable-next-line no-param-reassign
159
- track.onended = () => resolve();
160
- setTimeout(() => resolve(), 1000);
161
- }
162
- })));
163
- }
164
- this.closeMediaStream();
165
- this.setCurrentDeviceId(null);
166
- this.setMediaDevices(null);
167
- this.closeVideoMutationObserver();
168
- // backoff to ensure camera hardware is released
169
- yield new Promise((resolve) => setTimeout(resolve, 200));
170
- printLogs('[BaseCameraService] closeCamera: hardware released', '');
171
- }
172
- catch (error) {
173
- printLogs(`[BaseCameraService] closeCamera error: `, error, 'ERROR');
174
- }
175
- });
176
- }
177
- cameraSwitch(params) {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- if (!this.getVideoElementId())
180
- return null;
181
- const mediaDevices = this.getMediaDevices();
182
- // Security check: This is to prevent switching when no devices are available normally caused by race conditions where we have on attenpt to switch
183
- // on "road" and the user tried to switch camera very fast multiple times what cause the race condition on browsers. To avoid this we just check if we have devices available before switching."
184
- if (!mediaDevices || mediaDevices.length === 0) {
185
- printLogs('[BaseCameraService] cameraSwitch: No media devices available', '', 'WARN');
186
- return null;
187
- }
188
- const selectedDevice = mediaDevices.find((dev) => dev.deviceId === params.deviceId);
189
- // An additional security check to avoid switching to a non existing device
190
- if (!selectedDevice) {
191
- printLogs('[BaseCameraService] cameraSwitch: Device not found', params.deviceId, 'WARN');
192
- return null;
193
- }
194
- const resolvedFaceMode = isBackCameraLabel(selectedDevice.label)
195
- ? CameraFaceMode.back
196
- : CameraFaceMode.front;
197
- printLogs('[BaseCameraService] cameraSwitch deviceId:', params.deviceId);
198
- yield this.closeCamera();
199
- yield BaseCameraService.waitForCameraRelease(params.deviceId, resolvedFaceMode);
200
- const result = yield this.openCamera({
201
- videoElementId: this.getVideoElementId(),
202
- deviceId: params.deviceId,
203
- requestFaceMode: resolvedFaceMode,
204
- });
205
- if (!result) {
206
- printLogs('[BaseCameraService] cameraSwitch: Failed to open camera', '', 'ERROR');
207
- return null;
208
- }
209
- return {
210
- capabilities: result.capabilities,
211
- settings: result.settings,
212
- };
213
- });
214
- }
215
- isActive() {
216
- return this.mediaStream !== null;
217
- }
218
- // Video Element ID
219
- setVideoElementId(videoElementId) {
220
- this.videoElementId = videoElementId;
221
- }
222
- getVideoElementId() {
223
- return this.videoElementId;
224
- }
225
- // Video Element DOM
226
- getVideoElementDOM() {
227
- if (!this.videoElementId)
228
- return null;
229
- return document.getElementById(this.videoElementId);
230
- }
231
- // Face Mode
232
- setFaceMode(faceMode) {
233
- this.faceMode = faceMode;
234
- }
235
- getFaceMode() {
236
- return this.faceMode;
237
- }
238
- // Media Stream
239
- setMediaStream(mediaStream) {
240
- this.mediaStream = mediaStream;
241
- }
242
- getMediaStream() {
243
- return this.mediaStream;
244
- }
245
- closeMediaStream() {
246
- if (this.mediaStream) {
247
- this.mediaStream.getTracks().forEach((track) => track.stop());
248
- }
249
- }
250
- // Media Devices
251
- setMediaDevices(devices) {
252
- this.mediaDevices = devices;
253
- }
254
- getMediaDevices() {
255
- return this.mediaDevices;
256
- }
257
- // Current Device
258
- setCurrentDeviceId(deviceId) {
259
- this.currentDeviceId = deviceId;
260
- setDefaultCameraDeviceId(deviceId);
261
- }
262
- getCurrentDeviceId() {
263
- return this.currentDeviceId;
264
- }
265
- // Video Mutation Observer
266
- getVideoMutationObserver() {
267
- return this.videoMutationObserver;
268
- }
269
- closeVideoMutationObserver() {
270
- if (this.videoMutationObserver) {
271
- this.videoMutationObserver.disconnect();
272
- this.videoMutationObserver = null;
273
- }
274
- }
275
- checkVideoElementIsReady() {
276
- return this.getVideoElementDOM() && this.getVideoElementDOM().readyState === 4;
277
- }
278
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /* eslint-disable import/prefer-default-export */
11
+ /* eslint-disable lines-between-class-members */
12
+ import { CameraFaceMode, } from '../camera.types';
13
+ import { printLogs, setDefaultCameraDeviceId } from '../../../global/shared.utils';
14
+ import { isBackCameraLabel, isMobileDevice, startVideo } from '../camera.utils';
15
+ export class BaseCameraService {
16
+ constructor(permissionsService) {
17
+ /** Current video element ID being used for camera stream */
18
+ this.videoElementId = null;
19
+ /** Selected camera device ID */
20
+ this.currentDeviceId = null;
21
+ /** Current camera facing mode (front/back) */
22
+ this.faceMode = CameraFaceMode.front;
23
+ /** Active media stream from the camera */
24
+ this.mediaStream = null;
25
+ /** List of available media devices (cameras) */
26
+ this.mediaDevices = null;
27
+ /** Observer to monitor unauthorized video source changes */
28
+ this.videoMutationObserver = null;
29
+ this.permissionsService = permissionsService;
30
+ }
31
+ prepareCameraResult(stream, devices, faceMode, videoElementId) {
32
+ var _a, _b, _c, _d;
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const tracks = stream.getVideoTracks();
35
+ // Validation: check if there are video tracks
36
+ if (!tracks || tracks.length === 0) {
37
+ printLogs('[BaseCameraService] prepareCameraResult: No video tracks in stream', '', 'ERROR');
38
+ throw new Error('NO_VIDEO_TRACKS');
39
+ }
40
+ const track = tracks[0];
41
+ // Validation: check if track is ready
42
+ if (track.readyState !== 'live') {
43
+ printLogs('[BaseCameraService] prepareCameraResult: Track not ready, waiting...', track.readyState, 'WARN');
44
+ // Wait for track to be ready
45
+ yield new Promise((resolve) => {
46
+ if (track.readyState === 'live') {
47
+ resolve();
48
+ }
49
+ else {
50
+ const onReady = () => {
51
+ track.removeEventListener('unmute', onReady);
52
+ resolve();
53
+ };
54
+ track.addEventListener('unmute', onReady);
55
+ // Safety timeout
56
+ setTimeout(() => {
57
+ track.removeEventListener('unmute', onReady);
58
+ resolve();
59
+ }, 2000);
60
+ }
61
+ });
62
+ }
63
+ const capabilities = track.getCapabilities ? track.getCapabilities() : null;
64
+ let settings = track.getSettings ? track.getSettings() : null;
65
+ // On some Android devices, getSettings() might return null initially
66
+ // Try to wait and retry getting settings
67
+ if (!settings) {
68
+ printLogs('[BaseCameraService] prepareCameraResult: Could not get track settings, retrying...', '', 'WARN');
69
+ yield new Promise((resolve) => setTimeout(resolve, 500));
70
+ settings = track.getSettings ? track.getSettings() : null;
71
+ if (!settings) {
72
+ // Last resort: create minimal settings object from track properties
73
+ printLogs('[BaseCameraService] prepareCameraResult: Still no settings, creating fallback', '', 'WARN');
74
+ settings = {
75
+ deviceId: this.currentDeviceId || undefined,
76
+ width: ((_b = (_a = track.getConstraints) === null || _a === void 0 ? void 0 : _a.call(track)) === null || _b === void 0 ? void 0 : _b.width) || undefined,
77
+ height: ((_d = (_c = track.getConstraints) === null || _c === void 0 ? void 0 : _c.call(track)) === null || _d === void 0 ? void 0 : _d.height) || undefined,
78
+ facingMode: faceMode === CameraFaceMode.back ? 'environment' : 'user',
79
+ };
80
+ printLogs('[BaseCameraService] prepareCameraResult: Using fallback settings', settings, 'WARN');
81
+ }
82
+ }
83
+ printLogs('[BaseCameraService] prepareCameraResult settings: ', settings);
84
+ if (capabilities) {
85
+ printLogs('[BaseCameraService] prepareCameraResult capabilities: ', capabilities);
86
+ }
87
+ printLogs('[BaseCameraService] prepareCameraResult stream', stream);
88
+ yield startVideo(videoElementId, stream);
89
+ this.setMediaStream(stream);
90
+ this.setMediaDevices(devices);
91
+ return {
92
+ // TODO: what does this status represents? Should it be `success`?
93
+ status: true,
94
+ stream,
95
+ devices,
96
+ faceMode,
97
+ settings,
98
+ capabilities,
99
+ errorMessage: null,
100
+ };
101
+ });
102
+ }
103
+ // function to wait until the camera is released before opening it again
104
+ static waitForCameraRelease(targetDeviceId, targetFaceMode) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const isDesktop = !isMobileDevice();
107
+ const maxAttempts = isDesktop ? 5 : 10; // desktop can try less times
108
+ const delayMs = isDesktop ? 100 : 150; // desktop can use shorter delay
109
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
110
+ try {
111
+ // build constraints based on target deviceId or faceMode
112
+ const testConstraints = {
113
+ audio: false,
114
+ video: targetDeviceId
115
+ ? { deviceId: { exact: targetDeviceId } }
116
+ : { facingMode: targetFaceMode === CameraFaceMode.back ? 'environment' : 'user' },
117
+ };
118
+ printLogs(`[waitForCameraRelease] Attempt ${attempt + 1} - Testing camera availability`, testConstraints);
119
+ const testStream = yield navigator.mediaDevices.getUserMedia(testConstraints);
120
+ // if succeeded, camera is released
121
+ testStream.getTracks().forEach((track) => track.stop());
122
+ printLogs(`[waitForCameraRelease] Camera released after ${attempt} attempts`, '');
123
+ // Wait a bit more to ensure the track is really closed
124
+ yield new Promise((resolve) => setTimeout(resolve, 100));
125
+ return;
126
+ }
127
+ catch (error) {
128
+ // Camera still busy, wait and try again
129
+ printLogs(`[waitForCameraRelease] Attempt ${attempt + 1}/${maxAttempts} - Camera still busy: ${error.name}`, '');
130
+ yield new Promise((resolve) => setTimeout(resolve, delayMs));
131
+ }
132
+ }
133
+ // If reached here, couldn't verify but let's proceed
134
+ printLogs('[waitForCameraRelease] Max attempts reached, proceeding anyway', '', 'WARN');
135
+ });
136
+ }
137
+ closeCamera(element) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ try {
140
+ // TODO: Control devices, elements and streams only on SDK side to avoid issues with multiple SDK instances
141
+ const video = element || this.getVideoElementId();
142
+ const videoEl = document.getElementById(video);
143
+ const streamFromElement = videoEl === null || videoEl === void 0 ? void 0 : videoEl.srcObject;
144
+ printLogs('[BaseCameraService] closeCamera streamFromElement:', this.mediaStream);
145
+ if (streamFromElement) {
146
+ const tracks = streamFromElement.getTracks();
147
+ tracks.forEach((track) => {
148
+ printLogs('[BaseCameraService] closeCamera Stopping track:', track.label);
149
+ track.stop();
150
+ });
151
+ videoEl.srcObject = null;
152
+ // Wait for all tracks to finish stopping
153
+ yield Promise.all(tracks.map((track) => new Promise((resolve) => {
154
+ if (track.readyState === 'ended') {
155
+ resolve();
156
+ }
157
+ else {
158
+ // eslint-disable-next-line no-param-reassign
159
+ track.onended = () => resolve();
160
+ setTimeout(() => resolve(), 1000);
161
+ }
162
+ })));
163
+ }
164
+ this.closeMediaStream();
165
+ this.setCurrentDeviceId(null);
166
+ this.setMediaDevices(null);
167
+ this.closeVideoMutationObserver();
168
+ // backoff to ensure camera hardware is released
169
+ yield new Promise((resolve) => setTimeout(resolve, 200));
170
+ printLogs('[BaseCameraService] closeCamera: hardware released', '');
171
+ }
172
+ catch (error) {
173
+ printLogs(`[BaseCameraService] closeCamera error: `, error, 'ERROR');
174
+ }
175
+ });
176
+ }
177
+ cameraSwitch(params) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ if (!this.getVideoElementId())
180
+ return null;
181
+ const mediaDevices = this.getMediaDevices();
182
+ // Security check: This is to prevent switching when no devices are available normally caused by race conditions where we have on attenpt to switch
183
+ // on "road" and the user tried to switch camera very fast multiple times what cause the race condition on browsers. To avoid this we just check if we have devices available before switching."
184
+ if (!mediaDevices || mediaDevices.length === 0) {
185
+ printLogs('[BaseCameraService] cameraSwitch: No media devices available', '', 'WARN');
186
+ return null;
187
+ }
188
+ const selectedDevice = mediaDevices.find((dev) => dev.deviceId === params.deviceId);
189
+ // An additional security check to avoid switching to a non existing device
190
+ if (!selectedDevice) {
191
+ printLogs('[BaseCameraService] cameraSwitch: Device not found', params.deviceId, 'WARN');
192
+ return null;
193
+ }
194
+ const resolvedFaceMode = isBackCameraLabel(selectedDevice.label)
195
+ ? CameraFaceMode.back
196
+ : CameraFaceMode.front;
197
+ printLogs('[BaseCameraService] cameraSwitch deviceId:', params.deviceId);
198
+ yield this.closeCamera();
199
+ yield BaseCameraService.waitForCameraRelease(params.deviceId, resolvedFaceMode);
200
+ const result = yield this.openCamera({
201
+ videoElementId: this.getVideoElementId(),
202
+ deviceId: params.deviceId,
203
+ requestFaceMode: resolvedFaceMode,
204
+ });
205
+ if (!result) {
206
+ printLogs('[BaseCameraService] cameraSwitch: Failed to open camera', '', 'ERROR');
207
+ return null;
208
+ }
209
+ return {
210
+ capabilities: result.capabilities,
211
+ settings: result.settings,
212
+ };
213
+ });
214
+ }
215
+ isActive() {
216
+ return this.mediaStream !== null;
217
+ }
218
+ // Video Element ID
219
+ setVideoElementId(videoElementId) {
220
+ this.videoElementId = videoElementId;
221
+ }
222
+ getVideoElementId() {
223
+ return this.videoElementId;
224
+ }
225
+ // Video Element DOM
226
+ getVideoElementDOM() {
227
+ if (!this.videoElementId)
228
+ return null;
229
+ return document.getElementById(this.videoElementId);
230
+ }
231
+ // Face Mode
232
+ setFaceMode(faceMode) {
233
+ this.faceMode = faceMode;
234
+ }
235
+ getFaceMode() {
236
+ return this.faceMode;
237
+ }
238
+ // Media Stream
239
+ setMediaStream(mediaStream) {
240
+ this.mediaStream = mediaStream;
241
+ }
242
+ getMediaStream() {
243
+ return this.mediaStream;
244
+ }
245
+ closeMediaStream() {
246
+ if (this.mediaStream) {
247
+ this.mediaStream.getTracks().forEach((track) => track.stop());
248
+ }
249
+ }
250
+ // Media Devices
251
+ setMediaDevices(devices) {
252
+ this.mediaDevices = devices;
253
+ }
254
+ getMediaDevices() {
255
+ return this.mediaDevices;
256
+ }
257
+ // Current Device
258
+ setCurrentDeviceId(deviceId) {
259
+ this.currentDeviceId = deviceId;
260
+ setDefaultCameraDeviceId(deviceId);
261
+ }
262
+ getCurrentDeviceId() {
263
+ return this.currentDeviceId;
264
+ }
265
+ // Video Mutation Observer
266
+ getVideoMutationObserver() {
267
+ return this.videoMutationObserver;
268
+ }
269
+ closeVideoMutationObserver() {
270
+ if (this.videoMutationObserver) {
271
+ this.videoMutationObserver.disconnect();
272
+ this.videoMutationObserver = null;
273
+ }
274
+ }
275
+ checkVideoElementIsReady() {
276
+ return this.getVideoElementDOM() && this.getVideoElementDOM().readyState === 4;
277
+ }
278
+ }
279
279
  //# sourceMappingURL=BaseCameraService.js.map
@@ -1,5 +1,5 @@
1
- import { BaseCameraService } from './BaseCameraService';
2
- import { CameraOpenResult, OpenCameraProps } from '../camera.types';
3
- export declare class DesktopCameraService extends BaseCameraService {
4
- openCamera(props: OpenCameraProps): Promise<CameraOpenResult>;
5
- }
1
+ import { BaseCameraService } from './BaseCameraService';
2
+ import { CameraOpenResult, OpenCameraProps } from '../camera.types';
3
+ export declare class DesktopCameraService extends BaseCameraService {
4
+ openCamera(props: OpenCameraProps): Promise<CameraOpenResult>;
5
+ }