Skip to content

Web Worker Connector for Yjs (enables communication with a Web Worker)

License

Notifications You must be signed in to change notification settings

y-js/y-webworker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

[email protected]

About

Web Worker Connector for Yjs (enables communication with a Web Worker)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published