@authme/util 2.8.9 → 2.8.11

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 +58 -15
  2. package/index.js +58 -15
  3. package/package.json +1 -1
package/index.cjs CHANGED
@@ -1434,20 +1434,47 @@ function switchCamera(deviceId, video) {
1434
1434
  if (!constraint) {
1435
1435
  // 推測依然需要使用 width & height 的限制條件,
1436
1436
  // 否則即使是高解析度相機,也有可能拿到低解析度的圖片。(待驗證)
1437
- constraints.video.width = {
1438
- min: 1280,
1439
- ideal: 1920,
1440
- max: 1920
1441
- };
1442
- constraints.video.height = {
1443
- min: 720,
1444
- ideal: 1080,
1445
- max: 1080
1446
- };
1437
+ // 發現部分 camera 會無法套用這個設定導致不會有畫面出現
1438
+ // constraints.video.width = { min: 1280, ideal: 1920, max: 1920 };
1439
+ // constraints.video.height = { min: 720, ideal: 1080, max: 1080 };
1447
1440
  }
1448
1441
  stream = yield navigator.mediaDevices.getUserMedia(constraints);
1449
- video.srcObject = stream;
1450
- yield video.play();
1442
+ // try {
1443
+ // stream = await navigator.mediaDevices.getUserMedia(constraints);
1444
+ // console.log("獲取媒體流成功:", stream);
1445
+ // } catch (error) {
1446
+ // console.error("獲取媒體流失敗:", error);
1447
+ // }
1448
+ try {
1449
+ video.srcObject = stream;
1450
+ } catch (error) {
1451
+ // console.error("設置視訊流失敗:", error);
1452
+ throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
1453
+ }
1454
+ try {
1455
+ yield video.play();
1456
+ } catch (error) {
1457
+ // console.error("播放視訊失敗:", error);
1458
+ throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
1459
+ }
1460
+ // console.log('stream', stream.getVideoTracks()[0].getSettings());
1461
+ // console.log('constraints', navigator.mediaDevices.getSupportedConstraints());
1462
+ // const videoTracks = stream.getVideoTracks();
1463
+ // console.log("視訊軌道:", videoTracks.length, videoTracks);
1464
+ // const videoTrack = stream.getVideoTracks()[0];
1465
+ // if (videoTrack) {
1466
+ // console.log("視訊軌道啟用狀態:", videoTrack.enabled);
1467
+ // console.log("視訊軌道活躍狀態:", videoTrack.readyState);
1468
+ // console.log("視訊軌道設置:", videoTrack.getSettings());
1469
+ // console.log("視訊軌道約束:", videoTrack.getConstraints());
1470
+ // }
1471
+ stream.getTracks().forEach(track => {
1472
+ // track.onended = () => console.log("軌道結束:", track.kind);
1473
+ // track.onmute = () => console.log("軌道靜音:", track.kind);
1474
+ // track.onunmute = () => console.log("軌道取消靜音:", track.kind);
1475
+ });
1476
+ // const isStreamActive = stream.active;
1477
+ // console.log("流是否活躍:", isStreamActive);
1451
1478
  // Note: Fix Safari 15 video not showing bug
1452
1479
  video.srcObject = null;
1453
1480
  setTimeout(() => {
@@ -1471,6 +1498,11 @@ function _requestCamera(video, facingMode) {
1471
1498
  const media = yield navigator.mediaDevices.getUserMedia({
1472
1499
  video: true
1473
1500
  });
1501
+ const videoTrack = media.getVideoTracks()[0];
1502
+ // console.log('使用的攝影機:', videoTrack);
1503
+ // console.log('使用的攝影機:', videoTrack.label);
1504
+ const currentCamersDeviceId = videoTrack.id;
1505
+ // console.log('使用的攝影機:', currentCamersDeviceId);
1474
1506
  media.getTracks().forEach(function (track) {
1475
1507
  track.stop(); // 取得後會啟用攝影機,所以要關閉
1476
1508
  });
@@ -1529,7 +1561,18 @@ function _requestCamera(video, facingMode) {
1529
1561
  });
1530
1562
  const cameraIndex = window.localStorage.getItem('camera') || '0';
1531
1563
  const firstDevice = devices[parseInt(cameraIndex, 10)];
1532
- const deviceId = firstDevice.device.deviceId;
1564
+ let deviceId = firstDevice.device.deviceId;
1565
+ // 判斷是不是只有前鏡頭(電腦環境)
1566
+ let frontCameraCount = 0;
1567
+ devices.forEach(device => {
1568
+ if (device.meta.facingMode === 'front') {
1569
+ frontCameraCount++;
1570
+ }
1571
+ });
1572
+ if (frontCameraCount === devices.length) {
1573
+ deviceId = currentCamersDeviceId; // currentCamersDeviceId 是瀏覽器當前使用的攝影機
1574
+ }
1575
+
1533
1576
  if (!deviceId) {
1534
1577
  throw BROWSER_CAMERA_ERRORS.NO_CAMERA;
1535
1578
  }
@@ -3085,8 +3128,8 @@ const themeConfigDefault = {
3085
3128
  };
3086
3129
 
3087
3130
  var name = "authme/sdk";
3088
- var version$1 = "2.8.9";
3089
- var date = "2025-03-28T02:24:25+0000";
3131
+ var version$1 = "2.8.11";
3132
+ var date = "2025-04-10T03:53:45+0000";
3090
3133
  var packageInfo = {
3091
3134
  name: name,
3092
3135
  version: version$1,
package/index.js CHANGED
@@ -1424,20 +1424,47 @@ function switchCamera(deviceId, video) {
1424
1424
  if (!constraint) {
1425
1425
  // 推測依然需要使用 width & height 的限制條件,
1426
1426
  // 否則即使是高解析度相機,也有可能拿到低解析度的圖片。(待驗證)
1427
- constraints.video.width = {
1428
- min: 1280,
1429
- ideal: 1920,
1430
- max: 1920
1431
- };
1432
- constraints.video.height = {
1433
- min: 720,
1434
- ideal: 1080,
1435
- max: 1080
1436
- };
1427
+ // 發現部分 camera 會無法套用這個設定導致不會有畫面出現
1428
+ // constraints.video.width = { min: 1280, ideal: 1920, max: 1920 };
1429
+ // constraints.video.height = { min: 720, ideal: 1080, max: 1080 };
1437
1430
  }
1438
1431
  stream = yield navigator.mediaDevices.getUserMedia(constraints);
1439
- video.srcObject = stream;
1440
- yield video.play();
1432
+ // try {
1433
+ // stream = await navigator.mediaDevices.getUserMedia(constraints);
1434
+ // console.log("獲取媒體流成功:", stream);
1435
+ // } catch (error) {
1436
+ // console.error("獲取媒體流失敗:", error);
1437
+ // }
1438
+ try {
1439
+ video.srcObject = stream;
1440
+ } catch (error) {
1441
+ // console.error("設置視訊流失敗:", error);
1442
+ throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, error);
1443
+ }
1444
+ try {
1445
+ yield video.play();
1446
+ } catch (error) {
1447
+ // console.error("播放視訊失敗:", error);
1448
+ throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, error);
1449
+ }
1450
+ // console.log('stream', stream.getVideoTracks()[0].getSettings());
1451
+ // console.log('constraints', navigator.mediaDevices.getSupportedConstraints());
1452
+ // const videoTracks = stream.getVideoTracks();
1453
+ // console.log("視訊軌道:", videoTracks.length, videoTracks);
1454
+ // const videoTrack = stream.getVideoTracks()[0];
1455
+ // if (videoTrack) {
1456
+ // console.log("視訊軌道啟用狀態:", videoTrack.enabled);
1457
+ // console.log("視訊軌道活躍狀態:", videoTrack.readyState);
1458
+ // console.log("視訊軌道設置:", videoTrack.getSettings());
1459
+ // console.log("視訊軌道約束:", videoTrack.getConstraints());
1460
+ // }
1461
+ stream.getTracks().forEach(track => {
1462
+ // track.onended = () => console.log("軌道結束:", track.kind);
1463
+ // track.onmute = () => console.log("軌道靜音:", track.kind);
1464
+ // track.onunmute = () => console.log("軌道取消靜音:", track.kind);
1465
+ });
1466
+ // const isStreamActive = stream.active;
1467
+ // console.log("流是否活躍:", isStreamActive);
1441
1468
  // Note: Fix Safari 15 video not showing bug
1442
1469
  video.srcObject = null;
1443
1470
  setTimeout(() => {
@@ -1461,6 +1488,11 @@ function _requestCamera(video, facingMode) {
1461
1488
  const media = yield navigator.mediaDevices.getUserMedia({
1462
1489
  video: true
1463
1490
  });
1491
+ const videoTrack = media.getVideoTracks()[0];
1492
+ // console.log('使用的攝影機:', videoTrack);
1493
+ // console.log('使用的攝影機:', videoTrack.label);
1494
+ const currentCamersDeviceId = videoTrack.id;
1495
+ // console.log('使用的攝影機:', currentCamersDeviceId);
1464
1496
  media.getTracks().forEach(function (track) {
1465
1497
  track.stop(); // 取得後會啟用攝影機,所以要關閉
1466
1498
  });
@@ -1519,7 +1551,18 @@ function _requestCamera(video, facingMode) {
1519
1551
  });
1520
1552
  const cameraIndex = window.localStorage.getItem('camera') || '0';
1521
1553
  const firstDevice = devices[parseInt(cameraIndex, 10)];
1522
- const deviceId = firstDevice.device.deviceId;
1554
+ let deviceId = firstDevice.device.deviceId;
1555
+ // 判斷是不是只有前鏡頭(電腦環境)
1556
+ let frontCameraCount = 0;
1557
+ devices.forEach(device => {
1558
+ if (device.meta.facingMode === 'front') {
1559
+ frontCameraCount++;
1560
+ }
1561
+ });
1562
+ if (frontCameraCount === devices.length) {
1563
+ deviceId = currentCamersDeviceId; // currentCamersDeviceId 是瀏覽器當前使用的攝影機
1564
+ }
1565
+
1523
1566
  if (!deviceId) {
1524
1567
  throw BROWSER_CAMERA_ERRORS.NO_CAMERA;
1525
1568
  }
@@ -3075,8 +3118,8 @@ const themeConfigDefault = {
3075
3118
  };
3076
3119
 
3077
3120
  var name = "authme/sdk";
3078
- var version$1 = "2.8.9";
3079
- var date = "2025-03-28T02:24:25+0000";
3121
+ var version$1 = "2.8.11";
3122
+ var date = "2025-04-10T03:53:45+0000";
3080
3123
  var packageInfo = {
3081
3124
  name: name,
3082
3125
  version: version$1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authme/util",
3
- "version": "2.8.9",
3
+ "version": "2.8.11",
4
4
  "peerDependencies": {
5
5
  "core-js": "^3.6.0",
6
6
  "jwt-decode": "3.1.2",