fix: 修正 RTSP 為 5 秒抓一次 device

This commit is contained in:
MJM_2025_05\polly 2025-09-25 17:38:08 +08:00
parent ba7fda3d07
commit bb549311df
2 changed files with 37 additions and 5 deletions

View File

@ -1,9 +1,5 @@
// src/apis/rtsp/index.js
import {
POST_SET_RTSP_ENABLE,
POST_SET_SAMBA_DIRECTORY,
POST_GET_RTSP_DEVICE,
} from "./api";
import { POST_SET_RTSP_ENABLE, POST_GET_RTSP_DEVICE } from "./api";
import instance from "@/util/request";
import apihandler from "@/util/apihandler";

View File

@ -96,6 +96,7 @@ export default {
message: "",
rtspDevices: [],
selectedMainId: null, // main_id
pollTimer: null, //
};
},
computed: {
@ -109,6 +110,10 @@ export default {
async mounted() {
await this.loadRtspDevices();
},
beforeUnmount() {
//
this.stopPolling();
},
watch: {
selectedBtn: {
handler(newVal) {
@ -163,6 +168,31 @@ export default {
this.monitorUrl = d.rtsp_url || DEFAULT_MONITOR_URL;
},
// === ===
startPolling() {
//
if (this.pollTimer) return;
const tick = async () => {
const keepId = this.selectedMainId;
await this.loadRtspDevices();
//
const found = this.rtspDevices.find((d) => d.main_id === keepId);
if (found) this.selectDevice(found);
};
// 5
tick();
this.pollTimer = setInterval(tick, 5000);
},
stopPolling() {
if (this.pollTimer) {
clearInterval(this.pollTimer);
this.pollTimer = null;
}
},
//
async startDetection() {
if (!this.selectedMainId) {
@ -177,6 +207,9 @@ export default {
const found = this.rtspDevices.find((d) => d.main_id === keepId);
if (found) this.selectDevice(found);
this.message = this.$t("rtsp.startSuccess");
// 5
this.startPolling();
} catch (e) {
console.error(e);
this.message = this.$t("rtsp.startFail");
@ -199,6 +232,9 @@ export default {
const found = this.rtspDevices.find((d) => d.main_id === keepId);
if (found) this.selectDevice(found);
this.message = this.$t("rtsp.stopSuccess");
//
this.stopPolling();
} catch (e) {
console.error(e);
this.message = this.$t("rtsp.stopFail");