drew 6 년 전
부모
커밋
f57af893ec
1개의 변경된 파일52개의 추가작업 그리고 31개의 파일을 삭제
  1. 52 31
      html/SimpleThreeJsExample/asset/js/webar.js

+ 52 - 31
html/SimpleThreeJsExample/asset/js/webar.js

@@ -29,41 +29,62 @@ class WebAR {
             navigator.mediaDevices
                 .enumerateDevices()
                 .then(devices => {
-                    let index = 0;
-                    devices.find(device => {
+                    // let index = 0;
+                    // devices.find(device => {
+                    //     if (device.kind === "videoinput") {
+                    //         const option = document.createElement("option");
+                    //         console.log(device);
+                    //         // 在iOS12.2上deviceId为空
+                    //         if (device.deviceId == "") {
+                    //             option.text =
+                    //                 device.label ||
+                    //                 "camera " + this.cameras[index];
+                    //             option.value = JSON.stringify({
+                    //                 audio: false,
+                    //                 video: {
+                    //                     facingMode: {
+                    //                         exact: this.cameras[index]
+                    //                     }
+                    //                 }
+                    //             });
+                    //             index++;
+                    //         } else {
+                    //             option.text =
+                    //                 device.label ||
+                    //                 "camera " +
+                    //                     (videoDevice.length + 1).toString();
+                    //             option.value = JSON.stringify({
+                    //                 audio: false,
+                    //                 video: {
+                    //                     deviceId: { exact: device.deviceId }
+                    //                 }
+                    //             });
+                    //         }
+                    //         // 将摄像头信息存储在select元素中,方便切换前、后置摄像头
+                    //         videoDevice.appendChild(option);
+                    //     }
+                    //     return false;
+                    // });
+                    devices.forEach(function(device) {
                         if (device.kind === "videoinput") {
+                            console.log(
+                                device.kind +
+                                    ": " +
+                                    device.label +
+                                    " id = " +
+                                    device.deviceId
+                            );
+
                             const option = document.createElement("option");
-                            console.log(device);
-                            // 在iOS12.2上deviceId为空
-                            if (device.deviceId == "") {
-                                option.text =
-                                    device.label ||
-                                    "camera " + this.cameras[index];
-                                option.value = JSON.stringify({
-                                    audio: false,
-                                    video: {
-                                        facingMode: {
-                                            exact: this.cameras[index]
-                                        }
-                                    }
-                                });
-                                index++;
-                            } else {
-                                option.text =
-                                    device.label ||
-                                    "camera " +
-                                        (videoDevice.length + 1).toString();
-                                option.value = JSON.stringify({
-                                    audio: false,
-                                    video: {
-                                        deviceId: { exact: device.deviceId }
-                                    }
-                                });
-                            }
-                            // 将摄像头信息存储在select元素中,方便切换前、后置摄像头
+                            option.text = device.label;
+                            option.value = JSON.stringify({
+                                audio: false,
+                                video: {
+                                    deviceId: { exact: device.deviceId }
+                                }
+                            });
                             videoDevice.appendChild(option);
                         }
-                        return false;
                     });
                     if (videoDevice.length === 0) {
                         reject("没有可使用的视频设备");