|
|
@@ -7,7 +7,6 @@
|
|
|
>
|
|
|
<component
|
|
|
:is="item.component"
|
|
|
- :value="item.value"
|
|
|
@callBack="item.callBack"
|
|
|
/>
|
|
|
</template>
|
|
|
@@ -28,25 +27,29 @@
|
|
|
|
|
|
<script setup lang='ts'>
|
|
|
import {
|
|
|
- ref, onMounted, inject, watch,
|
|
|
+ ref, onMounted, inject,
|
|
|
onUnmounted,
|
|
|
shallowRef,
|
|
|
defineAsyncComponent
|
|
|
} from 'vue'
|
|
|
-import WebRtcService from '@/services/webrtc.service'
|
|
|
import topBar from '@/components/topBar.vue'
|
|
|
import Gauge from './component/gauge.vue'
|
|
|
-import useStore from '@/store/index'
|
|
|
|
|
|
-const RTC = new WebRtcService()
|
|
|
-const store = useStore()
|
|
|
-const mqtt = inject('MQTT') as Any
|
|
|
+const RTC = inject('RTC') as Any
|
|
|
const remoteVideo = ref(null as unknown as HTMLVideoElement)
|
|
|
const gauge = ref({ speed: 0, num: 0 })
|
|
|
const menuList = shallowRef([
|
|
|
- { name: '信号', value: 0, component: defineAsyncComponent(() => import('./component/signal.vue')) },
|
|
|
- { name: '电量', value: 0, component: defineAsyncComponent(() => import('./component/battery.vue')) },
|
|
|
- { name: '方向盘', vlaue: 0, component: defineAsyncComponent(() => import('./component/steering.vue')) },
|
|
|
+ { name: '信号', component: defineAsyncComponent(() => import('./component/signal.vue')) },
|
|
|
+ { name: '电量', component: defineAsyncComponent(() => import('./component/battery.vue')) },
|
|
|
+ {
|
|
|
+ name: '方向盘',
|
|
|
+ component: defineAsyncComponent(() => import('./component/steering.vue')),
|
|
|
+ callBack: (data: { leftPaddle: boolean; rightPaddle: boolean }) => {
|
|
|
+ console.log('方向盘返回的数据', data)
|
|
|
+ if (data.leftPaddle) gauge.value.num--
|
|
|
+ if (data.rightPaddle) gauge.value.num++
|
|
|
+ }
|
|
|
+ },
|
|
|
{
|
|
|
name: '静音',
|
|
|
component: defineAsyncComponent(() => import('./component/audio.vue')),
|
|
|
@@ -59,45 +62,9 @@ const menuList = shallowRef([
|
|
|
console.log('发送对讲', blob)
|
|
|
}
|
|
|
},
|
|
|
- { name: '网速', vlaue: 0, component: defineAsyncComponent(() => import('./component/stats.vue')) }
|
|
|
+ { name: '网速', component: defineAsyncComponent(() => import('./component/stats.vue')) }
|
|
|
])
|
|
|
|
|
|
-watch(() => store.mqtt_message, async (value: { type: string, data?: RTCSessionDescriptionInit }) => {
|
|
|
- const { type, data } = value
|
|
|
- // 接收远程offer
|
|
|
- if (type === 'offer') {
|
|
|
- await RTC.Peer?.setRemoteDescription(data!)
|
|
|
- const answerd = await RTC.Peer?.createAnswer()
|
|
|
- await RTC.Peer?.setLocalDescription(answerd)
|
|
|
- }
|
|
|
- // 发送本地answer
|
|
|
- if (type === 'answer') mqtt.send(value)
|
|
|
- // 控制数据
|
|
|
- if (type === 'control') {
|
|
|
- menuList.value[2].vlaue = data ? 1 : 0
|
|
|
- const obj = {
|
|
|
- type: 'control',
|
|
|
- data: {
|
|
|
- steering: 0, // 方向 -1-1
|
|
|
- throttle: 0, // 油门 0-1
|
|
|
- brake: 0, // 刹车 0-1
|
|
|
- clutch: 0, // 离合 0-1
|
|
|
- leftPaddle: false, // 左拨挡
|
|
|
- rightPaddle: false, // 右拨挡
|
|
|
- buttonR3: false, // R3
|
|
|
- buttonL3: false, // L3
|
|
|
- enterKey: false, // 回车键
|
|
|
- ...data
|
|
|
- }
|
|
|
- }
|
|
|
- if (obj.data.leftPaddle) gauge.value.num--
|
|
|
- if (obj.data.rightPaddle) gauge.value.num++
|
|
|
- if (store.rtcConnected) mqtt.send(obj)
|
|
|
- }
|
|
|
- // 网络状态
|
|
|
- if (type === 'WebRtcStats') menuList.value[5].vlaue = data.bitrate || 0
|
|
|
-})
|
|
|
-
|
|
|
onMounted(() => RTC.initRTC(remoteVideo.value))
|
|
|
onUnmounted(() => RTC.distory())
|
|
|
</script>
|