Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2650338b4b | ||
|
|
919dfb5e16 | ||
|
|
3b8e148d8f | ||
|
|
a77eb39218 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
||||
node_modules
|
||||
./Examples/bower_components
|
||||
bower_components
|
||||
.directory
|
||||
.codio
|
||||
.settings
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "yjs",
|
||||
"version": "0.8.2",
|
||||
"version": "0.8.6",
|
||||
"homepage": "y-js.org",
|
||||
"authors": [
|
||||
"Kevin Jahns <kevin.jahns@rwth-aachen.de>"
|
||||
|
||||
71
y.es6
71
y.es6
@@ -51,6 +51,7 @@ module.exports = function (Y/* :any */) {
|
||||
this.debug = opts.debug === true
|
||||
this.broadcastedHB = false
|
||||
this.syncStep2 = Promise.resolve()
|
||||
this.broadcastOpBuffer = []
|
||||
}
|
||||
reconnect () {
|
||||
}
|
||||
@@ -167,6 +168,34 @@ module.exports = function (Y/* :any */) {
|
||||
console.log(`send ${this.userId} -> ${uid}: ${message.type}`, message) // eslint-disable-line
|
||||
}
|
||||
}
|
||||
/*
|
||||
Buffer operations, and broadcast them when ready.
|
||||
*/
|
||||
broadcastOps (ops) {
|
||||
ops = ops.map(function (op) {
|
||||
return Y.Struct[op.struct].encode(op)
|
||||
})
|
||||
var self = this
|
||||
function broadcastOperations () {
|
||||
if (self.broadcastOpBuffer.length > 0) {
|
||||
self.broadcast({
|
||||
type: 'update',
|
||||
ops: self.broadcastOpBuffer
|
||||
})
|
||||
self.broadcastOpBuffer = []
|
||||
}
|
||||
}
|
||||
if (this.broadcastOpBuffer.length === 0) {
|
||||
this.broadcastOpBuffer = ops
|
||||
if (this.y.db.transactionInProgress) {
|
||||
this.y.db.whenTransactionsFinished().then(broadcastOperations)
|
||||
} else {
|
||||
setTimeout(broadcastOperations, 0)
|
||||
}
|
||||
} else {
|
||||
this.broadcastOpBuffer = this.broadcastOpBuffer.concat(ops)
|
||||
}
|
||||
}
|
||||
/*
|
||||
You received a raw message, and you know that it is intended for Yjs. Then call this function.
|
||||
*/
|
||||
@@ -227,15 +256,14 @@ module.exports = function (Y/* :any */) {
|
||||
db.requestTransaction(function * () {
|
||||
var ops = yield* this.getOperations(m.stateSet)
|
||||
if (ops.length > 0) {
|
||||
var update /* :MessageUpdate */ = {
|
||||
type: 'update',
|
||||
ops: ops
|
||||
}
|
||||
if (!broadcastHB) { // TODO: consider to broadcast here..
|
||||
conn.send(sender, update)
|
||||
conn.send(sender, {
|
||||
type: 'update',
|
||||
ops: ops
|
||||
})
|
||||
} else {
|
||||
// broadcast only once!
|
||||
conn.broadcast(update)
|
||||
conn.broadcastOps(ops)
|
||||
}
|
||||
}
|
||||
defer.resolve()
|
||||
@@ -257,10 +285,7 @@ module.exports = function (Y/* :any */) {
|
||||
return o.struct === 'Delete'
|
||||
})
|
||||
if (delops.length > 0) {
|
||||
this.broadcast({
|
||||
type: 'update',
|
||||
ops: delops
|
||||
})
|
||||
this.broadcastOps(delops)
|
||||
}
|
||||
}
|
||||
this.y.db.apply(message.ops)
|
||||
@@ -1406,10 +1431,7 @@ module.exports = function (Y/* :any */) {
|
||||
}
|
||||
if (!this.store.y.connector.isDisconnected() && send.length > 0) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops)
|
||||
// is connected, and this is not going to be send in addOperation
|
||||
this.store.y.connector.broadcast({
|
||||
type: 'update',
|
||||
ops: send
|
||||
})
|
||||
this.store.y.connector.broadcastOps(send)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1805,10 +1827,7 @@ module.exports = function (Y/* :any */) {
|
||||
var ops = deletions.map(function (d) {
|
||||
return {struct: 'Delete', target: [d[0], d[1]]}
|
||||
})
|
||||
this.store.y.connector.broadcast({
|
||||
type: 'update',
|
||||
ops: ops
|
||||
})
|
||||
this.store.y.connector.broadcastOps(ops)
|
||||
}
|
||||
}
|
||||
* isGarbageCollected (id) {
|
||||
@@ -1846,10 +1865,7 @@ module.exports = function (Y/* :any */) {
|
||||
yield* this.os.put(op)
|
||||
if (!this.store.y.connector.isDisconnected() && this.store.forwardAppliedOperations && op.id[0] !== '_') {
|
||||
// is connected, and this is not going to be send in addOperation
|
||||
this.store.y.connector.broadcast({
|
||||
type: 'update',
|
||||
ops: [op]
|
||||
})
|
||||
this.store.y.connector.broadcastOps([op])
|
||||
}
|
||||
}
|
||||
* getOperation (id/* :any */)/* :Transaction<any> */ {
|
||||
@@ -2028,7 +2044,7 @@ module.exports = function (Y/* :any */) {
|
||||
}
|
||||
})
|
||||
}
|
||||
return send
|
||||
return send.reverse()
|
||||
}
|
||||
/* this is what we used before.. use this as a reference..
|
||||
* makeOperationReady (startSS, op) {
|
||||
@@ -2385,8 +2401,9 @@ function Y (opts/* :YOptions */) /* :Promise<YConfig> */ {
|
||||
Y.sourceDir = opts.sourceDir
|
||||
return Y.requestModules(modules).then(function () {
|
||||
return new Promise(function (resolve) {
|
||||
var yconfig = new YConfig(opts, function () {
|
||||
yconfig.db.whenUserIdSet(function () {
|
||||
var yconfig = new YConfig(opts)
|
||||
yconfig.db.whenUserIdSet(function () {
|
||||
yconfig.init(function () {
|
||||
resolve(yconfig)
|
||||
})
|
||||
})
|
||||
@@ -2403,6 +2420,10 @@ class YConfig {
|
||||
constructor (opts, callback) {
|
||||
this.db = new Y[opts.db.name](this, opts.db)
|
||||
this.connector = new Y[opts.connector.name](this, opts.connector)
|
||||
this.options = opts
|
||||
}
|
||||
init (callback) {
|
||||
var opts = this.options
|
||||
var share = {}
|
||||
this.share = share
|
||||
this.db.requestTransaction(function * requestTransaction () {
|
||||
|
||||
Reference in New Issue
Block a user