Prechádzať zdrojové kódy

fix(student): 修复重复发送 class_begin 消息的问题

在三个发送 class_begin 消息的判断条件中,增加了 opRes.value.length === 0 的限制,避免相同文档重连或绑定新文档时重复发送上线消息。
lsc 20 hodín pred
rodič
commit
83a748a867
1 zmenil súbory, kde vykonal 4 pridanie a 3 odobranie
  1. 4 3
      src/views/Student/index.vue

+ 4 - 3
src/views/Student/index.vue

@@ -3258,7 +3258,7 @@ const messageInit = () => {
   console.log('🔗 messageInit: doc.guid=', doc.guid, 'boundDoc=', boundDoc?.guid, 'same=', boundDoc === doc)
   if (boundDoc === doc) {
     // 同 doc 重连:补发上线消息即可
-    if (props.type === '2') {
+    if (props.type === '2' && opRes.value.length === 0) {
       sendMessage({ type: 'class_begin', courseid: props.courseid })
     }
     return
@@ -3496,7 +3496,7 @@ const messageInit = () => {
   })
 
   // 新 doc 绑定完成,补发上线消息
-  if (props.type === '2') {
+  if (props.type === '2' && opRes.value.length === 0) {
     sendMessage({ type: 'class_begin', courseid: props.courseid })
   }
 }
@@ -4121,6 +4121,7 @@ onMounted(() => {
         '9. doc 里所有顶层 key': Array.from(doc.share.entries()).map(([k, v]: [string, any]) => k + ':' + v.constructor.name),
         '10. provider synced': providerSocket.value?.synced,
         '11. ws.readyState': providerSocket.value?.ws?.readyState,
+        '12. messageV3?.get("slidesIndex")': msgV3Type?.get?.('slidesIndex'),
       }
       console.log('════════ Yjs 诊断 ════════')
       for (const [k, v] of Object.entries(report)) {
@@ -4624,7 +4625,7 @@ const createWebSocketConnection = async (type = 1) => {
       }
 
       // 学生端补发上线消息,让老师知道学生已就绪
-      if (props.type === '2') {
+      if (props.type === '2' && opRes.value.length === 0) {
         console.log('🔗 sync handler: yMessage.value =', yMessage.value ? '已绑定' : 'null', 'doc.guid=', docSocket.value?.guid)
         sendMessage({ type: 'class_begin', courseid: props.courseid })
         // ★ 确认 class_begin 是否真的写入了 messageV3