Skip to content

Commit

Permalink
sync: readSyncMessage accepts origin parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Apr 26, 2019
1 parent 60c5e74 commit 76eb674
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
"homepage": "https://github.com/y-js/y-protocols#readme",
"dependencies": {},
"devDependencies": {
"lib0": "0.0.1",
"lib0": "0.0.2",
"rollup": "^1.1.2",
"rollup-cli": "^1.0.9",
"standard": "^12.0.1",
"yjs": "file:../yjs"
},
"peerDependenies": {
"lib0": "^0.0.1",
"lib0": "*",
"yjs": "*"
}
}
7 changes: 4 additions & 3 deletions sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,21 @@ export const readUpdate = Y.readModel
* @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.Y} y
* @param {any} origin
*/
export const readSyncMessage = (decoder, encoder, y) => {
export const readSyncMessage = (decoder, encoder, y, origin) => {
const messageType = decoding.readVarUint(decoder)
switch (messageType) {
case messageYjsSyncStep1:
readSyncStep1(decoder, encoder, y.store)
break
case messageYjsSyncStep2:
// @ts-ignore
y.transact(transaction => readSyncStep2(decoder, transaction, y.store))
y.transact(transaction => readSyncStep2(decoder, transaction, y.store), origin)
break
case messageYjsUpdate:
// @ts-ignore
y.transact(transaction => readUpdate(decoder, transaction, y.store))
y.transact(transaction => readUpdate(decoder, transaction, y.store), origin)
break
default:
throw new Error('Unknown message type')
Expand Down

0 comments on commit 76eb674

Please sign in to comment.