How to use the lib0/encoding.js.toUint8Array function in lib0

To help you get started, we’ve selected a few lib0 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yjs / yjs / src / utils / Transaction.js View on Github external
const clock = mid.clock
        const structs = /** @type {Array} */ (store.clients.get(client))
        const replacedStructPos = findIndexSS(structs, clock)
        if (replacedStructPos + 1 < structs.length) {
          tryToMergeWithLeft(structs, replacedStructPos + 1)
        }
        if (replacedStructPos > 0) {
          tryToMergeWithLeft(structs, replacedStructPos)
        }
      }
      // @todo Merge all the transactions into one and provide send the data as a single update message
      doc.emit('afterTransactionCleanup', [transaction, doc])
      if (doc._observers.has('update')) {
        const updateMessage = computeUpdateMessageFromTransaction(transaction)
        if (updateMessage !== null) {
          doc.emit('update', [encoding.toUint8Array(updateMessage), transaction.origin, doc])
        }
      }
      if (transactionCleanups.length <= i + 1) {
        doc._transactionCleanups = []
      } else {
        cleanupTransactions(transactionCleanups, i + 1)
      }
    }
  }
}
github yjs / y-webrtc / src / y-webrtc.js View on Github external
connect () {
    // signal through all available signaling connections
    announceSignalingInfo(this)
    const roomName = this.name
    bc.subscribe(roomName, this._bcSubscriber)
    this.bcconnected = true
    // broadcast peerId via broadcastchannel
    broadcastBcPeerId(this)
    // write sync step 1
    const encoderSync = encoding.createEncoder()
    encoding.writeVarUint(encoderSync, messageSync)
    syncProtocol.writeSyncStep1(encoderSync, this.doc)
    broadcastBcMessage(this, encoding.toUint8Array(encoderSync))
    // broadcast local state
    const encoderState = encoding.createEncoder()
    encoding.writeVarUint(encoderState, messageSync)
    syncProtocol.writeSyncStep2(encoderState, this.doc)
    broadcastBcMessage(this, encoding.toUint8Array(encoderState))
    // write queryAwareness
    const encoderAwarenessQuery = encoding.createEncoder()
    encoding.writeVarUint(encoderAwarenessQuery, messageQueryAwareness)
    broadcastBcMessage(this, encoding.toUint8Array(encoderAwarenessQuery))
    // broadcast local awareness state
    const encoderAwarenessState = encoding.createEncoder()
    encoding.writeVarUint(encoderAwarenessState, messageAwareness)
    encoding.writeVarUint8Array(encoderAwarenessState, awarenessProtocol.encodeAwarenessUpdate(this.awareness, [this.doc.clientID]))
    broadcastBcMessage(this, encoding.toUint8Array(encoderAwarenessState))
  }
  disconnect () {
github yjs / yjs / examples / prosemirror-history.js View on Github external
snapshot (updatedUserMap = new Map()) {
    const y = prosemirrorPluginKey.getState(this.editorView.state).y
    const history = y.define('history', Y.Array)
    const encoder = encoding.createEncoder()
    historyProtocol.writeHistorySnapshot(encoder, y, updatedUserMap)
    encoding.writeUint32(encoder, Math.floor(Date.now() / 1000))
    history.push([encoding.toUint8Array(encoder)])
  }
}
github yjs / y-webrtc / src / y-webrtc.js View on Github external
const sendWebrtcConn = (webrtcConn, encoder) => {
  log('send message to ', logging.BOLD, webrtcConn.remotePeerId, logging.UNBOLD, logging.GREY, ' (', webrtcConn.room.name, ')', logging.UNCOLOR)
  try {
    webrtcConn.peer.send(encoding.toUint8Array(encoder))
  } catch (e) {}
}
github yjs / yjs / src / utils / Snapshot.js View on Github external
export const encodeSnapshot = snapshot => {
  const encoder = encoding.createEncoder()
  writeDeleteSet(encoder, snapshot.ds)
  writeStateVector(encoder, snapshot.sv)
  return encoding.toUint8Array(encoder)
}
github yjs / y-webrtc / src / y-webrtc.js View on Github external
this.mux(() => {
          const reply = readMessage(this, m, () => {})
          if (reply) {
            broadcastBcMessage(this, encoding.toUint8Array(reply))
          }
        })
      )
github yjs / yjs / src / utils / PermanentUserData.js View on Github external
setTimeout(() => {
        const yds = user.get('ds')
        const ds = transaction.deleteSet
        if (transaction.local && ds.clients.size > 0) {
          const encoder = encoding.createEncoder()
          writeDeleteSet(encoder, ds)
          yds.push([encoding.toUint8Array(encoder)])
        }
      })
    })
github yjs / yjs / src / utils / RelativePosition.js View on Github external
export const encodeRelativePosition = rpos => {
  const encoder = encoding.createEncoder()
  writeRelativePosition(encoder, rpos)
  return encoding.toUint8Array(encoder)
}