|
|
@@ -118,12 +118,14 @@ export class YjsRedisProvider extends Observable<string> {
|
|
|
|
|
|
// 本地文档更新 → 广播
|
|
|
this._updateHandler = (update, origin) => {
|
|
|
- if (origin !== this) {
|
|
|
- const encoder = encoding.createEncoder()
|
|
|
- encoding.writeVarUint(encoder, messageSync)
|
|
|
- syncProtocol.writeUpdate(encoder, update)
|
|
|
- this._broadcast(encoding.toUint8Array(encoder))
|
|
|
- }
|
|
|
+ // 远端 update:origin 是 provider 实例 → 不回发
|
|
|
+ if (origin instanceof YjsRedisProvider) return
|
|
|
+
|
|
|
+ // 本地编辑:广播给服务器
|
|
|
+ const encoder = encoding.createEncoder()
|
|
|
+ encoding.writeVarUint(encoder, messageSync)
|
|
|
+ syncProtocol.writeUpdate(encoder, update)
|
|
|
+ this._broadcast(encoding.toUint8Array(encoder))
|
|
|
}
|
|
|
this.doc.on('update', this._updateHandler)
|
|
|
|