An open API service indexing awesome lists of open source software.

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)

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).