add serviceworker demo
This commit is contained in:
parent
20e3491a64
commit
e30e16c91b
@ -1,21 +1,31 @@
|
|||||||
/* global Y, Quill */
|
/* global Y, Quill */
|
||||||
|
|
||||||
|
// register yjs service worker
|
||||||
|
if('serviceWorker' in navigator){
|
||||||
|
// Register service worker
|
||||||
|
// it is important to copy yjs-sw-template to the root directory!
|
||||||
|
navigator.serviceWorker.register('./yjs-sw-template.js').then(function(reg){
|
||||||
|
console.log("Yjs service worker registration succeeded. Scope is " + reg.scope);
|
||||||
|
}).catch(function(err){
|
||||||
|
console.error("Yjs service worker registration failed with error " + err);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// initialize a shared object. This function call returns a promise!
|
// initialize a shared object. This function call returns a promise!
|
||||||
Y({
|
Y({
|
||||||
db: {
|
db: {
|
||||||
name: 'memory'
|
name: 'memory'
|
||||||
},
|
},
|
||||||
connector: {
|
connector: {
|
||||||
name: 'webworker',
|
name: 'serviceworker',
|
||||||
url: '../bower_components/y-webworker/yjs-webworker.js',
|
room: 'ServiceWorkerExample2'
|
||||||
room: 'WebWorkerExample2'
|
|
||||||
},
|
},
|
||||||
sourceDir: '/bower_components',
|
sourceDir: '/bower_components',
|
||||||
share: {
|
share: {
|
||||||
richtext: 'Richtext' // y.share.richtext is of type Y.Richtext
|
richtext: 'Richtext' // y.share.richtext is of type Y.Richtext
|
||||||
}
|
}
|
||||||
}).then(function (y) {
|
}).then(function (y) {
|
||||||
window.yQuill = y
|
window.yServiceWorker = y
|
||||||
|
|
||||||
// create quill element
|
// create quill element
|
||||||
window.quill = new Quill('#quill', {
|
window.quill = new Quill('#quill', {
|
22
Examples/ServiceWorker/yjs-sw-template.js
Normal file
22
Examples/ServiceWorker/yjs-sw-template.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* eslint-env worker */
|
||||||
|
|
||||||
|
// copy and modify this file
|
||||||
|
|
||||||
|
self.DBConfig = {
|
||||||
|
name: 'indexeddb'
|
||||||
|
}
|
||||||
|
self.ConnectorConfig = {
|
||||||
|
name: 'websockets-client',
|
||||||
|
// url: '..',
|
||||||
|
options: {
|
||||||
|
jsonp: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
importScripts(
|
||||||
|
'/bower_components/yjs/y.js',
|
||||||
|
'/bower_components/y-memory/y-memory.js',
|
||||||
|
'/bower_components/y-indexeddb/y-indexeddb.js',
|
||||||
|
'/bower_components/y-websockets-client/y-websockets-client.js',
|
||||||
|
'/bower_components/y-serviceworker/yjs-sw-include.js'
|
||||||
|
)
|
2
y.es6
2
y.es6
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* yjs - A framework for real-time p2p shared editing on any data
|
* yjs - A framework for real-time p2p shared editing on any data
|
||||||
* @version v12.1.6
|
* @version v12.1.7
|
||||||
* @link http://y-js.org
|
* @link http://y-js.org
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user