|
|
@@ -4457,17 +4457,27 @@ const createWebSocketConnection = async (type = 1) => {
|
|
|
|
|
|
// ★ 三层日志之二:Y.Doc update 事件 — 列出所有根类型的 size,看更新到底改了哪个
|
|
|
docSocket.value.on('update', (update: Uint8Array, origin: any) => {
|
|
|
- const originName = origin?.constructor?.name || (origin === providerSocket.value ? 'ws-provider' : typeof origin)
|
|
|
- const share = (docSocket.value as any)?.share
|
|
|
- const sizes: string[] = []
|
|
|
- if (share) {
|
|
|
- for (const [name, type] of share.entries()) {
|
|
|
- const sz = type.size ?? type.length ?? '?'
|
|
|
- const latest = type.get?.('latest')
|
|
|
- sizes.push(`${name}=${sz}${latest ? '(' + latest.type + ')' : ''}`)
|
|
|
+ // origin === providerSocket.value 表示来自网络
|
|
|
+ // origin !== providerSocket.value 表示本地修改
|
|
|
+ if (origin !== providerSocket.value) return
|
|
|
+
|
|
|
+ try {
|
|
|
+ const { structs } = Y.decodeUpdate(update)
|
|
|
+ for (const struct of structs) {
|
|
|
+ const arr = (struct as any)?.content?.arr
|
|
|
+ if (arr && Array.isArray(arr)) {
|
|
|
+ for (const val of arr) {
|
|
|
+ if (val && typeof val === 'object' && val.type && val.mId) {
|
|
|
+ console.log(`📦 提取: type=${val.type}, mId=${val.mId}`)
|
|
|
+ if (val.mId !== mId.value) getMessages(val)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- console.log(`📥 Y.Doc update: ${update.length} bytes, origin: ${originName}, types: [${sizes.join(', ')}]`)
|
|
|
+ catch (e) {
|
|
|
+ console.log('📦 解析失败:', e)
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
// 清理可能残留的旧心跳定时器
|