fireproof-storage / fireproof-alpha

🔥 Cloudless realtime database
https://fireproof.storage
Other
81 stars 4 forks source link

Live Sync #92

Closed jchris closed 1 year ago

jchris commented 1 year ago

This adds live sync, usage:

(db A and B are on two different machines)

async function setupSync (dbA, dbB) {
  const sync = new Sync(dbA, MockPeer)
  const sync2 = new Sync(dbB, MockPeer)

  const offer = await sync.offer()
  const accept = await sync2.accept(offer)

  // test stuff
  sync.peer.that = sync2.peer
  sync2.peer.that = sync.peer

  sync.connect(accept)
  const result = await sync.backlog()
  assert(result)
  assert.equal(result.ok, true)

  const resultB = await sync2.backlog()
  assert(resultB)
  assert.equal(resultB.ok, true)
}