Browse Source

优化rtc流程

Caner 2 years ago
parent
commit
9a1b5af942
1 changed files with 9 additions and 6 deletions
  1. 9 6
      src/App.vue

+ 9 - 6
src/App.vue

@@ -54,6 +54,7 @@ function close(err?: string) {
   audioStateNum.value = 0
   audioStateNum.value = 0
   quantity.value = 0
   quantity.value = 0
   cancelAnimationFrame(conctrlAnimation.value)
   cancelAnimationFrame(conctrlAnimation.value)
+  window.$electron.send('closeMqtt')
 }
 }
 
 
 // 初始化rtc
 // 初始化rtc
@@ -69,7 +70,8 @@ function initRTC() {
       console.log('GatheringState: ', Peer.value?.iceGatheringState)
       console.log('GatheringState: ', Peer.value?.iceGatheringState)
       if (Peer.value?.iceGatheringState === 'complete') {
       if (Peer.value?.iceGatheringState === 'complete') {
         const answer = Peer.value.localDescription
         const answer = Peer.value.localDescription
-        window.$electron.send('sendMqtt', answer)
+        console.log('send answer', answer)
+        window.$electron.send('sendMqtt', answer?.toJSON())
       }
       }
     }
     }
 
 
@@ -82,7 +84,7 @@ function initRTC() {
     // listen changestate·
     // listen changestate·
     Peer.value.oniceconnectionstatechange = async () => {
     Peer.value.oniceconnectionstatechange = async () => {
       const state = Peer.value?.iceConnectionState
       const state = Peer.value?.iceConnectionState
-      console.log('ICE状态', state)
+      console.log('StateChange', state)
       if (
       if (
         state === 'failed'
         state === 'failed'
         || state === 'disconnected'
         || state === 'disconnected'
@@ -131,7 +133,6 @@ function titleEvent(type: string) {
   if (type === 'maxWin') winMaxOrMin.value = !winMaxOrMin.value
   if (type === 'maxWin') winMaxOrMin.value = !winMaxOrMin.value
   if (type === 'loginOut') {
   if (type === 'loginOut') {
     close()
     close()
-    window.$electron.send('closeMqtt')
   } else {
   } else {
     window.$electron?.send(type, winMaxOrMin.value)
     window.$electron?.send(type, winMaxOrMin.value)
   }
   }
@@ -141,22 +142,24 @@ function titleEvent(type: string) {
 window.$electron.on('message', async (msg: any) => {
 window.$electron.on('message', async (msg: any) => {
   switch (msg.type) {
   switch (msg.type) {
     case 'connect':
     case 'connect':
-      console.log('连接成功')
+      console.log('mqtt connected start rtc')
       isLogin.value = true
       isLogin.value = true
       showLoading.value = true
       showLoading.value = true
+      initRTC()
       break
       break
     case 'disconnect':
     case 'disconnect':
       close('服务器连接失败')
       close('服务器连接失败')
       break
       break
     case 'join':
     case 'join':
+      console.log('join mqtt channel', msg)
       window.$electron.send('sendMqtt', { type: 'startRTC' })
       window.$electron.send('sendMqtt', { type: 'startRTC' })
-      initRTC()
       break
       break
     case 'leave':
     case 'leave':
       close('对方断开连接')
       close('对方断开连接')
       break
       break
     case 'offer':
     case 'offer':
       {
       {
+        console.log('get offer?', msg)
         await Peer.value?.setRemoteDescription(msg)
         await Peer.value?.setRemoteDescription(msg)
         const answerd = await Peer.value?.createAnswer()
         const answerd = await Peer.value?.createAnswer()
         await Peer.value?.setLocalDescription(answerd)
         await Peer.value?.setLocalDescription(answerd)
@@ -164,7 +167,7 @@ window.$electron.on('message', async (msg: any) => {
       break
       break
     case 'power':
     case 'power':
       quantity.value = msg.power
       quantity.value = msg.power
-      console.log('电量')
+      console.log('电量', msg.power)
       break
       break
     case 'speed':
     case 'speed':
       SpeedValue.value = Math.floor(msg.data)
       SpeedValue.value = Math.floor(msg.data)