|
@@ -117,6 +117,12 @@ import {
|
|
import SecondTimer from "../common/SecondTimer";
|
|
import SecondTimer from "../common/SecondTimer";
|
|
import { formatDate, timeNumberToText } from "@/utils/utils";
|
|
import { formatDate, timeNumberToText } from "@/utils/utils";
|
|
|
|
|
|
|
|
+const domEmpty = (dom) => {
|
|
|
|
+ dom.childNodes.forEach((childNode) => {
|
|
|
|
+ dom.removeChild(childNode);
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+
|
|
export default {
|
|
export default {
|
|
name: "video-communication",
|
|
name: "video-communication",
|
|
components: { SecondTimer },
|
|
components: { SecondTimer },
|
|
@@ -153,19 +159,21 @@ export default {
|
|
pageNumber: this.current,
|
|
pageNumber: this.current,
|
|
pageSize: this.size,
|
|
pageSize: this.size,
|
|
}).catch(() => {});
|
|
}).catch(() => {});
|
|
- this.students = res.data.data.records.map((item) => {
|
|
|
|
- item.durationTime = timeNumberToText(item.endTime - item.startTime);
|
|
|
|
- item.startTime = formatDate(
|
|
|
|
- "YYYY-MM-DD HH:mm:ss",
|
|
|
|
- new Date(item.startTime)
|
|
|
|
- );
|
|
|
|
- item.endTime = formatDate(
|
|
|
|
- "YYYY-MM-DD HH:mm:ss",
|
|
|
|
- new Date(item.endTime)
|
|
|
|
- );
|
|
|
|
- return item;
|
|
|
|
- });
|
|
|
|
- this.total = res.data.data.total;
|
|
|
|
|
|
+ if (res) {
|
|
|
|
+ this.students = res.data.data.records.map((item) => {
|
|
|
|
+ item.durationTime = timeNumberToText(item.endTime - item.startTime);
|
|
|
|
+ item.startTime = formatDate(
|
|
|
|
+ "YYYY-MM-DD HH:mm:ss",
|
|
|
|
+ new Date(item.startTime)
|
|
|
|
+ );
|
|
|
|
+ item.endTime = formatDate(
|
|
|
|
+ "YYYY-MM-DD HH:mm:ss",
|
|
|
|
+ new Date(item.endTime)
|
|
|
|
+ );
|
|
|
|
+ return item;
|
|
|
|
+ });
|
|
|
|
+ this.total = res.data.data.total;
|
|
|
|
+ }
|
|
// 当前页没有数据,同时当前页不是第一页,则自动跳到前一页。
|
|
// 当前页没有数据,同时当前页不是第一页,则自动跳到前一页。
|
|
if (!this.students.length && this.current > 1) {
|
|
if (!this.students.length && this.current > 1) {
|
|
this.current--;
|
|
this.current--;
|
|
@@ -214,7 +222,7 @@ export default {
|
|
let initLocalStreamResult = true;
|
|
let initLocalStreamResult = true;
|
|
await localStream.initialize().catch((error) => {
|
|
await localStream.initialize().catch((error) => {
|
|
console.log(errorTips[error.name]);
|
|
console.log(errorTips[error.name]);
|
|
- this.notifyError(errorTips[error.name]);
|
|
|
|
|
|
+ this.notifyError(errorTips[error.name] || "未知错误");
|
|
initLocalStreamResult = false;
|
|
initLocalStreamResult = false;
|
|
localStream.close();
|
|
localStream.close();
|
|
});
|
|
});
|
|
@@ -241,23 +249,27 @@ export default {
|
|
// 添加远程用户视频发布监听
|
|
// 添加远程用户视频发布监听
|
|
this.client.on("stream-added", (event) => {
|
|
this.client.on("stream-added", (event) => {
|
|
console.log(event);
|
|
console.log(event);
|
|
- if (event.stream.userId_ !== student.sourceUserId) return;
|
|
|
|
-
|
|
|
|
|
|
+ console.log(event.stream.getUserId(), student.sourceUserId);
|
|
const remoteStream = event.stream;
|
|
const remoteStream = event.stream;
|
|
|
|
+ if (remoteStream.getUserId() !== student.sourceUserId) return;
|
|
|
|
+ console.log(`有效视频${remoteStream.getUserId()},准备订阅`);
|
|
|
|
+
|
|
this.client
|
|
this.client
|
|
.subscribe(remoteStream, { audio: true, video: true })
|
|
.subscribe(remoteStream, { audio: true, video: true })
|
|
- .then(() => {
|
|
|
|
- console.log("开始订阅视频成功!");
|
|
|
|
- })
|
|
|
|
.catch((error) => {
|
|
.catch((error) => {
|
|
- console.log("订阅视频失败!", error);
|
|
|
|
|
|
+ console.log(`${remoteStream.getUserId()}视频订阅失败!`, error);
|
|
this.notifyError("学生视频获取失败!");
|
|
this.notifyError("学生视频获取失败!");
|
|
});
|
|
});
|
|
});
|
|
});
|
|
this.client.on("stream-subscribed", (event) => {
|
|
this.client.on("stream-subscribed", (event) => {
|
|
- console.log("视频已订阅!");
|
|
|
|
const remoteStream = event.stream;
|
|
const remoteStream = event.stream;
|
|
|
|
+ console.log(remoteStream.hasAudio(), remoteStream.hasVideo());
|
|
|
|
+ if (!remoteStream.hasAudio() || !remoteStream.hasVideo()) return;
|
|
|
|
+
|
|
|
|
+ console.log(event);
|
|
|
|
+ console.log(`${remoteStream.getUserId()}视频已订阅!`);
|
|
if (!this.$refs.SecondTimer.recoding) this.$refs.SecondTimer.start();
|
|
if (!this.$refs.SecondTimer.recoding) this.$refs.SecondTimer.start();
|
|
|
|
+ domEmpty(document.getElementById("communication-host"));
|
|
remoteStream.play("communication-host", { objectFit: "contain" });
|
|
remoteStream.play("communication-host", { objectFit: "contain" });
|
|
});
|
|
});
|
|
|
|
|
|
@@ -275,12 +287,13 @@ export default {
|
|
this.notifyError("接通通信失败!");
|
|
this.notifyError("接通通信失败!");
|
|
});
|
|
});
|
|
if (!roomJoinResult) return;
|
|
if (!roomJoinResult) return;
|
|
|
|
+ console.log("加入房间成功!");
|
|
|
|
|
|
// 切换角色,连麦互动
|
|
// 切换角色,连麦互动
|
|
let switchResult = true;
|
|
let switchResult = true;
|
|
await this.client.switchRole("anchor").catch((error) => {
|
|
await this.client.switchRole("anchor").catch((error) => {
|
|
console.log("切换角色失败!", error);
|
|
console.log("切换角色失败!", error);
|
|
- this.notifyError("接通通信失败!");
|
|
|
|
|
|
+ this.notifyError("角色错误!");
|
|
switchResult = false;
|
|
switchResult = false;
|
|
});
|
|
});
|
|
if (!switchResult) return;
|
|
if (!switchResult) return;
|
|
@@ -293,6 +306,7 @@ export default {
|
|
publishStreamResult = false;
|
|
publishStreamResult = false;
|
|
});
|
|
});
|
|
if (!publishStreamResult) return;
|
|
if (!publishStreamResult) return;
|
|
|
|
+ console.log("发布本地音视频成功!");
|
|
|
|
|
|
// 播放本地视频
|
|
// 播放本地视频
|
|
this.localStream.play("communication-guest", { muted: true });
|
|
this.localStream.play("communication-guest", { muted: true });
|