去掉不必要的配置
This commit is contained in:
parent
1bb1e72f66
commit
fe9229f044
99
src/App.vue
99
src/App.vue
@ -3,8 +3,13 @@
|
|||||||
<!-- 顶部导航 -->
|
<!-- 顶部导航 -->
|
||||||
<header class="nav-bar">
|
<header class="nav-bar">
|
||||||
<span class="nav-title">Real-time Monitoring</span>
|
<span class="nav-title">Real-time Monitoring</span>
|
||||||
|
<select v-model="selectedDeviceId" class="device-select" @change="onDeviceChange">
|
||||||
|
<option v-for="device in deviceList" :key="device.DeviceId" :value="device.DeviceId">
|
||||||
|
{{ device.DeviceName }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
<!-- <button class="layout-btn" @click="toggleLayout">
|
<!-- <button class="layout-btn" @click="toggleLayout">
|
||||||
{{ layout === 1 ? '⊞ 四画面' : '⊡ 单画面' }}
|
{{ layout === 1 ? '⊞ Quad View' : '⊡ Single View' }}
|
||||||
</button> -->
|
</button> -->
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@ -15,8 +20,6 @@
|
|||||||
:key="i - 1"
|
:key="i - 1"
|
||||||
:ref="(el) => setBoxRef(el, i - 1)"
|
:ref="(el) => setBoxRef(el, i - 1)"
|
||||||
:source="playingSources[i - 1] ? sourcesMap[playingSources[i - 1]!] : null"
|
:source="playingSources[i - 1] ? sourcesMap[playingSources[i - 1]!] : null"
|
||||||
:server-ip="config.serverIp"
|
|
||||||
:media-port="config.media_http_api"
|
|
||||||
@close="closeVideo(i - 1)"
|
@close="closeVideo(i - 1)"
|
||||||
@ready="onVideoReady($event, i - 1)"
|
@ready="onVideoReady($event, i - 1)"
|
||||||
/>
|
/>
|
||||||
@ -51,26 +54,33 @@
|
|||||||
import { ref, reactive, onMounted, onBeforeUnmount } from 'vue'
|
import { ref, reactive, onMounted, onBeforeUnmount } from 'vue'
|
||||||
import VideoBox from './components/VideoBox.vue'
|
import VideoBox from './components/VideoBox.vue'
|
||||||
import { createApis } from './api'
|
import { createApis } from './api'
|
||||||
import type { GlobalConfig, SourceItem, VideoInfo } from './types'
|
import type { GlobalConfig, SourceItem, VideoInfo, DeviceItem } from './types'
|
||||||
|
|
||||||
declare const mqtt: any
|
declare const mqtt: any
|
||||||
|
|
||||||
const deviceId = 'fcfabf1d5dd036033419057075a56304' // 设备 ID,实际使用中可动态获取
|
const deviceId = 'fcfabf1d5dd036033419057075a56304' // 设备 ID,实际使用中可动态获取
|
||||||
|
const selectedDeviceId = ref<string>('')
|
||||||
|
const deviceList = ref<DeviceItem[]>([])
|
||||||
|
|
||||||
|
// const config = reactive<GlobalConfig>({
|
||||||
|
// serverIp: '118.145.200.78',
|
||||||
|
// getSources: ':3000/ks/source',
|
||||||
|
// subscribe: ':3000/stream/live/subscribe',
|
||||||
|
// resultTopic: 'ks/video_detection',
|
||||||
|
// streamInfoTopic: 'ks/stream_local',
|
||||||
|
// media_http_api: 3001,
|
||||||
|
// websocket: 8083,
|
||||||
|
// mqttAuth: ['work', 'Bjhmdys@202010'],
|
||||||
|
// accessKey: '6952564ceb712e2daeea7039',
|
||||||
|
// accessSecret: 'df717a60-85b7-4a63-b638-0aed4605d277',
|
||||||
|
// token: '',
|
||||||
|
// getToken: ':3000/ks/system/user/token',
|
||||||
|
// getTime: ':3000/ks/system/time',
|
||||||
|
// })】
|
||||||
|
|
||||||
const config = reactive<GlobalConfig>({
|
const config = reactive<GlobalConfig>({
|
||||||
serverIp: '118.145.200.78',
|
|
||||||
getSources: ':3000/ks/source',
|
|
||||||
subscribe: ':3000/stream/live/subscribe',
|
|
||||||
resultTopic: 'ks/video_detection',
|
resultTopic: 'ks/video_detection',
|
||||||
streamInfoTopic: 'ks/stream_local',
|
streamInfoTopic: 'ks/stream_local',
|
||||||
media_http_api: 3001,
|
|
||||||
websocket: 8083,
|
|
||||||
mqttAuth: ['work', 'Bjhmdys@202010'],
|
|
||||||
accessKey: '6952564ceb712e2daeea7039',
|
|
||||||
accessSecret: 'df717a60-85b7-4a63-b638-0aed4605d277',
|
|
||||||
token: '',
|
|
||||||
getToken: ':3000/ks/system/user/token',
|
|
||||||
getTime: ':3000/ks/system/time',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const layout = ref<1 | 4>(1)
|
const layout = ref<1 | 4>(1)
|
||||||
@ -83,7 +93,7 @@ const playingSources = reactive<(string | null)[]>([null, null, null, null])
|
|||||||
const boxRefs: (InstanceType<typeof VideoBox> | null)[] = [null, null, null, null]
|
const boxRefs: (InstanceType<typeof VideoBox> | null)[] = [null, null, null, null]
|
||||||
|
|
||||||
let mqttClient: any = null
|
let mqttClient: any = null
|
||||||
let apis = createApis(config)
|
let apis = createApis()
|
||||||
|
|
||||||
function setBoxRef(el: any, index: number) {
|
function setBoxRef(el: any, index: number) {
|
||||||
boxRefs[index] = el
|
boxRefs[index] = el
|
||||||
@ -197,12 +207,44 @@ async function connectMqtt() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onDeviceChange() {
|
||||||
|
// 切换设备时关闭所有视频
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
if (playingSources[i]) closeVideo(i)
|
||||||
|
}
|
||||||
|
// 清空列表
|
||||||
|
sourceList.value = []
|
||||||
|
// 重新加载设备源
|
||||||
|
loadSources(selectedDeviceId.value)
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
//const tokenRes = await apis.getToken()
|
//const tokenRes = await apis.getToken()
|
||||||
// if (tokenRes.error_code === 0) {
|
// if (tokenRes.error_code === 0) {
|
||||||
//config.token = tokenRes.data
|
//config.token = tokenRes.data
|
||||||
apis = createApis(config)
|
apis = createApis()
|
||||||
|
|
||||||
|
// 加载设备列表
|
||||||
|
const devicesRes = await apis.getDevices()
|
||||||
|
deviceList.value = devicesRes
|
||||||
|
if (devicesRes.length > 0) {
|
||||||
|
selectedDeviceId.value = devicesRes[0].DeviceId
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载第一个设备的源列表
|
||||||
|
if (selectedDeviceId.value) {
|
||||||
|
await loadSources(selectedDeviceId.value)
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('初始化失败', e)
|
||||||
|
}
|
||||||
|
connectMqtt()
|
||||||
|
})
|
||||||
|
|
||||||
|
async function loadSources(deviceId: string) {
|
||||||
|
try {
|
||||||
const sourcesRes = await apis.getSources(deviceId)
|
const sourcesRes = await apis.getSources(deviceId)
|
||||||
sourceList.value = sourcesRes.map((item) => {
|
sourceList.value = sourcesRes.map((item) => {
|
||||||
item.sourceId = item.id
|
item.sourceId = item.id
|
||||||
@ -212,12 +254,10 @@ onMounted(async () => {
|
|||||||
sourcesMap[item.id] = item
|
sourcesMap[item.id] = item
|
||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
//}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('初始化失败', e)
|
console.error('加载源列表失败', e)
|
||||||
}
|
}
|
||||||
connectMqtt()
|
}
|
||||||
})
|
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
mqttClient?.end()
|
mqttClient?.end()
|
||||||
@ -275,6 +315,23 @@ html, body {
|
|||||||
letter-spacing: 1px;
|
letter-spacing: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.device-select {
|
||||||
|
background: rgba(0, 180, 255, 0.15);
|
||||||
|
border: 1px solid #0af;
|
||||||
|
color: #0af;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 4px 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.device-select option {
|
||||||
|
background: #0d1b2e;
|
||||||
|
color: #e0f0ff;
|
||||||
|
}
|
||||||
|
|
||||||
.layout-btn {
|
.layout-btn {
|
||||||
background: rgba(0, 180, 255, 0.15);
|
background: rgba(0, 180, 255, 0.15);
|
||||||
border: 1px solid #0af;
|
border: 1px solid #0af;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import type { GlobalConfig, SourceItem, MqttServerInfo, DeviceItem } from '../types'
|
import type { GlobalConfig, SourceItem, MqttServerInfo, DeviceItem } from '../types'
|
||||||
// import { generateSignature, generateRandomString } from '../utils/signature'
|
// import { generateSignature, generateRandomString } from '../utils/signature'
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
export function createApis(config: GlobalConfig) {
|
export function createApis() {
|
||||||
// const baseUrl = () => `http://${config.serverIp}`
|
// const baseUrl = () => `http://${config.serverIp}`
|
||||||
// const authHeader = () => ({ Authorization: `Bearer ${config.token}` })
|
// const authHeader = () => ({ Authorization: `Bearer ${config.token}` })
|
||||||
|
|
||||||
@ -43,5 +43,5 @@ export function createApis(config: GlobalConfig) {
|
|||||||
return await window.HybridWebView.InvokeDotNet<DeviceItem[]>('GetDevicesAsync')
|
return await window.HybridWebView.InvokeDotNet<DeviceItem[]>('GetDevicesAsync')
|
||||||
}
|
}
|
||||||
|
|
||||||
return { getSources, subscribeLive, GetMqttServerProxyInfo }
|
return { getSources, subscribeLive, GetMqttServerProxyInfo, getDevices }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,8 +44,6 @@ declare const ZLMRTCClient: any
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
source: SourceItem | null
|
source: SourceItem | null
|
||||||
serverIp: string
|
|
||||||
mediaPort: number
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@ -151,14 +149,10 @@ function playVideo(stream: string) {
|
|||||||
const video = videoRef.value
|
const video = videoRef.value
|
||||||
if (!video) return
|
if (!video) return
|
||||||
|
|
||||||
const streamUrl = stream
|
|
||||||
.replace('127.0.0.1', props.serverIp)
|
|
||||||
.replace('1985', String(props.mediaPort))
|
|
||||||
|
|
||||||
const srsrtc = new ZLMRTCClient.Endpoint({
|
const srsrtc = new ZLMRTCClient.Endpoint({
|
||||||
element: video,
|
element: video,
|
||||||
debug: false,
|
debug: false,
|
||||||
zlmsdpUrl: streamUrl,
|
zlmsdpUrl: stream,
|
||||||
simulcast: false,
|
simulcast: false,
|
||||||
useCamera: true,
|
useCamera: true,
|
||||||
audioEnable: true,
|
audioEnable: true,
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
export interface GlobalConfig {
|
export interface GlobalConfig {
|
||||||
serverIp: string
|
// serverIp: string
|
||||||
getSources: string
|
// getSources: string
|
||||||
subscribe: string
|
// subscribe: string
|
||||||
resultTopic: string
|
resultTopic: string
|
||||||
streamInfoTopic: string
|
streamInfoTopic: string
|
||||||
media_http_api: number
|
// media_http_api: number
|
||||||
websocket: number
|
// websocket: number
|
||||||
mqttAuth: [string, string]
|
// mqttAuth: [string, string]
|
||||||
accessKey: string
|
// accessKey: string
|
||||||
accessSecret: string
|
// accessSecret: string
|
||||||
token: string
|
// token: string
|
||||||
getToken: string
|
// getToken: string
|
||||||
getTime: string
|
// getTime: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AlgInfo {
|
export interface AlgInfo {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user