fix first y-array test
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import deleteItemRange from 'deleteItemRange'
|
||||
import { deleteItemRange } from '../Struct/Delete.js'
|
||||
|
||||
export function stringifyDeleteSet (y, decoder, strBuilder) {
|
||||
let dsLength = decoder.readUint32()
|
||||
@@ -48,7 +48,7 @@ export function writeDeleteSet (y, encoder) {
|
||||
if (currentUser !== null) { // happens on first iteration
|
||||
encoder.setUint32(lastLenPos, currentLength)
|
||||
}
|
||||
encoder.writeUint32(laterDSLenPus, numberOfUsers)
|
||||
encoder.setUint32(laterDSLenPus, numberOfUsers)
|
||||
}
|
||||
|
||||
export function readDeleteSet (y, decoder) {
|
||||
|
||||
@@ -45,7 +45,7 @@ export function integrateRemoteStructs (decoder, encoder, y) {
|
||||
let reference = decoder.readVarUint()
|
||||
let Constr = getStruct(reference)
|
||||
let struct = new Constr()
|
||||
let missing = struct._fromBinary(decoder)
|
||||
let missing = struct._fromBinary(y, decoder)
|
||||
if (missing.length === 0) {
|
||||
while (struct != null) {
|
||||
_integrateRemoteStructHelper(y, struct)
|
||||
|
||||
@@ -10,15 +10,14 @@ export function readStateSet (decoder) {
|
||||
return ss
|
||||
}
|
||||
|
||||
export function writeStateSet (encoder) {
|
||||
export function writeStateSet (y, encoder) {
|
||||
let lenPosition = encoder.pos
|
||||
let len = 0
|
||||
encoder.writeUint32(0)
|
||||
this.ss.iterate(null, null, function (n) {
|
||||
encoder.writeVarUint(n.id[0])
|
||||
encoder.writeVarUint(n.clock)
|
||||
for (let [user, clock] of y.ss.state) {
|
||||
encoder.writeVarUint(user)
|
||||
encoder.writeVarUint(clock)
|
||||
len++
|
||||
})
|
||||
}
|
||||
encoder.setUint32(lenPosition, len)
|
||||
return len === 0
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import BinaryEncoder from '../Binary/Encoder.js'
|
||||
import { readStateSet, writeStateSet } from './stateSet.js'
|
||||
import { writeDeleteSet } from './deleteSet.js'
|
||||
import ID from '../Util/ID.js'
|
||||
|
||||
export function stringifySyncStep1 (decoder, strBuilder) {
|
||||
let auth = decoder.readVarString()
|
||||
@@ -17,14 +20,22 @@ export function stringifySyncStep1 (decoder, strBuilder) {
|
||||
}
|
||||
}
|
||||
|
||||
export function sendSyncStep1 (y, syncUser) {
|
||||
export function sendSyncStep1 (connector, syncUser) {
|
||||
let encoder = new BinaryEncoder()
|
||||
encoder.writeVarString(y.room)
|
||||
encoder.writeVarString(connector.y.room)
|
||||
encoder.writeVarString('sync step 1')
|
||||
encoder.writeVarString(y.connector.authInfo || '')
|
||||
encoder.writeVarUint(y.connector.protocolVersion)
|
||||
y.ss.writeStateSet(encoder)
|
||||
y.connector.send(syncUser, encoder.createBuffer())
|
||||
encoder.writeVarString(connector.authInfo || '')
|
||||
encoder.writeVarUint(connector.protocolVersion)
|
||||
writeStateSet(connector.y, encoder)
|
||||
connector.send(syncUser, encoder.createBuffer())
|
||||
}
|
||||
|
||||
export default function writeStructs (encoder, decoder, y, ss) {
|
||||
for (let [user, clock] of ss) {
|
||||
y.os.iterate(new ID(user, clock), null, function (struct) {
|
||||
struct._toBinary(encoder)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function readSyncStep1 (decoder, encoder, y, senderConn, sender) {
|
||||
@@ -32,22 +43,20 @@ export function readSyncStep1 (decoder, encoder, y, senderConn, sender) {
|
||||
// check protocol version
|
||||
if (protocolVersion !== y.connector.protocolVersion) {
|
||||
console.warn(
|
||||
`You tried to sync with a yjs instance that has a different protocol version
|
||||
`You tried to sync with a Yjs instance that has a different protocol version
|
||||
(You: ${protocolVersion}, Client: ${protocolVersion}).
|
||||
The sync was stopped. You need to upgrade your dependencies (especially Yjs & the Connector)!
|
||||
`)
|
||||
y.destroy()
|
||||
}
|
||||
|
||||
// send sync step 2
|
||||
// write sync step 2
|
||||
encoder.writeVarString('sync step 2')
|
||||
encoder.writeVarString(y.connector.authInfo || '')
|
||||
writeDeleteSet(encoder)
|
||||
// reads ss and writes os
|
||||
writeOperations(encoder, decoder)
|
||||
writeDeleteSet(y, encoder)
|
||||
const ss = readStateSet(decoder)
|
||||
writeStructs(encoder, decoder, y, ss)
|
||||
y.connector.send(senderConn.uid, encoder.createBuffer())
|
||||
senderConn.receivedSyncStep2 = true
|
||||
if (y.connector.role === 'slave') {
|
||||
sendSyncStep1(y, sender)
|
||||
sendSyncStep1(y.connector, sender)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { integrateRemoteStructs } from './integrateRemoteStructs.js'
|
||||
import { stringifyUpdate } from './update.js'
|
||||
import ID from '../Util/ID.js'
|
||||
import { readDeleteSet } from './deleteSet.js'
|
||||
|
||||
export function stringifySyncStep2 (decoder, strBuilder) {
|
||||
strBuilder.push(' - auth: ' + decoder.readVarString() + '\n')
|
||||
@@ -22,27 +22,8 @@ export function stringifySyncStep2 (decoder, strBuilder) {
|
||||
}
|
||||
}
|
||||
|
||||
export function writeSyncStep2 () {
|
||||
// TODO
|
||||
}
|
||||
|
||||
export default function writeStructs (encoder, decoder, y, ss) {
|
||||
let lenPos = encoder.pos
|
||||
let len = 0
|
||||
encoder.writeUint32(0)
|
||||
for (let [user, clock] of ss) {
|
||||
y.os.iterate(new ID(user, clock), null, function (struct) {
|
||||
struct._toBinary(y, encoder)
|
||||
len++
|
||||
})
|
||||
}
|
||||
encoder.setUint32(lenPos, len)
|
||||
}
|
||||
|
||||
export function readSyncStep2 (decoder, encoder, y, senderConn, sender) {
|
||||
// apply operations first
|
||||
applyDeleteSet(decoder)
|
||||
readDeleteSet(y, decoder)
|
||||
integrateRemoteStructs(decoder, encoder, y)
|
||||
// then apply ds
|
||||
y.connector._setSyncedWith(sender)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user