commit
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
// 客户端实现
|
// 客户端实现
|
||||||
import { SimpleTextOperation as TextOperation } from "./op";
|
import { Noop, SimpleTextOperation as TextOperation } from "./op";
|
||||||
import { getDemoServerInstance } from "./server";
|
import { getDemoServerInstance } from "./server";
|
||||||
|
|
||||||
// 直接获取server实例,这里省略了网络过程
|
// 直接获取server实例,这里省略了网络过程
|
||||||
@@ -94,7 +94,7 @@ export class Client {
|
|||||||
this.enableSync = enabled;
|
this.enableSync = enabled;
|
||||||
// 重新启用同步,继续发送本地操作,发送一个空操作,确保服务端向我们推送最新操作
|
// 重新启用同步,继续发送本地操作,发送一个空操作,确保服务端向我们推送最新操作
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
// this.buffer.push(new Noop());
|
this.buffer.push(new Noop());
|
||||||
this.sendOperationIfNeed();
|
this.sendOperationIfNeed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ class Server {
|
|||||||
|
|
||||||
// 每当从客户端接收到操作时调用此方法
|
// 每当从客户端接收到操作时调用此方法
|
||||||
receiveOperation(client: Client, revision: number, operation: TextOperation) {
|
receiveOperation(client: Client, revision: number, operation: TextOperation) {
|
||||||
console.log("server", "received operation", revision, operation);
|
console.log("server", "received operation from", client.name, revision, operation);
|
||||||
|
|
||||||
if (revision < 0 || this.operations.length < revision) {
|
if (revision < 0 || this.operations.length < revision) {
|
||||||
throw new Error("operation revision not in history");
|
throw new Error("operation revision not in history");
|
||||||
|
|||||||
Reference in New Issue
Block a user