diff --git a/docs/bgs-integration.md b/docs/bgs-integration.md index ea9e34f..12f8cb1 100644 --- a/docs/bgs-integration.md +++ b/docs/bgs-integration.md @@ -4,7 +4,7 @@ Engine entry point: `dist/wrapper.js` from `fuji-engine`. The wrapper exports init, move, ended, scores, rankings, currentPlayer, dropPlayer, logLength, logSlice, stripSecret, round, replay and setPlayerMetaData, plus the optional isLiveUpdate hook. `hashSeed = true`; the seed never appears in a stripped view. `moveAI(state, player)` returns a new state using the shared baseline bot; the harness and simulations use the same implementation. -Viewer: self-contained IIFE, global `fuji`, function `launch(selector)` returning an emitter. The bridge consumes state/player events, requests fresh state on state updates and game logs, forwards moves without double wrapping, and announces readiness after rendering the initial state. The host provides chat transport and storage, clocks, identity and iframe messaging. Set `viewer.chat: true`: Fuji renders chat during and after the expedition, including lobby history. The bridge handles `chat:messages`, `chat:appended`, `chat:updated`, `chat:deleted`, `chat:state`, `chat:disabled` and `chat:result`; sends carry a request ID and visible messages emit `chat:read`. Chat drafts and updates are independent of game animation playback. The `chat:state` roster supplies mention suggestions. Messages use BGS-provided text, link and mention segments, with plain text as a fallback; outgoing mentions use `@name` or `@"Full Name"`. Links follow platform trust rules, and reading the chat clears the platform mention badge. The local harness keeps its chat separately in local storage; switch seats to test multiple authors. Source assets are bundled as data URLs, so the initial viewer has no independent asset-hosting requirement. +Viewer: self-contained IIFE, global `fuji`, function `launch(selector)` returning an emitter. `@boardgamers/protocol` handles viewer registration, validated events, state refreshes, readiness and cleanup. Its `ChatController` handles chat history, unread messages and send acknowledgements; the Svelte UI subscribes to its snapshots. The host provides chat transport and storage, clocks, identity and iframe messaging. Set `viewer.chat: true`: Fuji renders chat during and after the expedition, including lobby history. The bridge handles `chat:messages`, `chat:appended`, `chat:updated`, `chat:deleted`, `chat:state`, `chat:disabled` and `chat:result`; sends carry a request ID and visible messages emit `chat:read`. Chat drafts and updates are independent of game animation playback. The `chat:state` roster supplies mention suggestions. Messages use BGS-provided text, link and mention segments, with plain text as a fallback; outgoing mentions use `@name` or `@"Full Name"`. Links follow platform trust rules, and reading the chat clears the platform mention badge. The local harness keeps its chat separately in local storage; switch seats to test multiple authors. Source assets are bundled as data URLs, so the initial viewer has no independent asset-hosting requirement. ```sh pnpm check diff --git a/package.json b/package.json index a264cd0..ece2085 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "fmt": "oxfmt", "fmt:check": "oxfmt --check", "simulate": "pnpm --filter fuji-engine build && node scripts/simulate.mjs", - "test:browser": "node tests/browser-smoke.mjs && node tests/bgs-bundle-smoke.mjs && node tests/presentation-smoke.mjs && node tests/chat-smoke.mjs && node tests/mobile-readiness-smoke.mjs && node tests/chat-tabs-smoke.mjs && node tests/chat-mentions-smoke.mjs" + "test:browser": "node tests/browser-smoke.mjs && node tests/bgs-bundle-smoke.mjs && node tests/presentation-smoke.mjs && node tests/chat-smoke.mjs && node tests/mobile-readiness-smoke.mjs && node tests/chat-tabs-smoke.mjs && node tests/chat-mentions-smoke.mjs && node tests/protocol-lifecycle-smoke.mjs" }, "devDependencies": { "oxfmt": "0.61.0", diff --git a/packages/viewer/package.json b/packages/viewer/package.json index 6c40b5a..e22f563 100644 --- a/packages/viewer/package.json +++ b/packages/viewer/package.json @@ -10,6 +10,7 @@ "check": "svelte-check --tsconfig ./tsconfig.json" }, "dependencies": { + "@boardgamers/protocol": "0.1.0", "fuji-engine": "workspace:*" }, "devDependencies": { diff --git a/packages/viewer/src/App.svelte b/packages/viewer/src/App.svelte index 3b9cf45..4b77a88 100644 --- a/packages/viewer/src/App.svelte +++ b/packages/viewer/src/App.svelte @@ -69,11 +69,11 @@ let journal = $state(true); let socialTab = $state("chat"); $effect(() => { - store.chat.playerIndex = seat; + store.chat.setPlayer(seat); }); function openChat() { socialTab = "chat"; - store.chat.open = true; + store.chat.setOpen(true); requestAnimationFrame(() => document.querySelector(".expedition-chat")?.scrollIntoView({ behavior: "smooth", block: "center" }) ); @@ -450,8 +450,8 @@ - {#if store.chat.enabled}Chat{store.chatState.unreadIds.length ? ` · ${store.chatState.unreadIds.length}` : ""}{/if} - {#if store.chat.enabled}Chat{store.chatState.unreadIds.length ? ` · ${store.chatState.unreadIds.length}` : ""}{/if} {/if}
@@ -804,17 +806,17 @@ {/if} {/if}
-
{@render journalPanel("desktop")}
+
{@render journalPanel("desktop")}