diff --git a/public/automerge/collab.js b/public/automerge/collab.js index 6f60a5c..23dab89 100644 --- a/public/automerge/collab.js +++ b/public/automerge/collab.js @@ -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 diff --git a/public/bento.js b/public/bento.js index 8800e89..34a4a04 100644 --- a/public/bento.js +++ b/public/bento.js @@ -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), @@ -652,7 +652,7 @@ 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 () => { @@ -660,7 +660,7 @@ addEventListener("popstate", async () => { collab.stop() if (isValidAutomergeUrl(slug)) { await collab.init() - collab.start(slug, memtree) + await collab.start(slug, memtree) } else { await db.load(slug) }