lsc 2 tygodni temu
rodzic
commit
e61d4f799c
1 zmienionych plików z 14 dodań i 2 usunięć
  1. 14 2
      src/views/Student/index.vue

+ 14 - 2
src/views/Student/index.vue

@@ -4253,12 +4253,24 @@ const cleanupWebSocketConnection = () => {
     providerSocket.value.destroy()
     providerSocket.value = null
   }
-  
+
   if (docSocket.value) {
     // 注意:doc 会被 provider.destroy() 自动销毁,不需要手动 destroy
     // 但如果 provider 已经被销毁,这里置空即可
     docSocket.value = null
   }
+
+  // ★ 关键:doc 已销毁,必须把绑定在旧 doc 上的共享类型引用全部置空,
+  // 否则重连后 messageInit() 的 if (!yXxx.value) 守卫会跳过绑定,
+  // 新 doc 收到更新时 observe 回调不会触发(表现为突然收不到消息)
+  yMessage.value = null
+  yTimerState.value = null
+  yLaserState.value = null
+  yWritingBoardState.value = null
+  yTimerMessages.value = null
+  yLaserMessages.value = null
+  yWritingBoardMessages.value = null
+  yIsResultArrayMessages.value = null
 }
 
 // 创建WebSocket连接
@@ -4303,7 +4315,7 @@ const createWebSocketConnection = async (type = 1) => {
       docSocket.value,
       {
         params: { yauth: authToken.value },
-        maxBackoffTime: 5000, // 重连最长等 5 秒
+        // maxBackoffTime: 5000, // 重连最长等 5 秒
       }
     )
     providerSocket.value.awareness.setLocalState(null)