Merged
Conversation
Cloudflare Worker playground that demonstrates typed RPC calls and auto-batching via newHttpBatchRpcSession. Vanilla HTML/CSS, no framework dependencies. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Combine what was going to be two separate examples into one. A segmented control switches between HTTP batch and WebSocket transports — the server code is identical since newWorkersRpcResponse routes both. The bottom section adapts to explain auto-batching (HTTP) vs individual messages (WebSocket). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Server-to-client RPC over WebSocket: a Durable Object manages all connections and broadcasts audit events to every client whenever any method is invoked. Demonstrates newWorkersWebSocketRpcSession (server) and newWebSocketRpcSession with a local service (client). Two-column layout with method cards on the left and a live event log on the right. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ject The DO is now a pure WebSocket broadcast hub with no business logic. The Worker handles RPC sessions directly and uses a connectAuditLog() helper to subscribe/publish through the DO, reducing latency and cost. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the RemoteProxy abstraction with returning RpcSession directly
from newWorkersWebSocketRpcSession and newWebSocketRpcSession. This
gives callers access to session.onClose() for cleanup when connections
drop, which was previously impossible.
- Add onClose(handler) and Symbol.dispose to RpcSession
- Remove RemoteProxy type and createRemoteProxy helper
- newWorkersWebSocketRpcSession returns { response, session }
- newWebSocketRpcSession returns RpcSession
- Update examples to use session.remote and session.onClose()
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
worker-basicexample: HTTP batch + WebSocket transport toggle with interactive playgroundworker-bidirectionalexample: server-to-client RPC with Durable Object audit log broadcastRpcSessionfrom WebSocket helpers instead of a proxy, giving callers access tosession.onClose()for connection lifecycle managementonClose(handler)andSymbol.disposetoRpcSessionAPI changes
newWorkersWebSocketRpcSessionnow returns{ response, session }instead of{ response, remote }:newWebSocketRpcSessionnow returns anRpcSessioninstead of a proxy:Test plan
onClose(transport close, session close, already-closed, multiple handlers)Symbol.disposeonRpcSessionworker-bidirectionalexample, open two tabs, verify audit events broadcast, close a tab and verify subscription cleanup viaonClose