Skip to content

Commit

Permalink
Implement vesion header. Different version headers must not sync. imp…
Browse files Browse the repository at this point in the history
…lements #48
  • Loading branch information
dmonad committed Feb 23, 2016
1 parent fc92b12 commit be68a25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build_test
/y.js
/y.js.map
/y-*
.vscode
13 changes: 13 additions & 0 deletions src/Connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports = function (Y/* :any */) {
this.broadcastedHB = false
this.syncStep2 = Promise.resolve()
this.broadcastOpBuffer = []
this.protocolVersion = 8
}
reconnect () {
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit be68a25

Please sign in to comment.