Skip to content

feat(examples): managed session queue client reference - #190

Merged
AdirAmsalem merged 9 commits into
mainfrom
managed-queue-example
Jul 26, 2026
Merged

feat(examples): managed session queue client reference#190
AdirAmsalem merged 9 commits into
mainfrom
managed-queue-example

Conversation

@AdirAmsalem

@AdirAmsalem AdirAmsalem commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Client reference for Decart's managed session queue: when an account's realtime concurrency is at its limit, users wait in a fair line with live position feedback. The queue manages the line only — it never mints, holds, or sees credentials. On granted, the app fetches a token from your own token endpoint (the standard realtime integration; see examples/express-proxy for the pattern) and connects within the claim window.

The whole client contract is three rules — poll every ~2s while waiting (stop polling or DELETE to leave), on granted fetch your token and connect within the claim window, and if a connect is ever refused, join again:

const { status, join, leave, sessionEnded, rejoin } = useQueue(fetchSession);
// status: idle | waiting {position, queueSize} | ready {session} | error
// fetchSession: your token endpoint → { apiKey } (mint with short expiresIn + maxSessionDuration)

The queue state machine lives in a framework-free QueueClient class (plain fetch + timers, no React dependencies — unit-testable and portable as-is) with a thin useSyncExternalStore hook binding; the camera/render component is the only platform-specific part. Same try-on UI and preloaded sample garment as the sibling realtime-session-queue example, which remains the self-hosted variant of the pattern for customers who want to own queueing themselves.

Verified end-to-end in a real browser against a live queue and a stand-in customer token endpoint: join → granted → own-token fetch → live session with output frames; with capacity saturated, a second tab waits with live position and inherits the slot when it frees.


Note

Low Risk
Documentation and example-only code; no production SDK or service changes.

Overview
Adds examples/realtime-session-queue-managed, a Vite/React reference app for Decart’s managed session queue (sibling to the self-hosted realtime-session-queue example).

The integration centers on a framework-free QueueClient that talks to /v1/queues/{id}/tickets with the publishable queue key, polls about every 2s while waiting, and on granted calls the app’s own fetchSession (your token endpoint — queue never mints credentials). A thin useQueue hook wires it with useSyncExternalStore; TryOnSession connects via @decartai/sdk and rejoins on refused connect.

The UI covers idle → waiting (position) → live try-on with a preloaded sample garment, plus README, .env.example, and pnpm-lock.yaml workspace entries.

Reviewed by Cursor Bugbot for commit 01bda8c. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread examples/realtime-session-queue-managed/src/hooks/queue-client.ts
@pkg-pr-new

pkg-pr-new Bot commented Jul 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@decartai/sdk@190

commit: 3273961

Comment thread examples/realtime-session-queue-managed/src/hooks/queue-client.ts
Comment thread examples/realtime-session-queue-managed/src/hooks/queue-client.ts
Comment thread examples/realtime-session-queue-managed/src/hooks/queue-client.ts
A join that answers granted directly left the UI in idle while
fetchSession ran — a slow token endpoint looked like a dead click.
@AdirAmsalem
AdirAmsalem merged commit 160d2f7 into main Jul 26, 2026
3 checks passed
@AdirAmsalem
AdirAmsalem deleted the managed-queue-example branch July 26, 2026 15:44

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 01bda8c. Configure here.

if (epoch !== this.epoch) return;
if (body.state === "granted") {
await this.claim(epoch);
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale position after poll grant

Low Severity

When grant arrives from pollLoop, claim runs without first setting waiting to position 1. The join-granted path does update to “you’re next” so a slow fetchSession does not look stuck; the poll path leaves the previous place-in-line UI until ready.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 01bda8c. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant