|
@@ -23,6 +23,7 @@
|
|
|
import {
|
|
import {
|
|
|
ref, onMounted, inject, watch
|
|
ref, onMounted, inject, watch
|
|
|
} from 'vue'
|
|
} from 'vue'
|
|
|
|
|
+import { useRouter } from 'vue-router'
|
|
|
import topBar from '@/components/topBar.vue'
|
|
import topBar from '@/components/topBar.vue'
|
|
|
import signal from '@/components/signal.vue'
|
|
import signal from '@/components/signal.vue'
|
|
|
import battery from '@/components/battery.vue'
|
|
import battery from '@/components/battery.vue'
|
|
@@ -31,36 +32,35 @@ import mic from '@/components/mic.vue'
|
|
|
import WebRtcService from '@/services/webrtc.service'
|
|
import WebRtcService from '@/services/webrtc.service'
|
|
|
import useStore from '@/store/index'
|
|
import useStore from '@/store/index'
|
|
|
|
|
|
|
|
-const signalValue = ref(5)
|
|
|
|
|
-const batteryValue = ref(50)
|
|
|
|
|
-const SpeedValue = ref(60)
|
|
|
|
|
|
|
+const signalValue = ref(0)
|
|
|
|
|
+const batteryValue = ref(0)
|
|
|
|
|
+const SpeedValue = ref(0)
|
|
|
const conctrlNum = ref(0)
|
|
const conctrlNum = ref(0)
|
|
|
const remoteVideo = ref(null as unknown as HTMLVideoElement)
|
|
const remoteVideo = ref(null as unknown as HTMLVideoElement)
|
|
|
const RTC = new WebRtcService()
|
|
const RTC = new WebRtcService()
|
|
|
const store = useStore()
|
|
const store = useStore()
|
|
|
const mqtt = inject('MQTT') as Any
|
|
const mqtt = inject('MQTT') as Any
|
|
|
|
|
+const router = useRouter()
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 发送语音
|
|
* 发送语音
|
|
|
* @param blob blob
|
|
* @param blob blob
|
|
|
*/
|
|
*/
|
|
|
-function sendAudio(blob:Blob) {
|
|
|
|
|
|
|
+function sendAudio(blob: Blob) {
|
|
|
console.log('send audio', blob)
|
|
console.log('send audio', blob)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => RTC.initRTC(remoteVideo.value, (event) => {
|
|
onMounted(() => RTC.initRTC(remoteVideo.value, (event) => {
|
|
|
const { type, data } = event
|
|
const { type, data } = event
|
|
|
if (type === 'connected') {
|
|
if (type === 'connected') {
|
|
|
|
|
+ store.setLoading(false)
|
|
|
console.log('可以发送控制数据')
|
|
console.log('可以发送控制数据')
|
|
|
}
|
|
}
|
|
|
if (type === 'answer') {
|
|
if (type === 'answer') {
|
|
|
console.log('answer', data)
|
|
console.log('answer', data)
|
|
|
mqtt.send(JSON.stringify(data))
|
|
mqtt.send(JSON.stringify(data))
|
|
|
}
|
|
}
|
|
|
- if (type === 'disconnected') {
|
|
|
|
|
- RTC.distory()
|
|
|
|
|
- store.setMqttMessage({ type: 'disconnect' })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (store.errorDic[type]) mqtt.send(data)
|
|
|
}))
|
|
}))
|
|
|
|
|
|
|
|
watch(() => store.mqtt_message, async (val: { type: string, data?: RTCSessionDescriptionInit }) => {
|
|
watch(() => store.mqtt_message, async (val: { type: string, data?: RTCSessionDescriptionInit }) => {
|
|
@@ -71,6 +71,12 @@ watch(() => store.mqtt_message, async (val: { type: string, data?: RTCSessionDes
|
|
|
const answerd = await RTC.Peer?.createAnswer()
|
|
const answerd = await RTC.Peer?.createAnswer()
|
|
|
await RTC.Peer?.setLocalDescription(answerd)
|
|
await RTC.Peer?.setLocalDescription(answerd)
|
|
|
}
|
|
}
|
|
|
|
|
+ // mqtt|webrtc ERROR
|
|
|
|
|
+ if (store.errorDic[val.type]) {
|
|
|
|
|
+ RTC.distory()
|
|
|
|
|
+ mqtt.disconnect()
|
|
|
|
|
+ router.push('/')
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
</script>
|
|
</script>
|