Explorar o código

解决考生端交卷之后监考端自动退出视频通话

zhangjie %!s(int64=4) %!d(string=hai) anos
pai
achega
7f570dfcc5

+ 20 - 0
src/features/invigilation/RealtimeMonitoring/VideoCommunication.vue

@@ -142,6 +142,7 @@ export default {
       userMonitor: {},
       client: null,
       localStream: null,
+      isHandup: false,
     };
   },
   mounted() {
@@ -270,6 +271,20 @@ export default {
         domEmpty(document.getElementById("communication-host"));
         remoteStream.play("communication-host", { objectFit: "contain" });
       });
+      this.client.on("stream-removed", (event) => {
+        // 监考端手动挂断时也会触发这个事件
+        const remoteStream = event.stream;
+        if (
+          remoteStream.getUserId() !== student.sourceUserId ||
+          remoteStream.getType() !== "main" ||
+          this.isHandup
+        )
+          return;
+        console.log(event);
+        console.log(`${remoteStream.getUserId()}已退出房间!`);
+        this.notifyError("对方已挂断!");
+        this.hangup();
+      });
 
       // 加入房间
       let roomJoinResult = true;
@@ -314,13 +329,18 @@ export default {
         recordId: student.examRecordId,
         source: student.source,
       });
+      this.isHandup = false;
     },
     async hangup() {
+      if (this.isHandup) return;
+      this.isHandup = true;
       this.$refs.SecondTimer.end();
       // 结束学生的通话
       await communicationOver({
         recordId: this.curStudent.examRecordId,
         source: this.curStudent.source,
+      }).catch(() => {
+        console.log("结束通话状态异常!");
       });
       this.curStudent = {};
 

+ 18 - 0
src/features/invigilation/RealtimeMonitoring/WarningDetail.vue

@@ -351,6 +351,7 @@ export default {
       subscribeSetT: null,
       loopRunning: false,
       loopSetTs: [],
+      isHandup: false,
     };
   },
   computed: {
@@ -709,6 +710,20 @@ export default {
           remoteStream.play("communication-host", { objectFit: "contain" });
         });
       });
+      this.client.on("stream-removed", (event) => {
+        const remoteStream = event.stream;
+        if (
+          remoteStream.getUserId() !== this.userMonitor.sourceUserId ||
+          remoteStream.getType() !== "main" ||
+          this.isHandup
+        )
+          return;
+
+        console.log(event);
+        console.log(`${remoteStream.getUserId()}已退出房间!`);
+        this.notifyError("对方已挂断!");
+        this.hangup();
+      });
 
       // 加入房间
       let roomJoinResult = true;
@@ -746,8 +761,11 @@ export default {
 
       // 播放本地视频
       this.localStream.play("communication-guest", { muted: true });
+      this.isHandup = false;
     },
     async hangup() {
+      if (this.isHandup) return;
+      this.isHandup = true;
       if (this.subscribeSetT) clearTimeout(this.subscribeSetT);
 
       this.$refs.SecondTimer.end();