added utilities to make and recover snapshots
This commit is contained in:
@@ -97,8 +97,8 @@ const broadcastUpdate = (y, transaction) => {
|
||||
}
|
||||
|
||||
class WebsocketsSharedDocument extends Y.Y {
|
||||
constructor (url) {
|
||||
super()
|
||||
constructor (url, opts) {
|
||||
super(opts)
|
||||
this.url = url
|
||||
this.wsconnected = false
|
||||
this.mux = Y.createMutex()
|
||||
@@ -112,7 +112,7 @@ class WebsocketsSharedDocument extends Y.Y {
|
||||
const encoder = readMessage(this, data) // already muxed
|
||||
this.mux(() => {
|
||||
if (Y.encoding.length(encoder) > 1) {
|
||||
bc.publish(url, Y.encoding.toBuffer(encoder))
|
||||
bc.publish(url, Y.encoding.toBuffer(encoder))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -173,10 +173,10 @@ export class WebsocketProvider {
|
||||
* @param {string} name
|
||||
* @return {WebsocketsSharedDocument}
|
||||
*/
|
||||
get (name) {
|
||||
get (name, opts) {
|
||||
let doc = this.docs.get(name)
|
||||
if (doc === undefined) {
|
||||
doc = new WebsocketsSharedDocument(this.url + name)
|
||||
doc = new WebsocketsSharedDocument(this.url + name, opts)
|
||||
}
|
||||
return doc
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ const http = require('http')
|
||||
|
||||
const port = process.env.PORT || 1234
|
||||
|
||||
// disable gc when using snapshots!
|
||||
const gcEnabled = process.env.GC !== 'false' && process.env.GC !== '0'
|
||||
const persistenceDir = process.env.YPERSISTENCE
|
||||
let persistence = null
|
||||
if (typeof persistenceDir === 'string') {
|
||||
@@ -44,7 +46,7 @@ const afterTransaction = (doc, transaction) => {
|
||||
|
||||
class WSSharedDoc extends Y.Y {
|
||||
constructor () {
|
||||
super({ gc: true })
|
||||
super({ gc: gcEnabled })
|
||||
this.mux = Y.createMutex()
|
||||
/**
|
||||
* Maps from conn to set of controlled user ids. Delete all user ids from awareness when this conn is closed
|
||||
@@ -150,4 +152,4 @@ server.on('upgrade', (request, socket, head) => {
|
||||
|
||||
server.listen(port)
|
||||
|
||||
console.log('running on port', port)
|
||||
console.log('running on port', port)
|
||||
|
||||
Reference in New Issue
Block a user