fix: 修复摄像头无法正常启动,以及关闭摄像头会导致后端崩溃的问题

This commit is contained in:
2025-08-18 19:14:02 +08:00
parent 7265b10870
commit 1b5b0e28e3
8 changed files with 640 additions and 75 deletions

View File

@@ -387,8 +387,6 @@ import { VideoStreamClient, ResolutionConfigRequest } from "@/APIClient";
import { useEquipments } from "@/stores/equipments";
import { AuthManager } from "@/utils/AuthManager";
const eqps = useEquipments();
// 状态管理
const loading = ref(false);
const configing = ref(false);
@@ -510,7 +508,7 @@ const toggleStreamType = async () => {
"success",
`已切换到${streamType.value === "usbCamera" ? "USB摄像头" : "视频流"}`,
);
stopStream();
await stopStream();
} catch (error) {
addLog("error", `切换视频流类型失败: ${error}`);
console.error("切换视频流类型失败:", error);
@@ -647,7 +645,8 @@ const tryReconnect = () => {
// 执行对焦
const performFocus = async () => {
if (isFocusing.value || !isPlaying.value) return;
if (isFocusing.value || !isPlaying.value || streamType.value === "usbCamera")
return;
try {
isFocusing.value = true;
@@ -711,7 +710,7 @@ const startStream = async () => {
try {
addLog("info", "正在启动视频流...");
videoStatus.value = "正在连接视频流...";
videoClient.setVideoStreamEnable(true);
await videoClient.setVideoStreamEnable(true);
// 刷新状态
await refreshStatus();
@@ -778,7 +777,7 @@ const changeResolution = async () => {
// 如果正在播放,先停止视频流
if (wasPlaying) {
stopStream();
await stopStream();
await new Promise((resolve) => setTimeout(resolve, 1000)); // 等待1秒
}
@@ -815,10 +814,10 @@ const changeResolution = async () => {
};
// 停止视频流
const stopStream = () => {
const stopStream = async () => {
try {
addLog("info", "正在停止视频流...");
videoClient.setVideoStreamEnable(false);
await videoClient.setVideoStreamEnable(false);
// 清除视频源
currentVideoSource.value = "";