@authme/util 2.8.30 → 2.8.31

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 (3) hide show
  1. package/index.cjs +47 -13
  2. package/index.js +47 -13
  3. package/package.json +1 -1
package/index.cjs CHANGED
@@ -1460,6 +1460,7 @@ function waitForCameraReady(videoTrack, maxWaitMs = 100) {
1460
1460
  return __awaiter(this, void 0, void 0, function* () {
1461
1461
  const startTime = Date.now();
1462
1462
  const checkInterval = 50; // 每50ms檢查一次
1463
+ const minStableTime = 50; // 最小穩定時間:即使檢測到就緒,也要等待一小段時間
1463
1464
  while (Date.now() - startTime < maxWaitMs) {
1464
1465
  const _settings = videoTrack.getSettings();
1465
1466
  const capabilities = (_a = videoTrack.getCapabilities) === null || _a === void 0 ? void 0 : _a.call(videoTrack);
@@ -1470,7 +1471,14 @@ function waitForCameraReady(videoTrack, maxWaitMs = 100) {
1470
1471
  const hasCapabilities = !capabilities || ((_b = capabilities === null || capabilities === void 0 ? void 0 : capabilities.width) === null || _b === void 0 ? void 0 : _b.max) && ((_c = capabilities === null || capabilities === void 0 ? void 0 : capabilities.height) === null || _c === void 0 ? void 0 : _c.max);
1471
1472
  if (hasBasicSettings && hasCapabilities) {
1472
1473
  const elapsedTime = Date.now() - startTime;
1473
- console.log(`✅ Camera就緒 (耗時: ${elapsedTime}ms, 解析度: ${_settings.width}x${_settings.height})`);
1474
+ // ⚠️ 關鍵修正:即使檢測到就緒,也要確保經過最小等待時間
1475
+ // 這對外接相機特別重要,它們需要額外的硬體初始化時間
1476
+ if (elapsedTime < minStableTime) {
1477
+ const remainingTime = minStableTime - elapsedTime;
1478
+ console.log(`⏳ Camera基本就緒,額外等待 ${remainingTime}ms 確保穩定 (當前: ${_settings.width}x${_settings.height})`);
1479
+ yield new Promise(resolve => setTimeout(resolve, remainingTime));
1480
+ }
1481
+ console.log(`✅ Camera就緒 (耗時: ${Date.now() - startTime}ms, 解析度: ${_settings.width}x${_settings.height})`);
1474
1482
  return true;
1475
1483
  }
1476
1484
  yield new Promise(resolve => setTimeout(resolve, checkInterval));
@@ -1538,7 +1546,7 @@ function arrayFromAsync(asyncIterable) {
1538
1546
  });
1539
1547
  }
1540
1548
  function switchCamera(deviceId, video) {
1541
- var _a, _b;
1549
+ var _a, _b, _c, _d;
1542
1550
  return __awaiter(this, void 0, void 0, function* () {
1543
1551
  const startTime = performance.now();
1544
1552
  try {
@@ -1561,7 +1569,7 @@ function switchCamera(deviceId, video) {
1561
1569
  // 🆕 策略 1: 等待camera完全就緒(特別針對外接camera)
1562
1570
  const isReady = yield waitForCameraReady(videoTrack, 2000);
1563
1571
  if (isReady) {
1564
- // 🆕 策略 2: 漸進式重試邏輯
1572
+ // 🆕 策略 2: 漸進式重試邏輯 + 解析度驗證
1565
1573
  const targetConstraints = {
1566
1574
  width: {
1567
1575
  ideal: 1920,
@@ -1574,25 +1582,51 @@ function switchCamera(deviceId, video) {
1574
1582
  };
1575
1583
  const maxRetries = 3;
1576
1584
  const delays = [0, 100, 300]; // 第一次立即嘗試,後續間隔遞增
1585
+ const minAcceptableWidth = 1280; // 最低可接受的解析度寬度
1577
1586
  for (let attempt = 0; attempt < maxRetries; attempt++) {
1578
1587
  try {
1579
1588
  if (delays[attempt] > 0) {
1580
1589
  yield new Promise(resolve => setTimeout(resolve, delays[attempt]));
1581
1590
  }
1591
+ const beforeSettings = videoTrack.getSettings();
1582
1592
  yield videoTrack.applyConstraints(targetConstraints);
1583
- const settings = videoTrack.getSettings();
1584
- console.log(`✅ 解析度提升成功 (嘗試 ${attempt + 1}/${maxRetries})`, {
1585
- resolution: `${settings.width}x${settings.height}`,
1586
- deviceLabel: videoTrack.label
1587
- });
1588
- break; // 成功後跳出
1593
+ // ⚠️ 關鍵:驗證解析度是否真的改變
1594
+ const afterSettings = videoTrack.getSettings();
1595
+ const afterWidth = (_a = afterSettings.width) !== null && _a !== void 0 ? _a : 0;
1596
+ const beforeWidth = (_b = beforeSettings.width) !== null && _b !== void 0 ? _b : 0;
1597
+ // 成功條件:
1598
+ // 1. 如果初始解析度 < 最低標準 → 必須提升且達到最低標準
1599
+ // 2. 如果初始解析度 >= 最低標準 → 只要有提升就算成功
1600
+ const needsImprovement = beforeWidth < minAcceptableWidth;
1601
+ const resolutionImproved = needsImprovement ? afterWidth > beforeWidth && afterWidth >= minAcceptableWidth : afterWidth > beforeWidth;
1602
+ if (resolutionImproved) {
1603
+ console.log(`✅ 解析度提升成功 (嘗試 ${attempt + 1}/${maxRetries})`, {
1604
+ before: `${beforeWidth}x${beforeSettings.height}`,
1605
+ after: `${afterWidth}x${afterSettings.height}`,
1606
+ deviceLabel: videoTrack.label
1607
+ });
1608
+ break; // 真正成功才跳出
1609
+ } else {
1610
+ // applyConstraints 沒報錯,但解析度沒變 → 視為失敗,觸發重試
1611
+ console.warn(`⚠️ 解析度未改善 (嘗試 ${attempt + 1}/${maxRetries})`, {
1612
+ before: `${beforeWidth}x${beforeSettings.height}`,
1613
+ after: `${afterWidth}x${afterSettings.height}`,
1614
+ expected: needsImprovement ? `>= ${minAcceptableWidth}` : '任何提升'
1615
+ });
1616
+ if (attempt === maxRetries - 1) {
1617
+ console.warn(`⚠️ 達到最大重試次數,使用當前解析度 (${afterWidth}x${afterSettings.height})`);
1618
+ } else {
1619
+ // 繼續重試
1620
+ continue;
1621
+ }
1622
+ }
1589
1623
  } catch (error) {
1590
1624
  if (attempt === maxRetries - 1) {
1591
1625
  // 最後一次嘗試失敗,記錄警告但不影響功能
1592
1626
  const settings = videoTrack.getSettings();
1593
1627
  console.warn(`⚠️ 無法提升解析度,使用基本設定 (${settings.width}x${settings.height})`, error);
1594
1628
  } else {
1595
- console.log(`⏳ 解析度提升嘗試 ${attempt + 1} 失敗,準備重試...`);
1629
+ console.log(`⏳ 解析度提升嘗試 ${attempt + 1} 失敗,準備重試...`, error);
1596
1630
  }
1597
1631
  }
1598
1632
  }
@@ -1679,7 +1713,7 @@ function switchCamera(deviceId, video) {
1679
1713
  errorMessage: e === null || e === void 0 ? void 0 : e.message,
1680
1714
  initTime: `${initTime}ms`,
1681
1715
  streamExists: !!stream,
1682
- trackCount: (_b = (_a = stream === null || stream === void 0 ? void 0 : stream.getTracks()) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0
1716
+ trackCount: (_d = (_c = stream === null || stream === void 0 ? void 0 : stream.getTracks()) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0
1683
1717
  });
1684
1718
  throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, e);
1685
1719
  }
@@ -3363,8 +3397,8 @@ const themeConfigDefault = {
3363
3397
  };
3364
3398
 
3365
3399
  var name = "authme/sdk";
3366
- var version$1 = "2.8.30";
3367
- var date = "2025-10-30T10:27:17+0000";
3400
+ var version$1 = "2.8.31";
3401
+ var date = "2025-11-05T04:02:33+0000";
3368
3402
  var packageInfo = {
3369
3403
  name: name,
3370
3404
  version: version$1,
package/index.js CHANGED
@@ -1450,6 +1450,7 @@ function waitForCameraReady(videoTrack, maxWaitMs = 100) {
1450
1450
  return __awaiter(this, void 0, void 0, function* () {
1451
1451
  const startTime = Date.now();
1452
1452
  const checkInterval = 50; // 每50ms檢查一次
1453
+ const minStableTime = 50; // 最小穩定時間:即使檢測到就緒,也要等待一小段時間
1453
1454
  while (Date.now() - startTime < maxWaitMs) {
1454
1455
  const _settings = videoTrack.getSettings();
1455
1456
  const capabilities = (_a = videoTrack.getCapabilities) === null || _a === void 0 ? void 0 : _a.call(videoTrack);
@@ -1460,7 +1461,14 @@ function waitForCameraReady(videoTrack, maxWaitMs = 100) {
1460
1461
  const hasCapabilities = !capabilities || ((_b = capabilities === null || capabilities === void 0 ? void 0 : capabilities.width) === null || _b === void 0 ? void 0 : _b.max) && ((_c = capabilities === null || capabilities === void 0 ? void 0 : capabilities.height) === null || _c === void 0 ? void 0 : _c.max);
1461
1462
  if (hasBasicSettings && hasCapabilities) {
1462
1463
  const elapsedTime = Date.now() - startTime;
1463
- console.log(`✅ Camera就緒 (耗時: ${elapsedTime}ms, 解析度: ${_settings.width}x${_settings.height})`);
1464
+ // ⚠️ 關鍵修正:即使檢測到就緒,也要確保經過最小等待時間
1465
+ // 這對外接相機特別重要,它們需要額外的硬體初始化時間
1466
+ if (elapsedTime < minStableTime) {
1467
+ const remainingTime = minStableTime - elapsedTime;
1468
+ console.log(`⏳ Camera基本就緒,額外等待 ${remainingTime}ms 確保穩定 (當前: ${_settings.width}x${_settings.height})`);
1469
+ yield new Promise(resolve => setTimeout(resolve, remainingTime));
1470
+ }
1471
+ console.log(`✅ Camera就緒 (耗時: ${Date.now() - startTime}ms, 解析度: ${_settings.width}x${_settings.height})`);
1464
1472
  return true;
1465
1473
  }
1466
1474
  yield new Promise(resolve => setTimeout(resolve, checkInterval));
@@ -1528,7 +1536,7 @@ function arrayFromAsync(asyncIterable) {
1528
1536
  });
1529
1537
  }
1530
1538
  function switchCamera(deviceId, video) {
1531
- var _a, _b;
1539
+ var _a, _b, _c, _d;
1532
1540
  return __awaiter(this, void 0, void 0, function* () {
1533
1541
  const startTime = performance.now();
1534
1542
  try {
@@ -1551,7 +1559,7 @@ function switchCamera(deviceId, video) {
1551
1559
  // 🆕 策略 1: 等待camera完全就緒(特別針對外接camera)
1552
1560
  const isReady = yield waitForCameraReady(videoTrack, 2000);
1553
1561
  if (isReady) {
1554
- // 🆕 策略 2: 漸進式重試邏輯
1562
+ // 🆕 策略 2: 漸進式重試邏輯 + 解析度驗證
1555
1563
  const targetConstraints = {
1556
1564
  width: {
1557
1565
  ideal: 1920,
@@ -1564,25 +1572,51 @@ function switchCamera(deviceId, video) {
1564
1572
  };
1565
1573
  const maxRetries = 3;
1566
1574
  const delays = [0, 100, 300]; // 第一次立即嘗試,後續間隔遞增
1575
+ const minAcceptableWidth = 1280; // 最低可接受的解析度寬度
1567
1576
  for (let attempt = 0; attempt < maxRetries; attempt++) {
1568
1577
  try {
1569
1578
  if (delays[attempt] > 0) {
1570
1579
  yield new Promise(resolve => setTimeout(resolve, delays[attempt]));
1571
1580
  }
1581
+ const beforeSettings = videoTrack.getSettings();
1572
1582
  yield videoTrack.applyConstraints(targetConstraints);
1573
- const settings = videoTrack.getSettings();
1574
- console.log(`✅ 解析度提升成功 (嘗試 ${attempt + 1}/${maxRetries})`, {
1575
- resolution: `${settings.width}x${settings.height}`,
1576
- deviceLabel: videoTrack.label
1577
- });
1578
- break; // 成功後跳出
1583
+ // ⚠️ 關鍵:驗證解析度是否真的改變
1584
+ const afterSettings = videoTrack.getSettings();
1585
+ const afterWidth = (_a = afterSettings.width) !== null && _a !== void 0 ? _a : 0;
1586
+ const beforeWidth = (_b = beforeSettings.width) !== null && _b !== void 0 ? _b : 0;
1587
+ // 成功條件:
1588
+ // 1. 如果初始解析度 < 最低標準 → 必須提升且達到最低標準
1589
+ // 2. 如果初始解析度 >= 最低標準 → 只要有提升就算成功
1590
+ const needsImprovement = beforeWidth < minAcceptableWidth;
1591
+ const resolutionImproved = needsImprovement ? afterWidth > beforeWidth && afterWidth >= minAcceptableWidth : afterWidth > beforeWidth;
1592
+ if (resolutionImproved) {
1593
+ console.log(`✅ 解析度提升成功 (嘗試 ${attempt + 1}/${maxRetries})`, {
1594
+ before: `${beforeWidth}x${beforeSettings.height}`,
1595
+ after: `${afterWidth}x${afterSettings.height}`,
1596
+ deviceLabel: videoTrack.label
1597
+ });
1598
+ break; // 真正成功才跳出
1599
+ } else {
1600
+ // applyConstraints 沒報錯,但解析度沒變 → 視為失敗,觸發重試
1601
+ console.warn(`⚠️ 解析度未改善 (嘗試 ${attempt + 1}/${maxRetries})`, {
1602
+ before: `${beforeWidth}x${beforeSettings.height}`,
1603
+ after: `${afterWidth}x${afterSettings.height}`,
1604
+ expected: needsImprovement ? `>= ${minAcceptableWidth}` : '任何提升'
1605
+ });
1606
+ if (attempt === maxRetries - 1) {
1607
+ console.warn(`⚠️ 達到最大重試次數,使用當前解析度 (${afterWidth}x${afterSettings.height})`);
1608
+ } else {
1609
+ // 繼續重試
1610
+ continue;
1611
+ }
1612
+ }
1579
1613
  } catch (error) {
1580
1614
  if (attempt === maxRetries - 1) {
1581
1615
  // 最後一次嘗試失敗,記錄警告但不影響功能
1582
1616
  const settings = videoTrack.getSettings();
1583
1617
  console.warn(`⚠️ 無法提升解析度,使用基本設定 (${settings.width}x${settings.height})`, error);
1584
1618
  } else {
1585
- console.log(`⏳ 解析度提升嘗試 ${attempt + 1} 失敗,準備重試...`);
1619
+ console.log(`⏳ 解析度提升嘗試 ${attempt + 1} 失敗,準備重試...`, error);
1586
1620
  }
1587
1621
  }
1588
1622
  }
@@ -1669,7 +1703,7 @@ function switchCamera(deviceId, video) {
1669
1703
  errorMessage: e === null || e === void 0 ? void 0 : e.message,
1670
1704
  initTime: `${initTime}ms`,
1671
1705
  streamExists: !!stream,
1672
- trackCount: (_b = (_a = stream === null || stream === void 0 ? void 0 : stream.getTracks()) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0
1706
+ trackCount: (_d = (_c = stream === null || stream === void 0 ? void 0 : stream.getTracks()) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0
1673
1707
  });
1674
1708
  throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, e);
1675
1709
  }
@@ -3353,8 +3387,8 @@ const themeConfigDefault = {
3353
3387
  };
3354
3388
 
3355
3389
  var name = "authme/sdk";
3356
- var version$1 = "2.8.30";
3357
- var date = "2025-10-30T10:27:17+0000";
3390
+ var version$1 = "2.8.31";
3391
+ var date = "2025-11-05T04:02:33+0000";
3358
3392
  var packageInfo = {
3359
3393
  name: name,
3360
3394
  version: version$1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authme/util",
3
- "version": "2.8.30",
3
+ "version": "2.8.31",
4
4
  "peerDependencies": {
5
5
  "core-js": "^3.6.0",
6
6
  "file-saver": "2.0.5",