From be68a25904bd30f4c88c8e5dd53501084bee97d4 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Tue, 23 Feb 2016 11:21:37 +0100 Subject: [PATCH] Implement vesion header. Different version headers must not sync. implements #48 --- .gitignore | 1 + src/Connector.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/.gitignore b/.gitignore index 383bd88b..13da2938 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ build_test /y.js /y.js.map /y-* +.vscode \ No newline at end of file diff --git a/src/Connector.js b/src/Connector.js index 74af6f1d..00c74e89 100644 --- a/src/Connector.js +++ b/src/Connector.js @@ -51,6 +51,7 @@ module.exports = function (Y/* :any */) { this.broadcastedHB = false this.syncStep2 = Promise.resolve() this.broadcastOpBuffer = [] + this.protocolVersion = 8 } reconnect () { } @@ -207,6 +208,18 @@ module.exports = function (Y/* :any */) { if (this.debug) { console.log(`receive ${sender} -> ${this.userId}: ${message.type}`, JSON.parse(JSON.stringify(message))) // eslint-disable-line } + if (message.protocolVersion != null && message.protocolVersion !== this.protocolVersion) { + console.error( + `You tried to sync with a yjs instance that has a different protocol version + (You: ${this.protocolVersion}, Client: ${message.protocolVersion}). + The sync was stopped. You need to upgrade your dependencies (especially Yjs & the Connector)! + `) + this.send(sender, { + type: 'sync stop', + protocolVersion: this.protocolVersion + }) + return + } if (message.type === 'sync step 1') { // TODO: make transaction, stream the ops let conn = this