|
@@ -7,6 +7,7 @@ import Login from '@/components/login.vue'
|
|
|
import Gauge from '@/components/gauge.vue'
|
|
import Gauge from '@/components/gauge.vue'
|
|
|
import Record from '@/components/record.vue'
|
|
import Record from '@/components/record.vue'
|
|
|
import Battery from '@/components/battery.vue'
|
|
import Battery from '@/components/battery.vue'
|
|
|
|
|
+import Loading from '@/components/loading.vue'
|
|
|
|
|
|
|
|
const sleep = (ms: number) => new Promise((res) => setTimeout(res, ms))
|
|
const sleep = (ms: number) => new Promise((res) => setTimeout(res, ms))
|
|
|
const socket = ref(null as null | Socket)
|
|
const socket = ref(null as null | Socket)
|
|
@@ -44,32 +45,32 @@ function sendAudio(blob: Blob) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 挡位
|
|
|
|
|
-function Gear(speed: number, num: number) {
|
|
|
|
|
- // 低速档
|
|
|
|
|
- if (speed === 1) {
|
|
|
|
|
- if (num < 116) {
|
|
|
|
|
- // 前
|
|
|
|
|
- num = 120
|
|
|
|
|
- } else if (num >= 120 && num <= 131) {
|
|
|
|
|
- num = 128
|
|
|
|
|
- } else if (num > 140) {
|
|
|
|
|
- // 后
|
|
|
|
|
- num = 140
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- // 高速档
|
|
|
|
|
- if (speed === 2) {
|
|
|
|
|
- if (num < 96) {
|
|
|
|
|
- num = 96
|
|
|
|
|
- } else if (num >= 120 && num <= 131) {
|
|
|
|
|
- num = 128
|
|
|
|
|
- } else if (num > 160) {
|
|
|
|
|
- num = 160
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return num
|
|
|
|
|
-}
|
|
|
|
|
|
|
+// // 挡位
|
|
|
|
|
+// function Gear(speed: number, num: number) {
|
|
|
|
|
+// // 低速档
|
|
|
|
|
+// if (speed === 1) {
|
|
|
|
|
+// if (num < 116) {
|
|
|
|
|
+// // 前
|
|
|
|
|
+// num = 120
|
|
|
|
|
+// } else if (num >= 120 && num <= 131) {
|
|
|
|
|
+// num = 128
|
|
|
|
|
+// } else if (num > 140) {
|
|
|
|
|
+// // 后
|
|
|
|
|
+// num = 140
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// // 高速档
|
|
|
|
|
+// if (speed === 2) {
|
|
|
|
|
+// if (num < 96) {
|
|
|
|
|
+// num = 96
|
|
|
|
|
+// } else if (num >= 120 && num <= 131) {
|
|
|
|
|
+// num = 128
|
|
|
|
|
+// } else if (num > 160) {
|
|
|
|
|
+// num = 160
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// return num
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
// 登录
|
|
// 登录
|
|
|
function login(data: { name: string, roomID: string }) {
|
|
function login(data: { name: string, roomID: string }) {
|
|
@@ -84,43 +85,43 @@ function login(data: { name: string, roomID: string }) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 手柄数据
|
|
|
|
|
-function ControlData() {
|
|
|
|
|
- const data = navigator.getGamepads()
|
|
|
|
|
- const db = data[0]
|
|
|
|
|
- if (!db) return
|
|
|
|
|
- // 挡位选择AB
|
|
|
|
|
- if (db.buttons[1].touched) speed.value = 2
|
|
|
|
|
- if (db.buttons[0].touched) speed.value = 1
|
|
|
|
|
- // 语音按键R2
|
|
|
|
|
- audioState.value = db.buttons[7].touched
|
|
|
|
|
- // 静音X3
|
|
|
|
|
- mutedState.value = db.buttons[3].touched
|
|
|
|
|
- // 播放警笛Y2
|
|
|
|
|
- warnAudio.value = db.buttons[2].touched
|
|
|
|
|
- // console.log(db.buttons);
|
|
|
|
|
- const params = {
|
|
|
|
|
- v0: Math.floor(db.axes[0] * 128 + 128),
|
|
|
|
|
- v1: Math.floor(db.axes[1] * 128 + 128),
|
|
|
|
|
- v2: Math.floor(db.axes[2] * 128 + 128),
|
|
|
|
|
- v3: Gear(speed.value, Math.floor(db.axes[3] * 128 + 128))
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// // 手柄数据
|
|
|
|
|
+// function ControlData() {
|
|
|
|
|
+// const data = navigator.getGamepads()
|
|
|
|
|
+// const db = data[0]
|
|
|
|
|
+// if (!db) return
|
|
|
|
|
+// // 挡位选择AB
|
|
|
|
|
+// if (db.buttons[1].touched) speed.value = 2
|
|
|
|
|
+// if (db.buttons[0].touched) speed.value = 1
|
|
|
|
|
+// // 语音按键R2
|
|
|
|
|
+// audioState.value = db.buttons[7].touched
|
|
|
|
|
+// // 静音X3
|
|
|
|
|
+// mutedState.value = db.buttons[3].touched
|
|
|
|
|
+// // 播放警笛Y2
|
|
|
|
|
+// warnAudio.value = db.buttons[2].touched
|
|
|
|
|
+// // console.log(db.buttons);
|
|
|
|
|
+// const params = {
|
|
|
|
|
+// v0: Math.floor(db.axes[0] * 128 + 128),
|
|
|
|
|
+// v1: Math.floor(db.axes[1] * 128 + 128),
|
|
|
|
|
+// v2: Math.floor(db.axes[2] * 128 + 128),
|
|
|
|
|
+// v3: Gear(speed.value, Math.floor(db.axes[3] * 128 + 128))
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
- if (socket.value && socket.value.connected) socket.value.emit('msg', { type: 'conctrl', conctrl: params })
|
|
|
|
|
- requestAnimationFrame(ControlData)
|
|
|
|
|
-}
|
|
|
|
|
|
|
+// if (socket.value && socket.value.connected) socket.value.emit('msg', { type: 'conctrl', conctrl: params })
|
|
|
|
|
+// requestAnimationFrame(ControlData)
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
-// 手柄连接
|
|
|
|
|
-function conControl() {
|
|
|
|
|
- contrlState.value = true
|
|
|
|
|
- ControlData()
|
|
|
|
|
-}
|
|
|
|
|
|
|
+// // 手柄连接
|
|
|
|
|
+// function conControl() {
|
|
|
|
|
+// contrlState.value = true
|
|
|
|
|
+// ControlData()
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
-// 手柄断开连接
|
|
|
|
|
-function disControl() {
|
|
|
|
|
- contrlState.value = false
|
|
|
|
|
- cancelAnimationFrame(ControlData as any)
|
|
|
|
|
-}
|
|
|
|
|
|
|
+// // 手柄断开连接
|
|
|
|
|
+// function disControl() {
|
|
|
|
|
+// contrlState.value = false
|
|
|
|
|
+// cancelAnimationFrame(ControlData as any)
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
// 关闭
|
|
// 关闭
|
|
|
function close(err?: string) {
|
|
function close(err?: string) {
|
|
@@ -133,10 +134,11 @@ function close(err?: string) {
|
|
|
socket.value = null
|
|
socket.value = null
|
|
|
Peer.value = null
|
|
Peer.value = null
|
|
|
num.value = 0
|
|
num.value = 0
|
|
|
- cancelAnimationFrame(ControlData as any)
|
|
|
|
|
- window.removeEventListener('gamepadconnected', conControl)
|
|
|
|
|
- window.removeEventListener('gamepaddisconnected', disControl)
|
|
|
|
|
|
|
+ // cancelAnimationFrame(ControlData as any)
|
|
|
|
|
+ // window.removeEventListener('gamepadconnected', conControl)
|
|
|
|
|
+ // window.removeEventListener('gamepaddisconnected', disControl)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 网络连接
|
|
* 网络连接
|
|
|
* @param host
|
|
* @param host
|
|
@@ -188,8 +190,11 @@ function intSoketRtc(host: string) {
|
|
|
// ICE连接成功|初始化摇杆
|
|
// ICE连接成功|初始化摇杆
|
|
|
if (state === 'connected') {
|
|
if (state === 'connected') {
|
|
|
// init Control
|
|
// init Control
|
|
|
- window.addEventListener('gamepadconnected', conControl)
|
|
|
|
|
- window.addEventListener('gamepaddisconnected', disControl)
|
|
|
|
|
|
|
+ // window.addEventListener('gamepadconnected', conControl)
|
|
|
|
|
+ // window.addEventListener('gamepaddisconnected', disControl)
|
|
|
|
|
+ window.$electron.onContrl((db:ArrayBuffer) => {
|
|
|
|
|
+ console.log('123', db)
|
|
|
|
|
+ })
|
|
|
await sleep(3000)
|
|
await sleep(3000)
|
|
|
showLoading.value = false
|
|
showLoading.value = false
|
|
|
}
|
|
}
|
|
@@ -220,17 +225,18 @@ function intSoketRtc(host: string) {
|
|
|
socket.value.on('connect_error', () => close('服务器连接失败'))
|
|
socket.value.on('connect_error', () => close('服务器连接失败'))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-watch(() => mutedState.value, (v) => {
|
|
|
|
|
- if (v) {
|
|
|
|
|
- const state = !!(num.value % 2)
|
|
|
|
|
- muted.value = state
|
|
|
|
|
- if (socket.value && socket.value.connected) socket.value.emit('msg', { type: 'contrlAudio', contrlAudio: state })
|
|
|
|
|
- num.value++
|
|
|
|
|
- }
|
|
|
|
|
-})
|
|
|
|
|
-watch(() => warnAudio.value, (v) => {
|
|
|
|
|
- if (v && socket.value && socket.value.connected) socket.value.emit('msg', { type: 'warnAudio', warnAudio: v })
|
|
|
|
|
-})
|
|
|
|
|
|
|
+// watch(() => mutedState.value, (v) => {
|
|
|
|
|
+// if (v) {
|
|
|
|
|
+// const state = !!(num.value % 2)
|
|
|
|
|
+// muted.value = state
|
|
|
|
|
+// if (socket.value && socket.value.connected) socket.value.emit('msg', { type: 'contrlAudio', contrlAudio: state })
|
|
|
|
|
+// num.value++
|
|
|
|
|
+// }
|
|
|
|
|
+// })
|
|
|
|
|
+// watch(() => warnAudio.value, (v) => {
|
|
|
|
|
+// if (v && socket.value && socket.value.connected) socket.value.emit('msg', { type: 'warnAudio', warnAudio: v })
|
|
|
|
|
+// })
|
|
|
|
|
+
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
intSoketRtc(HOST.value)
|
|
intSoketRtc(HOST.value)
|
|
|
})
|
|
})
|