idmission-web-sdk 2.3.225-feature-per-runtime-capability-probe-e2ff01d → 2.3.225

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.
package/dist/sdk2.esm.js CHANGED
@@ -204,7 +204,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
204
204
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
205
205
  };
206
206
 
207
- var webSdkVersion = '2.3.224';
207
+ var webSdkVersion = '2.3.225';
208
208
 
209
209
  function getPlatform() {
210
210
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -3194,20 +3194,28 @@ function probeNetworkSpeed() {
3194
3194
  // invokes a particular runtime never loads its WASM payload.
3195
3195
  function probeDelegateForRuntime(runtime) {
3196
3196
  return __awaiter(this, void 0, void 0, function () {
3197
- var state, firstError_1, secondError_1;
3197
+ var state, MAX_WAIT_MS_1, firstError_1, secondError_1;
3198
3198
  return __generator(this, function (_a) {
3199
3199
  switch (_a.label) {
3200
3200
  case 0:
3201
3201
  state = modelCapabilities.delegateByRuntime[runtime];
3202
3202
  if (state.probeState === 'probed') return [2 /*return*/];
3203
3203
  if (state.probeState === 'probing') {
3204
+ MAX_WAIT_MS_1 = 30000;
3204
3205
  return [2 /*return*/, new Promise(function (resolve) {
3205
3206
  var id = setInterval(function () {
3206
3207
  if (state.probeState === 'probed') {
3207
3208
  clearInterval(id);
3209
+ clearTimeout(timeoutId);
3208
3210
  resolve();
3209
3211
  }
3210
3212
  }, 100);
3213
+ // Forward-referenced by the interval callback above; safe because the
3214
+ // callback only fires after this line has run.
3215
+ var timeoutId = setTimeout(function () {
3216
+ clearInterval(id);
3217
+ resolve();
3218
+ }, MAX_WAIT_MS_1);
3211
3219
  })];
3212
3220
  }
3213
3221
  state.probeState = 'probing';
@@ -3514,19 +3522,7 @@ var preloadBarcodeReadabilityModelDependencies = function preloadBarcodeReadabil
3514
3522
  };
3515
3523
  function preloadModelDependencies(model) {
3516
3524
  return __awaiter(this, void 0, void 0, function () {
3517
- function handleModelDownloadProgress(event) {
3518
- var detail = event.detail;
3519
- if (!dependencies.some(function (d) {
3520
- return d.url === detail.url;
3521
- })) return;
3522
- progressByUseCase[model] = sumUpProgressForDependencies(dependencies.map(function (d) {
3523
- return d.url;
3524
- }));
3525
- document.dispatchEvent(new CustomEvent("idmission.preloadProgress.".concat(model), {
3526
- detail: progressByUseCase[model]
3527
- }));
3528
- }
3529
- var dependencies;
3525
+ var dependencies_1, handleModelDownloadProgress;
3530
3526
  return __generator(this, function (_a) {
3531
3527
  switch (_a.label) {
3532
3528
  case 0:
@@ -3539,40 +3535,62 @@ function preloadModelDependencies(model) {
3539
3535
  }, 100);
3540
3536
  })];
3541
3537
  modelsPreloading[model] = true;
3538
+ _a.label = 1;
3539
+ case 1:
3540
+ _a.trys.push([1,, 8, 9]);
3542
3541
  // All five models in this function are MediaPipe-backed; probe MP's
3543
3542
  // delegate to surface NONE before we waste bandwidth downloading bytes
3544
3543
  // for a model the device can't run.
3545
3544
  return [4 /*yield*/, probeNetworkSpeed()];
3546
- case 1:
3545
+ case 2:
3547
3546
  // All five models in this function are MediaPipe-backed; probe MP's
3548
3547
  // delegate to surface NONE before we waste bandwidth downloading bytes
3549
3548
  // for a model the device can't run.
3550
3549
  _a.sent();
3551
3550
  return [4 /*yield*/, probeDelegateForRuntime('mediapipe')];
3552
- case 2:
3551
+ case 3:
3553
3552
  _a.sent();
3554
3553
  if (getDelegate('mediapipe') === 'NONE') {
3555
3554
  throw new Error("No available delegate for ".concat(model, " model."));
3556
3555
  }
3557
- dependencies = [{
3556
+ dependencies_1 = [{
3558
3557
  url: defaultModelPaths[model],
3559
3558
  hash: defaultModelPaths[model + 'Hash']
3560
3559
  }];
3560
+ handleModelDownloadProgress = function handleModelDownloadProgress(event) {
3561
+ var detail = event.detail;
3562
+ if (!dependencies_1.some(function (d) {
3563
+ return d.url === detail.url;
3564
+ })) return;
3565
+ progressByUseCase[model] = sumUpProgressForDependencies(dependencies_1.map(function (d) {
3566
+ return d.url;
3567
+ }));
3568
+ document.dispatchEvent(new CustomEvent("idmission.preloadProgress.".concat(model), {
3569
+ detail: progressByUseCase[model]
3570
+ }));
3571
+ };
3561
3572
  document.addEventListener('idmission.preloadProgress', handleModelDownloadProgress);
3562
- _a.label = 3;
3563
- case 3:
3564
- _a.trys.push([3,, 5, 6]);
3565
- return [4 /*yield*/, Promise.all(dependencies.map(function (d) {
3573
+ _a.label = 4;
3574
+ case 4:
3575
+ _a.trys.push([4,, 6, 7]);
3576
+ return [4 /*yield*/, Promise.all(dependencies_1.map(function (d) {
3566
3577
  return preloadDependency(d.url, d.hash);
3567
3578
  }))];
3568
- case 4:
3569
- _a.sent();
3570
- return [3 /*break*/, 6];
3571
3579
  case 5:
3580
+ _a.sent();
3581
+ return [3 /*break*/, 7];
3582
+ case 6:
3572
3583
  document.removeEventListener('idmission.preloadProgress', handleModelDownloadProgress);
3584
+ return [7 /*endfinally*/];
3585
+ case 7:
3586
+ return [3 /*break*/, 9];
3587
+ case 8:
3588
+ // Always clear the gate — including when probe/guard throws before the
3589
+ // download phase — so concurrent callers polling on modelsPreloading
3590
+ // don't hang forever.
3573
3591
  modelsPreloading[model] = false;
3574
3592
  return [7 /*endfinally*/];
3575
- case 6:
3593
+ case 9:
3576
3594
  return [2 /*return*/];
3577
3595
  }
3578
3596
  });