Skip to content

Commit

Permalink
await for collab to be RDY before we pop off
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Oct 3, 2024
1 parent 26a744d commit b62b40d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion public/automerge/collab.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ async function withAutomergeRepo(fn) {
}

export function fancy() {
return !!repo
return Boolean(repo?.networkSubsystem.isReady())
}

/**
*
* @param {SharedArrayBuffer} sab
* @returns
*/
export async function init(sab) {
if (repo) return
sharedarraybuffer = sab
Expand Down
6 changes: 3 additions & 3 deletions public/bento.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function getFancy() {
await sounds.loadDefaultKit()
}
}
if (isAutomerge) {
if (isAutomerge && !collab.fancy()) {
await collab.init(sharedarraybuffer)
await collab.start(
/** @type {import("@automerge/automerge-repo").AutomergeUrl}*/ (slug),
Expand Down Expand Up @@ -652,15 +652,15 @@ party.settings.when("jam", async () => {
collab.stop()
party.slug = slug
party.tree = memtree
collab.start(slug, memtree)
await collab.start(slug, memtree)
})

addEventListener("popstate", async () => {
let slug = history.state?.slug || "bento"
collab.stop()
if (isValidAutomergeUrl(slug)) {
await collab.init()
collab.start(slug, memtree)
await collab.start(slug, memtree)
} else {
await db.load(slug)
}
Expand Down

0 comments on commit b62b40d

Please sign in to comment.