Compare commits

..

6 Commits

Author SHA1 Message Date
Kevin Jahns
eeacb5665a v13.0.0-21 -- distribution files 2017-10-02 15:52:23 +02:00
Kevin Jahns
c8ca80d15f 13.0.0-21 2017-10-02 15:52:11 +02:00
Kevin Jahns
be282c8338 fix lint 2017-10-02 15:50:56 +02:00
Kevin Jahns
829a094c6d check for responsiveness when maxBufferSize is set 2017-10-02 15:45:23 +02:00
Kevin Jahns
725273167e 13.0.0-20 2017-09-29 22:34:18 +02:00
Kevin Jahns
581264c5e3 implement relative position helper 2017-09-29 22:33:28 +02:00
8 changed files with 130 additions and 12 deletions

View File

@@ -7,9 +7,9 @@ Y({
},
connector: {
name: 'websockets-client',
// url: 'http://127.0.0.1:1234',
url: 'http://192.168.178.81:1234',
url: 'http://127.0.0.1:1234',
room: 'html-editor-example6'
// maxBufferLength: 100
},
share: {
xml: 'XmlFragment()' // y.share.xml is of type Y.Xml with tagname "p"

View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "13.0.0-19",
"version": "13.0.0-21",
"description": "A framework for real-time p2p shared editing on any data",
"main": "./y.node.js",
"browser": "./y.js",

View File

@@ -213,7 +213,7 @@ export default function extendConnector (Y/* :any */) {
self.broadcastOpBuffer = ops.slice(i)
self.broadcast(encoder.createBuffer())
if (i !== length) {
setTimeout(broadcastOperations, 100)
self.whenRemoteResponsive().then(broadcastOperations)
}
}
}
@@ -225,6 +225,20 @@ export default function extendConnector (Y/* :any */) {
}
}
/*
* Somehow check the responsiveness of the remote clients/server
* Default behavior:
* Wait 100ms before broadcasting the next batch of operations
*
* Only used when maxBufferLength is set
*
*/
whenRemoteResponsive () {
return new Promise(function (resolve) {
setTimeout(resolve, 100)
})
}
/*
You received a raw message, and you know that it is intended for Yjs. Then call this function.
*/

View File

@@ -49,6 +49,51 @@ export default function Utils (Y) {
}
}
Y.utils.getRelativePosition = function (type, offset) {
if (type == null) {
return null
} else {
if (type._content.length <= offset) {
return ['endof', type._model[0], type._model[1]]
} else {
return type._content[offset].id
}
}
}
Y.utils.fromRelativePosition = function (y, id) {
var offset = 0
var op
if (id[0] === 'endof') {
id = y.db.os.find(id.slice(1)).end
op = y.db.os.findNodeWithUpperBound(id).val
if (!op.deleted) {
offset = op.content != null ? op.content.length : 1
}
} else {
op = y.db.os.findNodeWithUpperBound(id).val
if (!op.deleted) {
offset = id[1] - op.id[1]
}
}
var type = y.db.getType(op.parent)
if (type == null || y.db.os.find(op.parent).deleted) {
return null
}
while (op.left != null) {
op = y.db.os.findNodeWithUpperBound(op.left).val
if (!op.deleted) {
offset += op.content != null ? op.content.length : 1
}
}
return {
type: type,
offset: offset
}
}
class NamedEventHandler {
constructor () {
this._eventListener = {}

8
y.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
/**
* yjs - A framework for real-time p2p shared editing on any data
* @version v13.0.0-19
* @version v13.0.0-21
* @license MIT
*/
@@ -841,7 +841,7 @@ function extendConnector (Y/* :any */) {
self.broadcastOpBuffer = ops.slice(i);
self.broadcast(encoder.createBuffer());
if (i !== length) {
setTimeout(broadcastOperations, 100);
self.whenRemoteResponsive().then(broadcastOperations);
}
}
}
@@ -853,6 +853,20 @@ function extendConnector (Y/* :any */) {
}
}
/*
* Somehow check the responsiveness of the remote clients/server
* Default behavior:
* Wait 100ms before broadcasting the next batch of operations
*
* Only used when maxBufferLength is set
*
*/
whenRemoteResponsive () {
return new Promise(function (resolve) {
setTimeout(resolve, 100);
})
}
/*
You received a raw message, and you know that it is intended for Yjs. Then call this function.
*/
@@ -3448,6 +3462,51 @@ function Utils (Y) {
}
};
Y.utils.getRelativePosition = function (type, offset) {
if (type == null) {
return null
} else {
if (type._content.length <= offset) {
return ['endof', type._model[0], type._model[1]]
} else {
return type._content[offset].id
}
}
};
Y.utils.fromRelativePosition = function (y, id) {
var offset = 0;
var op;
if (id[0] === 'endof') {
id = y.db.os.find(id.slice(1)).end;
op = y.db.os.findNodeWithUpperBound(id).val;
if (!op.deleted) {
offset = op.content != null ? op.content.length : 1;
}
} else {
op = y.db.os.findNodeWithUpperBound(id).val;
if (!op.deleted) {
offset = id[1] - op.id[1];
}
}
var type = y.db.getType(op.parent);
if (type == null || y.db.os.find(op.parent).deleted) {
return null
}
while (op.left != null) {
op = y.db.os.findNodeWithUpperBound(op.left).val;
if (!op.deleted) {
offset += op.content != null ? op.content.length : 1;
}
}
return {
type: type,
offset: offset
}
};
class NamedEventHandler {
constructor () {
this._eventListener = {};

File diff suppressed because one or more lines are too long