Browse Source

优化相关BUG

Caner 3 years ago
parent
commit
6bfd89ea18
2 changed files with 23 additions and 19 deletions
  1. 1 1
      README.md
  2. 22 18
      src/App.vue

+ 1 - 1
README.md

@@ -6,7 +6,7 @@
 ```
 ```
 1. 房间ID与车端ID需一致
 1. 房间ID与车端ID需一致
 2. 可自行编译打包
 2. 可自行编译打包
-3. 可使用现控制端:car.caner.top
+3. 可使用现控制端:car.caner.top
 ```
 ```
 ## 编译
 ## 编译
 ```
 ```

+ 22 - 18
src/App.vue

@@ -6,11 +6,11 @@
         <!-- 信号 -->
         <!-- 信号 -->
         <Signal :signalValue="signalValue" />
         <Signal :signalValue="signalValue" />
         <!-- 手柄状态 -->
         <!-- 手柄状态 -->
-        <div class="contrl" :style="`color:${contrlState ? '#00CED1':'rgba(0, 0, 0, 0.3)'}`">&#xe72a;</div>
+        <div class="contrl" :style="`color:${contrlState ? '#00CED1' : 'rgba(0, 0, 0, 0.3)'}`">&#xe72a;</div>
         <!-- 音频 -->
         <!-- 音频 -->
         <Record class="audio" @callBack="sendAudio" :audioState="audioState" />
         <Record class="audio" @callBack="sendAudio" :audioState="audioState" />
         <!-- 喇叭 -->
         <!-- 喇叭 -->
-        <div class="arcode" :style="`color:${muted ? '#00CED1':'rgba(0, 0, 0, 0.3)'}`">&#xe600;</div>
+        <div class="arcode" :style="`color:${muted ? '#00CED1' : 'rgba(0, 0, 0, 0.3)'}`">&#xe600;</div>
         <!-- 电量 -->
         <!-- 电量 -->
         <Battery :quantity="60" />
         <Battery :quantity="60" />
       </div>
       </div>
@@ -129,26 +129,31 @@ export default {
       });
       });
 
 
       this.socket.on("msg", async (data) => {
       this.socket.on("msg", async (data) => {
-        if (data.type === "offer") {
-          console.log(data.sdp);
-          await this.Peer.setRemoteDescription(data);
-          const answer = await this.Peer.createAnswer();
-          await this.Peer.setLocalDescription(answer);
-        } else if (data.type === "power") {
-          console.log("电量", data);
-        } else if (data.type === "signal") {
-          const v = data.data <= 20 ? Math.floor(data.data / 4) : 5
-          this.signalValue = v || 1
-        } else if (data.type === 'speed') {
-          const v = Math.floor(data.data)
-          this.SpeedValue = v
+        const key = data.type
+        switch (key) {
+          case "offer":
+            await this.Peer.setRemoteDescription(data);
+            const answer = await this.Peer.createAnswer();
+            await this.Peer.setLocalDescription(answer);
+          case 'power':
+            console.log("电量", data);
+          case 'signal':
+            const s = data.data <= 20 ? Math.floor(data.data / 4) : 5
+            this.signalValue = s || 1
+          case 'speed':
+            const d = Math.floor(data.data)
+            this.SpeedValue = d
+          default:
+            break;
         }
         }
       });
       });
 
 
       this.socket.on("joined", async () =>
       this.socket.on("joined", async () =>
         this.socket.emit("msg", { type: "startRTC" })
         this.socket.emit("msg", { type: "startRTC" })
       );
       );
+
       this.socket.on("leaved", () => this.close("车端断开"));
       this.socket.on("leaved", () => this.close("车端断开"));
+      
       this.socket.on("connect_error", () => this.close('服务器连接失败'));
       this.socket.on("connect_error", () => this.close('服务器连接失败'));
     },
     },
 
 
@@ -273,13 +278,13 @@ export default {
       if (v && this.socket && this.socket.connected) this.socket.emit("msg", { type: "warnAudio", warnAudio: v });
       if (v && this.socket && this.socket.connected) this.socket.emit("msg", { type: "warnAudio", warnAudio: v });
     }
     }
   },
   },
-  beforeDestroy(){
+  beforeDestroy() {
     this.close()
     this.close()
   }
   }
 };
 };
 </script>
 </script>
 <style scoped>
 <style scoped>
-  #app {
+#app {
   font-family: "fonts";
   font-family: "fonts";
   font-style: normal;
   font-style: normal;
 }
 }
@@ -367,5 +372,4 @@ body {
   min-width: 1000px;
   min-width: 1000px;
   min-height: 900px;
   min-height: 900px;
 }
 }
-
 </style>
 </style>