视频采集卡-正常展示

main
ysn 1 week ago
parent 04dd2951b2
commit fbf04a5ec0
  1. 155
      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;
const constraints = { // 2. Video CSS
video: { // Video
deviceId: { exact: deviceId }, if (videoEl) {
width: { ideal: 1920 }, videoEl.srcObject = null;
height: { ideal: 1080 }, videoEl.load();
frameRate: { ideal: 30 }, videoEl.style.width = "100%";
}, videoEl.style.height = "100%";
audio: false, videoEl.style.objectFit = "contain";
}; videoEl.style.background = "#000";
videoEl.muted = false; //
}
let captureStream = null;
try { try {
captureStream = await navigator.mediaDevices.getUserMedia(constraints); console.log("正在执行最终修复方案:强制30帧 + 无分辨率限制...");
} 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(
"无法打开采集卡,请检查USB口、权限、是否被其他软件占用"
);
this.isSharing = false;
return;
}
}
const videoEl = this.$refs.shareVideo; // 3.
videoEl.srcObject = captureStream; const stream = await navigator.mediaDevices.getUserMedia({
videoEl.muted = true; video: {
videoEl.playsinline = true; deviceId: { exact: deviceId },
videoEl.autoplay = true; // A 30绿 USB 2.0 线
frameRate: { exact: 30 },
let hasValidFrame = false; // B MJPEG USB 2.0
videoEl.onloadeddata = () => (hasValidFrame = true); advanced: [{ chromegfx: "mjpeg" }],
// width/height 640x480
// 3 },
this.captureCheckTimer = setTimeout(() => { audio: true,
if (!hasValidFrame) { });
this.$message.error("采集卡无信号,请检查设备、HDMI线、USB3.0接口");
this.closeCaptureCard(); console.log(
this.isSharing = false; "采集成功!实际设置:",
stream.getVideoTracks()[0].getSettings()
);
// 4.
if (videoEl) {
videoEl.srcObject = stream;
// 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("播放被拦截,请尝试点击页面任意位置");
});
}
} }
}, 3000); } catch (err) {
console.error("最终方案失败:", err);
// this.$message.error("连接失败: " + err.message);
const videoTrack = captureStream.getVideoTracks()[0]; this.isSharing = false;
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