瀏覽代碼

摄像头被禁用,退出登录

Michael Wang 6 年之前
父節點
當前提交
87add46511
共有 1 個文件被更改,包括 7 次插入4 次删除
  1. 7 4
      src/components/FaceRecognition/FaceRecognition.vue

+ 7 - 4
src/components/FaceRecognition/FaceRecognition.vue

@@ -77,9 +77,12 @@ export default {
               // height: this.showRecognizeButton ? 300 : 250
             }
           });
-
-          video.srcObject = stream;
-          video.play();
+          if (stream) {
+            video.srcObject = stream;
+            video.play();
+          } else {
+            this.$Message.error("没有可用的视频流");
+          }
         } catch (error) {
           console.log(error);
           this.$Message.error("无法启用摄像头");
@@ -149,7 +152,7 @@ export default {
     async getSnapShot() {
       return new Promise((resolve, reject) => {
         const video = this.$refs.video;
-        if (video.readyState !== 4) {
+        if (video.readyState !== 4 && video.srcObject.active) {
           this.$Message.error({ content: "摄像头没有正常启用", duration: 5 });
           reject("摄像头没有正常启用");
           this.logout();