https://github.com/y-js/y-webworker
Web Worker Connector for Yjs (enables communication with a Web Worker)
https://github.com/y-js/y-webworker
yjs yjs-connector
Last synced: about 1 month ago
JSON representation
Web Worker Connector for Yjs (enables communication with a Web Worker)
- Host: GitHub
- URL: https://github.com/y-js/y-webworker
- Owner: y-js
- License: mit
- Created: 2016-11-15T14:49:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-03T17:16:47.000Z (about 8 years ago)
- Last Synced: 2025-04-10T21:10:00.954Z (about 1 month ago)
- Topics: yjs, yjs-connector
- Language: JavaScript
- Homepage:
- Size: 26.4 KB
- Stars: 6
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Web Worker Connector for [Yjs](https://github.com/y-js/yjs)
It enables communication with a [SharedWorker](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/SharedWorker) thread.
The Shared Worker can handle connections, and save changes using a persistent database (e.g. [y-indexeddb](https://github.com/y-js/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](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API)
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](https://github.com/whatwg/html/issues/411)* 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
```bash
npm install y-webworker --save
```##### Bower
```bash
bower install y-webworker --save
```### Example
```javascript
// 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](https://github.com/y-js/y-webworker) is licensed under the [MIT License](./LICENSE).