feat(realtime): add realtime namespace with subscribe/send#212
feat(realtime): add realtime namespace with subscribe/send#212ImriKochWix wants to merge 10 commits into
Conversation
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 encountered an error —— View job I'll analyze this and get back to you. |
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/sdk@0.8.35-pr.212.02fa769Prefer not to change any import paths? Install using npm alias so your code still imports npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.35-pr.212.02fa769"Or add it to your {
"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 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 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 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 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 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 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 encountered an error —— View job I'll analyze this and get back to you. |
… async token refresh
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
… by JWT script_name, not URL party name
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Summary
PR B of 3 for the Realtime Handler feature.
src/modules/realtime.ts:createRealtimeModulereturns a Proxy sobase44.realtime.GameRoomworks dynamically.subscribe(instanceId, cb)fetches a 30s token from the backend, opens aPartySockettowss://dispatcher/parties/{handlerName}/{instanceId}?token=..., re-fetches token on reconnect. Returns{ send, close }.src/modules/realtime.types.ts: exported typesRealtimeModule,RealtimeHandlerClient,RealtimeSubscriptionsrc/client.ts: wiredrealtimemodule withgetTokenPOST to/api/apps/{appId}/realtime-token, derivesdispatcherWsUrlfromserverUrl(https://→wss://)package.json: addedpartysocketdependencyDepends on
PR A deployed to preview (needs the token endpoint + Dispatcher WS handling live).
🤖 Generated with Claude Code