视频采集卡-正常展示

main
ysn 1 week ago
parent 04dd2951b2
commit fbf04a5ec0
  1. 145
      src/views/videoCommunication/realTimeConsultation.vue

@ -69,7 +69,7 @@
class="share-preview" class="share-preview"
autoplay autoplay
playsinline playsinline
muted :muted="false"
></video> ></video>
</div> </div>
@ -623,7 +623,7 @@ export default {
// ==================== 4 ==================== // ==================== 4 ====================
async switchCaptureCard(deviceId) { async switchCaptureCard(deviceId) {
// // 1.
if (this.captureCheckTimer) clearTimeout(this.captureCheckTimer); if (this.captureCheckTimer) clearTimeout(this.captureCheckTimer);
this.closeCaptureCard(); this.closeCaptureCard();
@ -635,65 +635,64 @@ export default {
this.isSharing = true; this.isSharing = true;
await this.$nextTick(); await this.$nextTick();
const videoEl = this.$refs.shareVideo;
// 2. Video CSS
// Video
if (videoEl) {
videoEl.srcObject = null;
videoEl.load();
videoEl.style.width = "100%";
videoEl.style.height = "100%";
videoEl.style.objectFit = "contain";
videoEl.style.background = "#000";
videoEl.muted = false; //
}
const constraints = { try {
console.log("正在执行最终修复方案:强制30帧 + 无分辨率限制...");
// 3.
const stream = await navigator.mediaDevices.getUserMedia({
video: { video: {
deviceId: { exact: deviceId }, deviceId: { exact: deviceId },
width: { ideal: 1920 }, // A 30绿 USB 2.0 线
height: { ideal: 1080 }, frameRate: { exact: 30 },
frameRate: { ideal: 30 }, // B MJPEG USB 2.0
advanced: [{ chromegfx: "mjpeg" }],
// width/height 640x480
}, },
audio: false, audio: true,
}; });
let captureStream = null; console.log(
try { "采集成功!实际设置:",
captureStream = await navigator.mediaDevices.getUserMedia(constraints); stream.getVideoTracks()[0].getSettings()
} catch (err) {
console.error("采集卡获取流失败:", err);
const lowConstraints = {
video: { deviceId: { exact: deviceId } },
audio: false,
};
try {
captureStream = await navigator.mediaDevices.getUserMedia(
lowConstraints
); );
} catch (e2) {
this.$message.error( // 4.
"无法打开采集卡,请检查USB口、权限、是否被其他软件占用" if (videoEl) {
); videoEl.srcObject = stream;
this.isSharing = false;
return; // C
const playPromise = videoEl.play();
if (playPromise !== undefined) {
playPromise
.then(() => {
console.log("视频播放已成功启动");
this.$message.success("采集卡已连接 (强制30帧/MJPEG)");
})
.catch((error) => {
console.error("自动播放被拦截:", error);
this.$message.error("播放被拦截,请尝试点击页面任意位置");
});
} }
} }
} catch (err) {
const videoEl = this.$refs.shareVideo; console.error("最终方案失败:", err);
videoEl.srcObject = captureStream; this.$message.error("连接失败: " + err.message);
videoEl.muted = true;
videoEl.playsinline = true;
videoEl.autoplay = true;
let hasValidFrame = false;
videoEl.onloadeddata = () => (hasValidFrame = true);
// 3
this.captureCheckTimer = setTimeout(() => {
if (!hasValidFrame) {
this.$message.error("采集卡无信号,请检查设备、HDMI线、USB3.0接口");
this.closeCaptureCard();
this.isSharing = false; this.isSharing = false;
} }
}, 3000);
//
const videoTrack = captureStream.getVideoTracks()[0];
if (videoTrack)
videoTrack.onended = () => {
this.$message.warning("采集卡信号已断开");
this.closeCaptureCard();
this.isSharing = false;
};
}, },
// //
@ -702,14 +701,16 @@ export default {
if (this.captureCheckTimer) clearTimeout(this.captureCheckTimer); if (this.captureCheckTimer) clearTimeout(this.captureCheckTimer);
const videoEl = this.$refs.shareVideo; const videoEl = this.$refs.shareVideo;
if (!videoEl) return; if (!videoEl) return;
const stream = videoEl.srcObject; const stream = videoEl.srcObject;
if (stream) if (stream) {
stream.getTracks().forEach((t) => { //
t.stop(); stream.getTracks().forEach((track) => {
t.onended = null; track.stop();
track.onended = null;
}); });
}
videoEl.srcObject = null; videoEl.srcObject = null;
videoEl.onloadeddata = null;
} catch (e) { } catch (e) {
console.log("关闭采集卡异常:", e); console.log("关闭采集卡异常:", e);
} }
@ -724,7 +725,7 @@ export default {
try { try {
const stream = await navigator.mediaDevices.getDisplayMedia({ const stream = await navigator.mediaDevices.getDisplayMedia({
video: { width: 1920, height: 1080, frameRate: 15 }, video: { width: 1920, height: 1080, frameRate: 15 },
audio: false, audio: true,
}); });
const track = stream.getVideoTracks()[0]; const track = stream.getVideoTracks()[0];
track.onended = () => this.stopShare(); track.onended = () => this.stopShare();
@ -994,20 +995,20 @@ export default {
// ==================== 11 ==================== // ==================== 11 ====================
startNetworkMonitoring() { startNetworkMonitoring() {
setInterval(() => { // setInterval(() => {
if (!window.hirtcwebsdk) return; // if (!window.hirtcwebsdk) return;
const s = window.hirtcwebsdk.getNetworkStats(); // const s = window.hirtcwebsdk.getNetworkStats();
if (s?.rtt) { // if (s?.rtt) {
this.networkDelay = Math.round(s.rtt); // this.networkDelay = Math.round(s.rtt);
if (this.networkDelay < 100) // if (this.networkDelay < 100)
this.networkQuality = { text: "优秀", color: "#00e676" }; // this.networkQuality = { text: "", color: "#00e676" };
else if (this.networkDelay < 300) // else if (this.networkDelay < 300)
this.networkQuality = { text: "良好", color: "#00e676" }; // this.networkQuality = { text: "", color: "#00e676" };
else if (this.networkDelay < 600) // else if (this.networkDelay < 600)
this.networkQuality = { text: "一般", color: "#ffc107" }; // this.networkQuality = { text: "", color: "#ffc107" };
else this.networkQuality = { text: "差", color: "#f56c6c" }; // else this.networkQuality = { text: "", color: "#f56c6c" };
} // }
}, 2000); // }, 2000);
}, },
// ==================== 12 ==================== // ==================== 12 ====================
@ -1065,7 +1066,7 @@ export default {
this.inviteDialogVisible = true; this.inviteDialogVisible = true;
}, },
handleInviteConfirm(selectedContacts) { handleInviteConfirm(selectedContacts) {
console.log('邀请的联系人:', selectedContacts); console.log("邀请的联系人:", selectedContacts);
this.$message.success(`已邀请 ${selectedContacts.length} 位联系人`); this.$message.success(`已邀请 ${selectedContacts.length} 位联系人`);
this.inviteDialogVisible = false; this.inviteDialogVisible = false;
}, },

Loading…
Cancel
Save