diff --git a/src/App.vue b/src/App.vue index 546547f..2571479 100644 --- a/src/App.vue +++ b/src/App.vue @@ -165,10 +165,12 @@ function onVideoReady(_info: VideoInfo, _index: number) { // 可在此做额外处理 } -function connectMqtt() { - mqttClient = mqtt.connect(`ws://${config.serverIp}:${config.websocket}/mqtt`, { - username: config.mqttAuth[0], - password: config.mqttAuth[1], +async function connectMqtt() { + var mqttServerInfo = await apis.GetMqttServerProxyInfo() + if (!mqttServerInfo.server) return + mqttClient = mqtt.connect(mqttServerInfo.server, { + username:mqttServerInfo.username, + password:mqttServerInfo.password, }) mqttClient.subscribe(config.resultTopic, { qos: 0 }) mqttClient.subscribe(config.streamInfoTopic, { qos: 0 }) diff --git a/src/api/index.ts b/src/api/index.ts index e96eb1d..7578249 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,4 +1,4 @@ -import type { GlobalConfig, SourceItem } from '../types' +import type { GlobalConfig, SourceItem, MqttServerInfo, DeviceItem } from '../types' // import { generateSignature, generateRandomString } from '../utils/signature' // eslint-disable-next-line @typescript-eslint/no-unused-vars export function createApis(config: GlobalConfig) { @@ -35,9 +35,13 @@ export function createApis(config: GlobalConfig) { return await window.HybridWebView.InvokeDotNet('SubscribeLiveAsync', [deviceId, source_id]) } - async function getMqttServerProxyUrl(): Promise<{ data: string }> { - return await window.HybridWebView.InvokeDotNet<{ data: string }>('GetMqttServerProxyUrlAsync') + async function GetMqttServerProxyInfo(): Promise { + return await window.HybridWebView.InvokeDotNet('GetMqttServerProxyInfo') } - return { getSources, subscribeLive, getMqttServerProxyUrl } + async function getDevices(): Promise { + return await window.HybridWebView.InvokeDotNet('GetDevicesAsync') + } + + return { getSources, subscribeLive, GetMqttServerProxyInfo } } diff --git a/src/types/index.ts b/src/types/index.ts index 55b871d..4c481e1 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -98,4 +98,15 @@ export interface BboxData { export interface DetectionResult { bbox: BboxData +} + +export interface MqttServerInfo { + username: string + password: string + server: string +} + +export interface DeviceItem { + DeviceId: string + DeviceName: string } \ No newline at end of file