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

Offen
#689 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
30/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
typescript

Rechercherichtung

Start by reading the defineRoom API for *.ws.ts routes and the existing onRequest approach described in the issue; inspect how the generated binding in void.lock.json identifies a room instance. The proposal calls for a supported server-side handle usable from route handlers, auth hooks, queues, and cron jobs. Done means external code can address the same room instance as a client's connect() and use it to broadcast or close selected connections.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Void 1.5.0, Cloudflare target, defineRoom in a *.ws.ts route.

We need to reach a room from server code outside its own hooks. Our case is closing a user's open sockets when their Better Auth session is revoked: databaseHooks.session.delete.after fires on every revoke, sign-out and user deletion, but from there nothing in Void's API reaches the room's Durable Object. The docs only suggest re-checking records in onMessage and closing, which leaves an idle socket of a revoked session open until its next frame, and costs a database read per frame.

The only way we found is undocumented: the binding name Void generates (from void.lock.json), idFromName('<param>=<value>'), and a request handled in onRequest. We do not want to depend on those internals.

Proposal: a server-side handle to a room instance, for example:

import { getRoom } from 'void/ws';

const room = getRoom('/relay/:accountId', { params: { accountId } });
await room.broadcast(event);
await room.close({ code: 4001, reason: 'session revoked', filter: (connection) => connection.state.sessionId === id });

usable from route handlers, auth hooks, queues and cron jobs, and addressing the same instance a client's connect() would.

Vorherrschende Sprache
TypeScript
Sterne
627
Forks
66
Ø Merge
14 Std. 38 Min.
Gemergte PRs (30 T.)
179

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus voidzero-dev/void

Alle Issues in voidzero-dev/void

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.