y-webworker
v0.1.5
Published
Web Worker Connector for Yjs (enables communication with a Web Worker)
Downloads
11
Maintainers
Readme
Web Worker Connector for Yjs
It enables communication with a SharedWorker thread. The Shared Worker can handle connections, and save changes using a persistent database (e.g. y-indexeddb), while the clients connect to the shared worker leveraging improved performance. You can also set it up to perform background tasks in the Shared Worker.
In the future you may want set up a Service Worker that keeps the Shared Worker running even after the page is closed - thus enabling synchronization after the page is closed. But this is not yet supported - see issue
- Only the Shared Worker connects to the server / other clients (less connection overhead)
- Works best with y-indexeddb
- Faster start-up when multiple windows are open
- Background tasks
Use it!
Retrieve this with bower or npm.
NPM
npm install y-webworker --save
Bower
bower install y-webworker --save
Example
// Connect to the web worker
Y({
db: {
name: 'memory'
},
connector: {
name: 'webworker',
url: '/bower_components/y-webworker/yjs-webworker.js',
room: 'my room name'
},
sourceDir: '/bower_components', // location of the y-* modules
share: {
textarea: 'Text' // y.share.textarea is of type Y.Text
}
}).then(function (y) {
// bind the textarea to a shared text element
y.share.textarea.bind(document.getElementById('textfield'))
}
Modify yjs-webworker.js
The default behavior of yjs-webworker.js
is to use y-indexeddb, and connect to the default server using y-websockets-client.
For productive systems you should copy & modify the file for your set-up.
License
y-webworker is licensed under the MIT License.