Skip to content

Add examples#10

Merged
jmorrell merged 10 commits intomainfrom
add-examples
Feb 17, 2026
Merged

Add examples#10
jmorrell merged 10 commits intomainfrom
add-examples

Conversation

@jmorrell
Copy link
Owner

@jmorrell jmorrell commented Feb 17, 2026

Summary

  • Adds worker-basic example: HTTP batch + WebSocket transport toggle with interactive playground
  • Adds worker-bidirectional example: server-to-client RPC with Durable Object audit log broadcast
  • Returns RpcSession from WebSocket helpers instead of a proxy, giving callers access to session.onClose() for connection lifecycle management
  • Adds onClose(handler) and Symbol.dispose to RpcSession

API changes

newWorkersWebSocketRpcSession now returns { response, session } instead of { response, remote }:

const { response, session } = newWorkersWebSocketRpcSession<ClientApi, typeof service>(
  request,
  service,
);

session.remote.onEvent(event);           // call methods on the client
session.onClose(() => cleanup());        // clean up when connection drops

newWebSocketRpcSession now returns an RpcSession instead of a proxy:

const session = newWebSocketRpcSession<ServerApi>(wsUrl);
await session.remote.add(1, 2);          // was: await proxy.add(1, 2)
session.close();

Test plan

  • All 163 existing tests pass
  • New tests for onClose (transport close, session close, already-closed, multiple handlers)
  • New test for Symbol.dispose on RpcSession
  • Manual: run worker-bidirectional example, open two tabs, verify audit events broadcast, close a tab and verify subscription cleanup via onClose

jmorrell and others added 10 commits February 16, 2026 16:48
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>
@jmorrell jmorrell merged commit 2910c8c into main Feb 17, 2026
1 check passed
@jmorrell jmorrell deleted the add-examples branch February 17, 2026 01:58
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