From e16195cb542f5467ec003f6da6a442cefa4bf294 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 14 Aug 2017 15:39:17 +0200 Subject: [PATCH 1/4] implement timeout for creating Yjs instance --- examples/textarea/index.js | 7 +++++-- src/y.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/textarea/index.js b/examples/textarea/index.js index d58ab9d1..e40bba32 100644 --- a/examples/textarea/index.js +++ b/examples/textarea/index.js @@ -12,17 +12,20 @@ Y({ connector: { name: 'websockets-client', room: 'Textarea-example', - url: url || 'http://127.0.0.1:1234' + url: 'https://yjs-v13.herokuapp.com/' }, sourceDir: '/bower_components', share: { textarea: 'Text', // y.share.textarea is of type Y.Text test: 'Array' - } + }, + timeout: 5000 // reject if no connection was established within 5 seconds }).then(function (y) { window.yTextarea = y // bind the textarea to a shared text element y.share.textarea.bind(document.getElementById('textfield')) // thats it.. +}).catch(() => { + console.log('Something went wrong while creating the instance..') }) diff --git a/src/y.js b/src/y.js index 0dd86e43..f96594a7 100644 --- a/src/y.js +++ b/src/y.js @@ -139,10 +139,20 @@ export default function Y (opts/* :YOptions */) /* :Promise */ { opts.share = Y.utils.copyObject(opts.share) Y.requestModules(modules).then(function () { var yconfig = new YConfig(opts) + let resolved = false + if (opts.timeout != null && opts.timeout >= 0) { + setTimeout(function () { + if (!resolved) { + reject(new Error('Yjs init timeout')) + yconfig.destroy() + } + }, opts.timeout) + } yconfig.db.whenUserIdSet(function () { yconfig.init(function () { + resolved = true resolve(yconfig) - }) + }, reject) }) }).catch(reject) } From 6e633d0bd9f357f5b9a272bcf4506c47577bd541 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 14 Aug 2017 15:41:37 +0200 Subject: [PATCH 2/4] lint --- examples/textarea/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/textarea/index.js b/examples/textarea/index.js index e40bba32..11448d6c 100644 --- a/examples/textarea/index.js +++ b/examples/textarea/index.js @@ -2,7 +2,6 @@ // eslint-disable-next-line let search = new URLSearchParams(location.search) -let url = search.get('url') // initialize a shared object. This function call returns a promise! Y({ From 9ed7e15d0f4292161d705dc3e928bf37d8bd40b7 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 14 Aug 2017 15:49:15 +0200 Subject: [PATCH 3/4] 13.0.0-14 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 572cfd7e..8dd60c64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yjs", - "version": "13.0.0-13", + "version": "13.0.0-14", "description": "A framework for real-time p2p shared editing on any data", "main": "./y.node.js", "browser": "./y.js", From 0455eaa8adf0336cb37498f431e7d77f1dac5d2c Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 14 Aug 2017 15:53:54 +0200 Subject: [PATCH 4/4] 13.0.0-15 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8dd60c64..348793de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yjs", - "version": "13.0.0-14", + "version": "13.0.0-15", "description": "A framework for real-time p2p shared editing on any data", "main": "./y.node.js", "browser": "./y.js",