Skip to content

Commit

Permalink
experiment with newer version
Browse files Browse the repository at this point in the history
  • Loading branch information
gempir committed Feb 4, 2024
1 parent 0085063 commit f47c9c8
Show file tree
Hide file tree
Showing 3 changed files with 295 additions and 180 deletions.
7 changes: 4 additions & 3 deletions web/yjs/callback.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
const http = require('http')

const CALLBACK_URL = process.env.CALLBACK_URL ? new URL(process.env.CALLBACK_URL) : null
Expand All @@ -14,7 +15,7 @@ exports.isCallbackSet = !!CALLBACK_URL
exports.callbackHandler = (update, origin, doc) => {
const room = doc.name
const dataToSend = {
room,
room: room,
data: {}
}
const sharedObjectList = Object.keys(CALLBACK_OBJECTS)
Expand All @@ -39,7 +40,7 @@ const callbackRequest = (url, timeout, data) => {
hostname: url.hostname,
port: url.port,
path: url.pathname,
timeout,
timeout: timeout,
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -73,4 +74,4 @@ const getContent = (objName, objType, doc) => {
case 'XmlElement': return doc.getXmlElement(objName)
default : return {}
}
}
}
34 changes: 34 additions & 0 deletions web/yjs/readSyncMessageFork.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @ts-nocheck
const syncProtocol = require('y-protocols/dist/sync.cjs')

const decoding = require('lib0/dist/decoding.cjs')

/**
* @param {decoding.Decoder} decoder A message received from another client
* @param {encoding.Encoder} encoder The reply message. Will not be sent if empty.
* @param {Y.Doc} doc
* @param {boolean} readOnly If true, updates will be silently ignored instead of applied.
* @param {any} transactionOrigin
* @returns {number|undefined}
*/
const readSyncMessage = (decoder, encoder, doc, readOnly = false, transactionOrigin) => {
const messageType = decoding.readVarUint(decoder)
switch (messageType) {
case syncProtocol.messageYjsSyncStep1:
syncProtocol.readSyncStep1(decoder, encoder, doc)
break
case syncProtocol.messageYjsSyncStep2:
if (readOnly) return
syncProtocol.readSyncStep2(decoder, doc, transactionOrigin)
break
case syncProtocol.messageYjsUpdate:
if (readOnly) return
syncProtocol.readUpdate(decoder, doc, transactionOrigin)
break
default:
throw new Error('Unknown message type')
}
return messageType
}

module.exports = { readSyncMessage }
Loading

0 comments on commit f47c9c8

Please sign in to comment.