Я использую следующий код для установки изменений byte[] от клиентов: Ydoc — один из опор
Код: Выделить всё
public void ApplyUpdate(byte[] clientUpdate)
{
if (clientUpdate == null || clientUpdate.Length == 0)
return;
lock (_stateLock)
{
using (var transaction = YDoc.WriteTransaction())
{
transaction.ApplyV1(clientUpdate);
transaction.Commit();
}
LastActivity = DateTime.UtcNow;
}
}
Код: Выделить всё
public byte[] GetFullState()
{
lock (_stateLock)
{
using (var transaction = YDoc.ReadTransaction())
{
var stateVector = transaction.StateVectorV1();
if (stateVector == null || stateVector.Length == 0)
{
// Document is empty, return empty array
return Array.Empty();
}
// Get the entire document state
var state = transaction.StateDiffV1(Array.Empty());
return state ?? Array.Empty();
}
}
}
Код: Выделить всё
Value cannot be null. (Parameter 'source')
Код: Выделить всё
const ydocA = useMemo(() => new Y.Doc(), [])
const sharedTypeA = useMemo(
() => ydocA.get('slate', Y.XmlText),
[ydocA]
)
const editorA = useMemo(() => {
const e = withReact(createEditor())
const yEditor = withYjs(e, sharedTypeA)
return withYHistory(yEditor)
}, [sharedTypeA])
useEffect(() => {
YjsEditor.connect(editorA)
return () => {
YjsEditor.disconnect(editorA)
}
}, [editorA])
Подробнее здесь: https://stackoverflow.com/questions/798 ... et-package
Мобильная версия