|
@@ -1,9 +1,16 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div class="room">
|
|
<div class="room">
|
|
|
<topBar class="room-bar">
|
|
<topBar class="room-bar">
|
|
|
- <signal :signal-value="signalValue" />
|
|
|
|
|
- <battery :quantity="batteryValue" />
|
|
|
|
|
- <mic @callBack="sendAudio" />
|
|
|
|
|
|
|
+ <template
|
|
|
|
|
+ v-for="(item, index) in menuList"
|
|
|
|
|
+ :key="index"
|
|
|
|
|
+ >
|
|
|
|
|
+ <component
|
|
|
|
|
+ :is="item.component"
|
|
|
|
|
+ :value="item.value"
|
|
|
|
|
+ @callBack="item.callBack"
|
|
|
|
|
+ />
|
|
|
|
|
+ </template>
|
|
|
</topBar>
|
|
</topBar>
|
|
|
<video
|
|
<video
|
|
|
ref="remoteVideo"
|
|
ref="remoteVideo"
|
|
@@ -11,9 +18,9 @@
|
|
|
playsinline
|
|
playsinline
|
|
|
/>
|
|
/>
|
|
|
<div class="room-gauge">
|
|
<div class="room-gauge">
|
|
|
- <gauge
|
|
|
|
|
- :value="SpeedValue"
|
|
|
|
|
- :gears="conctrlNum % 2 ? '倒档' : '前进'"
|
|
|
|
|
|
|
+ <Gauge
|
|
|
|
|
+ :value="gauge.speed"
|
|
|
|
|
+ :gears="gauge.num % 2 ? '倒档' : '前进'"
|
|
|
/>
|
|
/>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -21,64 +28,55 @@
|
|
|
|
|
|
|
|
<script setup lang='ts'>
|
|
<script setup lang='ts'>
|
|
|
import {
|
|
import {
|
|
|
- ref, onMounted, inject, watch
|
|
|
|
|
|
|
+ ref, onMounted, inject, watch,
|
|
|
|
|
+ onUnmounted,
|
|
|
|
|
+ shallowRef,
|
|
|
|
|
+ defineAsyncComponent
|
|
|
} 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 battery from '@/components/battery.vue'
|
|
|
|
|
-import gauge from '@/components/gauge.vue'
|
|
|
|
|
-import mic from '@/components/mic.vue'
|
|
|
|
|
|
|
+import Gauge from '@/components/gauge.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(0)
|
|
|
|
|
-const batteryValue = ref(0)
|
|
|
|
|
-const SpeedValue = 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()
|
|
|
|
|
|
|
+const menuList = shallowRef([ { name: '信号', value: 0, component: defineAsyncComponent(() => import('@/components/signal.vue')) },
|
|
|
|
|
+ { name: '电量', value: 0, component: defineAsyncComponent(() => import('@/components/battery.vue')) },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: '录音',
|
|
|
|
|
+ value: 0,
|
|
|
|
|
+ callBack: (blob: Blob) => {
|
|
|
|
|
+ console.log('send audio', blob)
|
|
|
|
|
+ },
|
|
|
|
|
+ component: defineAsyncComponent(() => import('@/components/mic.vue'))
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: '静音', value: 0, callBack: (mute: boolean) => RTC.muteRemoteAudio(mute), component: defineAsyncComponent(() => import('@/components/audio.vue'))
|
|
|
|
|
+ } ])
|
|
|
|
|
+const gauge = ref({ speed: 0, num: 0 })
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * 发送语音
|
|
|
|
|
- * @param blob blob
|
|
|
|
|
- */
|
|
|
|
|
-function sendAudio(blob: Blob) {
|
|
|
|
|
- console.log('send audio', blob)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-onMounted(() => RTC.initRTC(remoteVideo.value, (event) => {
|
|
|
|
|
- const { type, data } = event
|
|
|
|
|
- if (type === 'connected') {
|
|
|
|
|
- store.setLoading(false)
|
|
|
|
|
- console.log('可以发送控制数据')
|
|
|
|
|
- }
|
|
|
|
|
- if (type === 'answer') {
|
|
|
|
|
- console.log('answer', data)
|
|
|
|
|
- mqtt.send(JSON.stringify(data))
|
|
|
|
|
- }
|
|
|
|
|
- if (store.errorDic[type]) mqtt.send(data)
|
|
|
|
|
-}))
|
|
|
|
|
|
|
+watch(() => store.mqtt_message, async (value: { type: string, data?: RTCSessionDescriptionInit }) => {
|
|
|
|
|
+ const { type, data } = value
|
|
|
|
|
+ console.log('二级监听', value)
|
|
|
|
|
|
|
|
-watch(() => store.mqtt_message, async (val: { type: string, data?: RTCSessionDescriptionInit }) => {
|
|
|
|
|
- // 接收offer
|
|
|
|
|
- if (val.type === 'offer') {
|
|
|
|
|
- console.log('offer', val)
|
|
|
|
|
- await RTC.Peer?.setRemoteDescription(val.data!)
|
|
|
|
|
|
|
+ // 接收远程offer
|
|
|
|
|
+ if (type === 'offer') {
|
|
|
|
|
+ console.log('offer', data)
|
|
|
|
|
+ await RTC.Peer?.setRemoteDescription(data!)
|
|
|
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('/')
|
|
|
|
|
|
|
+ // 发送本地answer
|
|
|
|
|
+ if (type === 'answer') {
|
|
|
|
|
+ console.log('send answer', data)
|
|
|
|
|
+ mqtt.send(JSON.stringify(data))
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+onMounted(() => RTC.initRTC(remoteVideo.value))
|
|
|
|
|
+onUnmounted(() => RTC.distory())
|
|
|
</script>
|
|
</script>
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
|
.room {
|
|
.room {
|