merged changes on home pc. some improvements on rejoin&sync

This commit is contained in:
Kevin Jahns
2015-09-27 00:58:23 +02:00
8 changed files with 141 additions and 74 deletions

View File

@@ -22,6 +22,7 @@ class AbstractConnector {
}
this.role = opts.role
this.connections = {}
this.isSynced = false
this.userEventListeners = []
this.whenSyncedListeners = []
this.currentSyncTarget = null
@@ -97,7 +98,7 @@ class AbstractConnector {
true otherwise
*/
findNextSyncTarget () {
if (this.currentSyncTarget != null) {
if (this.currentSyncTarget != null || this.isSynced) {
return // "The current sync has not finished!"
}
@@ -118,19 +119,18 @@ class AbstractConnector {
deleteSet: yield* this.getDeleteSet()
})
})
}
// This user synced with at least one user, set the state to synced (TODO: does this suffice?)
if (!this.isSynced) {
} else {
this.isSynced = true
for (var f of this.whenSyncedListeners) {
f()
}
this.whenSyncedListeners = []
this.y.db.garbageCollectAfterSync()
}
}
send (uid, message) {
if (this.debug) {
console.log(`me -> ${uid}: ${message.type}`, m);// eslint-disable-line
console.log(`send ${this.userId} -> ${uid}: ${message.type}`, m);// eslint-disable-line
}
}
/*
@@ -141,36 +141,26 @@ class AbstractConnector {
return
}
if (this.debug) {
console.log(`${sender} -> me: ${m.type}`, m);// eslint-disable-line
if (m.os != null && m.os.some(function(o){return o.deleted })){
console.log("bullshit.. ")
debugger
}
console.log(`receive ${sender} -> ${this.userId}: ${m.type}`, m);// eslint-disable-line
}
if (m.type === 'sync step 1') {
// TODO: make transaction, stream the ops
let conn = this
this.y.db.requestTransaction(function *() {
var currentStateSet = yield* this.getStateSet()
var dels = yield* this.getOpsFromDeleteSet(m.deleteSet)
for (var i in dels) {
// TODO: no longer get delete ops (just get the ids..)!
yield* Y.Struct.Delete.delete.call(this, dels[i].target)
}
var ops = yield* this.getOperations(m.stateSet)
conn.send(sender, {
type: 'sync step 2',
os: ops,
stateSet: yield* this.getStateSet(),
deleteSet: yield* this.getDeleteSet() // TODO: consider that you have a ds from the other user..
stateSet: currentStateSet,
deleteSet: yield* this.getDeleteSet()
})
var dels = yield* this.getOpsFromDeleteSet(m.deleteSet)
if (dels.length > 0) {
for (var i in dels) {
// TODO: no longer get delete ops (just get the ids..)!
yield* Y.Struct.Delete.delete.call(this, dels[i].target)
}
/*/ broadcast missing dels from syncing client
this.store.y.connector.broadcast({
type: 'update',
ops: dels
})
*/
}
if (this.forwardToSyncingClients) {
conn.syncingClients.push(sender)
setTimeout(function () {
@@ -192,11 +182,13 @@ class AbstractConnector {
let conn = this
var broadcastHB = !this.broadcastedHB
this.broadcastedHB = true
this.y.db.requestTransaction(function *() {
var ops = yield* this.getOperations(m.stateSet)
this.y.db.requestTransaction(function * () {
var dels = yield* this.getOpsFromDeleteSet(m.deleteSet)
for (var i in dels) {
yield* Y.Struct.Delete.delete.call(this, dels[i].target)
}
var ops = yield* this.getOperations(m.stateSet)
this.store.apply(m.os)
this.store.apply(dels)
if (ops.length > 0) {
m = {
type: 'update',