Skip to content

feat(realtime): add realtime namespace with subscribe/send#212

Draft
ImriKochWix wants to merge 10 commits into
mainfrom
feat/realtime-handler
Draft

feat(realtime): add realtime namespace with subscribe/send#212
ImriKochWix wants to merge 10 commits into
mainfrom
feat/realtime-handler

Conversation

@ImriKochWix

Copy link
Copy Markdown

Summary

PR B of 3 for the Realtime Handler feature.

  • New src/modules/realtime.ts: createRealtimeModule returns a Proxy so base44.realtime.GameRoom works dynamically. subscribe(instanceId, cb) fetches a 30s token from the backend, opens a PartySocket to wss://dispatcher/parties/{handlerName}/{instanceId}?token=..., re-fetches token on reconnect. Returns { send, close }.
  • New src/modules/realtime.types.ts: exported types RealtimeModule, RealtimeHandlerClient, RealtimeSubscription
  • src/client.ts: wired realtime module with getToken POST to /api/apps/{appId}/realtime-token, derives dispatcherWsUrl from serverUrl (https://wss://)
  • package.json: added partysocket dependency

Depends on

PR A deployed to preview (needs the token endpoint + Dispatcher WS handling live).

🤖 Generated with Claude Code

Add a `realtime` module to the Base44 JS SDK that lets users subscribe
to and send messages to Cloudflare Durable Object-backed RealtimeHandlers
deployed by the Base44 platform. Uses PartySocket for WebSocket transport
with automatic token refresh on reconnect.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Jun 30, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/sdk@0.8.35-pr.212.02fa769

Prefer not to change any import paths? Install using npm alias so your code still imports @base44/sdk:

npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.35-pr.212.02fa769"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "@base44/sdk": "npm:@base44-preview/sdk@0.8.35-pr.212.02fa769"
  }
}

Preview published to npm registry — try new features instantly!

partysocket was added to package.json but lock file was never generated.
Also fixes .npmrc: was using env-var syntax (npm_config_registry=...)
instead of npmrc syntax (registry=...).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Jun 30, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Jun 30, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

- subscribe() now returns a sync unsubscribe function instead of Promise<RealtimeSubscription>
- send() is typed via RealtimeHandlerRegistry (user-declared message types)
- Add RealtimeHandlerNameRegistry for CLI codegen (no conflict with user augmentation)
- Drop RealtimeSubscription in favor of the simpler sync cleanup pattern

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Jun 30, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Jun 30, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

…et URL

partysocket@0.0.23's updateProperties only falls back for host/room/path,
not party. Passing {query:{token}} dropped party, changing the URL from
/parties/ChatRoom/room to /party/room.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Jun 30, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

Don't connect until we have a token — avoids initial tokenless
connection being rejected and the updateProperties/reconnect timing race.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Jun 30, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

Expose this.storage (DO KV) and onStart() lifecycle hook so handlers
can persist and load state. Both are backed by the compiled shim at
runtime; the stub implementations throw to surface misuse in local
dev/test outside a deployed context.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Jul 1, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 1, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 1, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

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