commit
Drop the Hub entrypoint now the system site has its own socket
The system site broadcasts fronting and mental state on doughmination.co.uk/api/plural/ws. /v2/ws keeps presence and devices. Co-Authored-By: Sandrone <[email protected]>
diff --git a/src/apidata.ts b/src/apidata.ts
index 19805df..abe6e01 100644
--- a/src/apidata.ts
+++ b/src/apidata.ts
@@ -85,7 +85,7 @@ export const GROUPS: GroupDef[] = [
id: "realtime", name: "Realtime", blurb: "One WebSocket for every live update.",
endpoints: [
{ m: "WS", path: "/ws", auth: "public",
- desc: "The single realtime socket for ALL live updates. On connect you get a connection_established message. Fronting (fronters_update), mental state (mental_state_update), device/battery (device_update) and force_refresh events are pushed to every client automatically. For live Discord presence, send a subscribe frame — either { \"type\": \"subscribe\", \"all\": true } or { \"type\": \"subscribe\", \"ids\": [\"<user id>\", …] }; you'll get an init_state snapshot immediately and presence_update events thereafter (only for the users you subscribed to). Every message is a { type, data } object. Send 'ping' to get 'pong'." },
+ desc: "The realtime socket for presence and devices. On connect you get a connection_established message. Device/battery (device_update) events are pushed to every client automatically. Fronting and mental state are on the system site's socket, wss://doughmination.co.uk/api/plural/ws. For live Discord presence, send a subscribe frame — either { \"type\": \"subscribe\", \"all\": true } or { \"type\": \"subscribe\", \"ids\": [\"<user id>\", …] }; you'll get an init_state snapshot immediately and presence_update events thereafter (only for the users you subscribed to). Every message is a { type, data } object. Send 'ping' to get 'pong'." },
],
},
{
diff --git a/src/index.ts b/src/index.ts
index 22cbd61..a3845e7 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -2,8 +2,9 @@
* index.ts — Worker entry: v2 router + cron keepalive.
*
* Namespaces
- * /v2/ws — the single realtime socket for ALL live updates
- * (presence, fronting, mental state, devices) (SystemState DO)
+ * /v2/ws — the realtime socket for presence and devices (SystemState DO).
+ * Fronting and mental state live on the system site's own
+ * socket, wss://doughmination.co.uk/api/plural/ws
* /v2/discord/* — Discord users (profile + badges + presence + equipped
* collectibles, one merged record), guilds, girls, status
* (the old /v2/lanyard/* presence routes now live here)
@@ -52,25 +53,10 @@ import { DOCS_HTML } from "./docs";
import { ABUSE_HTML, ABUSE_CONTACT, securityTxt } from "./abuse";
import { LANDING_HTML, TERMS_HTML, PRIVACY_HTML, NOT_FOUND_HTML } from "./pages";
import { OPENAPI_JSON } from "./openapi";
-import { SystemState, BROADCAST_PATH } from "./system/do";
-import { WorkerEntrypoint } from "cloudflare:workers";
+import { SystemState } from "./system/do";
export { GatewayManager, SystemState };
-/**
- * RPC entrypoint for the system site (doughmination.co.uk), bound there as
- * HUB with entrypoint "Hub". Service-binding only: it has no public route.
- */
-export class Hub extends WorkerEntrypoint<Env> {
- /** Fan a { type, data } event out to every /v2/ws client. */
- async broadcast(data: unknown): Promise<void> {
- await systemStub(this.env).fetch(`https://do${BROADCAST_PATH}`, {
- method: "POST",
- body: JSON.stringify(data),
- });
- }
-}
-
const CORS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
diff --git a/src/openapi.ts b/src/openapi.ts
index 9ba51dd..77e5bd7 100644
--- a/src/openapi.ts
+++ b/src/openapi.ts
@@ -159,7 +159,7 @@ function buildSpec(): JsonObj {
description:
"Combined Discord presence + profile/badges API, Minecraft lookups, git contribution heatmaps, devices, guestbook and counters — one Cloudflare Worker.\n\n" +
"All JSON responses share one envelope: `{ success, data }` or `{ success: false, error: { code, message } }`.\n\n" +
- "**Realtime:** live updates (presence, fronting, mental state, devices) are pushed over a single WebSocket at `wss://doughmination.uk/v2/ws` — see /docs for the frame protocol. WebSocket endpoints are not listed as paths below.\n\n" +
+ "**Realtime:** presence and device updates are pushed over a WebSocket at `wss://doughmination.uk/v2/ws` — see /docs for the frame protocol. Fronting and mental state are on the system site's socket, `wss://doughmination.co.uk/api/plural/ws`. WebSocket endpoints are not listed as paths below.\n\n" +
"**Terms:** be reasonable with request volume or your IP gets blocked — https://doughmination.uk/terms",
contact: { email: ABUSE_CONTACT, url: `${BASE}/abuse` },
termsOfService: `${BASE}/terms`,
diff --git a/src/system/do.ts b/src/system/do.ts
index 406c6c8..96a4000 100644
--- a/src/system/do.ts
+++ b/src/system/do.ts
@@ -12,9 +12,9 @@
* - Owns the visit-counter SQLite tables (DO embedded SQLite).
* - Is the SINGLE realtime WebSocket hub for the whole API, at /v2/ws,
* using the hibernatable WebSocket API so idle sockets don't keep the DO
- * billed/awake. Every live update — presence, fronting, mental state,
- * device/battery, force-refresh — is delivered over this one socket as a
- * { type, data } envelope.
+ * billed/awake. Presence and device/battery updates are delivered over
+ * this socket as a { type, data } envelope. Fronting and mental state moved
+ * to the system site's own socket (doughmination.co.uk/api/plural/ws).
* - Delegates all HTTP to the Hono `systemApp`.
*
* Presence lives in the GatewayManager DO (which owns the Discord gateway
@@ -53,8 +53,6 @@ class DoStore implements Store {
const WS_PATH = "/v2/ws";
/** Internal DO-to-DO path GatewayManager relays presence updates to. */
const PRESENCE_RELAY_PATH = "/internal/presence";
-/** Internal path the Hub entrypoint (index.ts) calls for the system site. */
-export const BROADCAST_PATH = "/internal/broadcast";
/** Per-socket presence subscription, persisted on the hibernatable socket via
* serializeAttachment so it survives eviction. Presence events are filtered
@@ -104,12 +102,6 @@ export class SystemState implements DurableObject {
return new Response(null, { status: 204 });
}
- // Fronting / mental-state events from the system site, via the Hub entrypoint
- if (url.pathname === BROADCAST_PATH && req.method === "POST") {
- this.broadcast(await req.json());
- return new Response(null, { status: 204 });
- }
-
return systemApp.fetch(req, {} as never);
}
@@ -120,7 +112,7 @@ export class SystemState implements DurableObject {
// Hibernatable accept — the DO can be evicted while sockets stay open.
this.state.acceptWebSocket(server);
// Start with no presence subscription; the client opts in by sending a
- // { type: "subscribe" } message. Fronting / mental-state / device events
+ // { type: "subscribe" } message. Device events
// are still delivered without any subscription.
server.serializeAttachment(EMPTY_SUB);
@@ -226,7 +218,7 @@ export class SystemState implements DurableObject {
// ---- fan-out ------------------------------------------------------------
/** Fan a { type, data } payload out to EVERY connected client. Used for
- * fronting / mental-state / device / force_refresh events. */
+ * device events. */
private broadcast(data: unknown): void {
const message = JSON.stringify(data);
for (const ws of this.state.getWebSockets()) {
diff --git a/src/system/ws.ts b/src/system/ws.ts
index 8ddf6af..8fe139a 100644
--- a/src/system/ws.ts
+++ b/src/system/ws.ts
@@ -15,19 +15,7 @@
import { rt } from "./runtime";
-export function broadcastFrontingUpdate(frontersData: unknown): void {
- rt().broadcast({ type: "fronters_update", data: frontersData });
-}
-
-export function broadcastMentalStateUpdate(stateData: unknown): void {
- rt().broadcast({ type: "mental_state_update", data: stateData });
-}
-
/** A device/battery state change ({ device, level, charging, ... }). */
export function broadcastDeviceUpdate(deviceData: unknown): void {
rt().broadcast({ type: "device_update", data: deviceData });
}
-
-export function broadcastFrontendUpdate(updateType: string, data: unknown): void {
- rt().broadcast({ type: updateType, data });
-}