From 829a094c6d43917d5c0e4bc84b8eb5f9bf4a7fe8 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 2 Oct 2017 15:45:23 +0200 Subject: [PATCH] check for responsiveness when maxBufferSize is set --- examples/html-editor/index.js | 3 ++- src/Connector.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/examples/html-editor/index.js b/examples/html-editor/index.js index db4bd6ff..0a2668fd 100644 --- a/examples/html-editor/index.js +++ b/examples/html-editor/index.js @@ -8,7 +8,8 @@ Y({ connector: { name: 'websockets-client', url: 'http://127.0.0.1:1234', - room: 'html-editor-example6' + room: 'html-editor-example6', + // maxBufferLength: 100 }, share: { xml: 'XmlFragment()' // y.share.xml is of type Y.Xml with tagname "p" diff --git a/src/Connector.js b/src/Connector.js index 3033d0d6..5bcba919 100644 --- a/src/Connector.js +++ b/src/Connector.js @@ -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. */