feat(server): the relay joins modems of different projects by a code (K3)

A modem that offers a connection to another project is found by six
characters derived from its project and itself (modemCode): a copy of the
project has another code, so no two modems offer the same one. The room
names its modems of other projects to F's relay at a start and none at a
stop; the relay pairs each offer with the first modem that joins its code,
one to one as Java's server modem takes one client, and passes the frames
between the rooms' threads. Every client hears how each modem stands
(`modems`: connected, waiting, taken, unpaired, ambiguous, detached, or
unavailable without F). The document keeps the connection and the code.

Measured on F with two threads: a ping from one project's notebook to the
other's goes through; a third project that wants the same code reads
taken, and takes it when the second stops; a deleted project's modem
leaves with its room.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 18:24:19 +00:00
co-authored by Claude Opus 5.5
parent c85b0e45da
commit 7b943d3d96
15 changed files with 726 additions and 25 deletions
+15 -1
View File
@@ -61,7 +61,7 @@ export type ClientMessage =
readonly reqId: string;
};
export const HOST_MESSAGE_KINDS = ['state', 'activity', 'trace', 'dropped', 'app', 'view', 'node', 'ack', 'error'] as const;
export const HOST_MESSAGE_KINDS = ['state', 'activity', 'trace', 'dropped', 'app', 'view', 'node', 'modems', 'ack', 'error'] as const;
export type HostMessageKind = (typeof HOST_MESSAGE_KINDS)[number];
export type SimMode = 'design' | 'simulation';
@@ -126,9 +126,23 @@ export type HostMessage =
* on subscribing, when it changes, and none while the simulation never ran.
*/
| { readonly v: 1; readonly kind: 'node'; readonly node: string; readonly settings: NodeSettings }
/** How each modem stands, by node: to every client when it changes and when it connects; none while the simulation does not run. */
| { readonly v: 1; readonly kind: 'modems'; readonly modems: Readonly<Record<string, ModemStatus>> }
| { readonly v: 1; readonly kind: 'ack'; readonly reqId: string }
| { readonly v: 1; readonly kind: 'error'; readonly code: ErrorCode; readonly reqId?: string; readonly detail?: string };
/**
* How a modem stands while the simulation runs (shown under it):
* `connected` to its partner (in the project, or another project's);
* `unpaired`: no other modem on its port in the project; `ambiguous`: more
* than two there; `detached`: its cable or its partner's missing; for a
* modem of another project `waiting` (no partner: the other simulation does
* not run, or no modem has the code), `taken` (the modem with the code is
* connected with another) or `unavailable` (no server F: a room of one's own
* page cannot reach another project).
*/
export type ModemStatus = 'connected' | 'unpaired' | 'ambiguous' | 'detached' | 'waiting' | 'taken' | 'unavailable';
/** What Java's desktop shows of a computer's network (NetworkInfoPanel, the window's title). */
export interface NodeSettings {
readonly ipAddress: string;