Skip to content

feat(ws): add server-side room actions - #780

Open
0froq wants to merge 8 commits into
voidzero-dev:mainfrom
0froq:feat/room-server-actions
Open

0froq wants to merge 8 commits into
voidzero-dev:mainfrom
0froq:feat/room-server-actions

Conversation

@0froq

@0froq 0froq commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Fixes #689

Description

Let rooms declare named actions that other server code can call through getRoom() from void/ws/server.

An auth hook can pass a session ID to an action that closes matching connections inside the room. The filtering stays in the Durable Object rather than crossing the boundary as a callback. Action arguments and return values retain their declared types.

getRoom() uses the same room addressing as client connections, including route params and custom keys. Actions run over Durable Object RPC, not through an HTTP endpoint or client message. Internal helpers use JavaScript private methods so they are not exposed through RPC.

The server-only entry point stays separate from void/ws. Existing rooms without actions and defineWebSocket routes retain their behavior. The guide includes a session-revocation example using server-authenticated session IDs.

Current boundaries:

  • Authorization belongs in the calling server code. Action context has no request or user.
  • Arguments must be structured-cloneable.
  • Broadcast messages are schema-validated at runtime but are not statically typed inside actions yet.
  • Room hooks should use ctx.room directly instead of awaiting an RPC action on their own room.
  • then is reserved by the actions proxy to prevent accidental Promise assimilation.

Test

  • 309 focused unit and integration tests pass, including existing WebSocket and routing regressions.
  • Miniflare tests exercise the generated Worker, action dispatch, connection filtering, storage, broadcasts, cron and queue callers, and client/HTTP isolation.
  • Regression tests verify that internal helpers cannot be called over RPC and that awaiting the actions proxy does not dispatch an action. Both fail against the pre-fix implementation.
  • A temporary project checks getRoom() against actual generated route declarations, including invalid calls. The test uses the package's built declarations.
  • Package typecheck, lint and formatting checks pass.

The full suite has not passed locally. Earlier runs encountered missing Playwright browsers, an older Node version and missing generated configs; those failures were not compared against the base commit. Live Cloudflare deployment and the development server have not been verified.

@0froq
0froq requested a review from a team as a code owner November 11, 2026 04:24

This branch has not been deployed

No deployments
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.

WebSockets: a server-side handle to a room, to broadcast to or close its connections from other server code

1 participant