This commit is contained in:
denggaofeng 2026-03-26 14:49:49 +08:00
parent fe9229f044
commit d075dabf2a
2 changed files with 32 additions and 8 deletions

View File

@ -58,7 +58,6 @@ import type { GlobalConfig, SourceItem, VideoInfo, DeviceItem } from './types'
declare const mqtt: any
const deviceId = 'fcfabf1d5dd036033419057075a56304' // ID使
const selectedDeviceId = ref<string>('')
const deviceList = ref<DeviceItem[]>([])
@ -150,7 +149,7 @@ function openVideo(id: string, index: number) {
if (box && sourcesMap[id]) {
box.subscribeLive(sourcesMap[id])
//
apis.subscribeLive(deviceId,id).then((res) => {
apis.subscribeLive(selectedDeviceId.value,id).then((res) => {
if (res) {
box.startPlay(res)
} else {
@ -170,6 +169,24 @@ function closeVideo(index: number) {
boxRefs[index]?.destroy()
}
//
function cleanupAll() {
//
for (let i = 0; i < 4; i++) {
if (playingSources[i]) {
closeVideo(i)
}
}
//
playingSources.fill(null)
boxRefs.fill(null)
sourceList.value = []
// MQTT
mqttClient?.end(true)
mqttClient = null
drawerOpen.value = false
}
// VideoBox ready videoInfo
function onVideoReady(_info: VideoInfo, _index: number) {
//
@ -219,10 +236,14 @@ function onDeviceChange() {
}
onMounted(async () => {
window.cleanupAll = cleanupAll;
window.handleInit = handleInit;
await handleInit()
})
async function handleInit(){
try {
//const tokenRes = await apis.getToken()
// if (tokenRes.error_code === 0) {
//config.token = tokenRes.data
apis = createApis()
//
@ -236,12 +257,12 @@ onMounted(async () => {
if (selectedDeviceId.value) {
await loadSources(selectedDeviceId.value)
}
//}
} catch (e) {
console.error('初始化失败', e)
}
connectMqtt()
})
}
async function loadSources(deviceId: string) {
try {
@ -260,7 +281,8 @@ async function loadSources(deviceId: string) {
}
onBeforeUnmount(() => {
mqttClient?.end()
window.cleanupAll = () => {};
window.handleInit = () => {};
})
</script>

View File

@ -1,5 +1,7 @@
declare interface Window {
HybridWebView: HybridWebView
cleanupAll: () => void
handleInit: () => void
}
declare interface HybridWebView {
InvokeDotNet(methodName: string, ...args: any[]): Promise<T>;