-
Notifications
You must be signed in to change notification settings - Fork 5
feat: live session page updates with join link and board preview #902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import type { ConnectionContext, SessionEvent } from '@boardsesh/shared-schema'; | ||
| import { pubsub } from '../../../pubsub/index'; | ||
| import { requireSessionMember } from '../shared/helpers'; | ||
| import { requireSessionMember, validateInput } from '../shared/helpers'; | ||
| import { createAsyncIterator } from '../shared/async-iterators'; | ||
| import { SessionIdSchema } from '../../../validation/schemas'; | ||
| import { buildSessionStatsUpdatedEvent } from './live-session-stats'; | ||
|
|
||
| export const sessionSubscriptions = { | ||
| /** | ||
|
|
@@ -27,4 +29,31 @@ export const sessionSubscriptions = { | |
| } | ||
| }, | ||
| }, | ||
|
|
||
| /** | ||
| * Subscribe to read-only live session stats by session ID. | ||
| * This is intentionally public for share-link viewers on /session/:id pages. | ||
| */ | ||
| sessionStats: { | ||
| subscribe: async function* (_: unknown, { sessionId }: { sessionId: string }) { | ||
| validateInput(SessionIdSchema, sessionId, 'sessionId'); | ||
|
|
||
| // Send a snapshot immediately so viewers get up-to-date stats on first paint. | ||
| const initial = await buildSessionStatsUpdatedEvent(sessionId); | ||
|
|
||
| const asyncIterator = await createAsyncIterator<SessionEvent>((push) => { | ||
| return pubsub.subscribeSession(sessionId, push); | ||
| }); | ||
|
|
||
| if (initial) { | ||
| yield { sessionStats: initial }; | ||
| } | ||
|
|
||
| for await (const event of asyncIterator) { | ||
| if (event.__typename === 'SessionStatsUpdated') { | ||
| yield { sessionStats: event }; | ||
|
Comment on lines
+52
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The subscription drops every non- Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
| }, | ||
| }, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fetching
initialbefore attaching the pubsub listener creates a race where ticks logged in between are never delivered:buildSessionStatsUpdatedEventcaptures old totals, thenpubsub.subscribeSessionstarts after that point, so the in-betweenSessionStatsUpdatedevent is dropped and viewers can remain permanently stale if no later ticks arrive. This resolver should subscribe first (or use the eager iterator path) and then emit a snapshot to avoid missing updates.Useful? React with 👍 / 👎.