@air-jam/server 0.9.3 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-PSWSCMDN.js → chunk-2BHF5ZCS.js} +2 -12
- package/dist/{chunk-PSWSCMDN.js.map → chunk-2BHF5ZCS.js.map} +1 -1
- package/dist/{chunk-LWVOQ5PH.js → chunk-5YSBR6YK.js} +3 -54
- package/dist/chunk-5YSBR6YK.js.map +1 -0
- package/dist/chunk-64G5AWIQ.js +1271 -0
- package/dist/chunk-64G5AWIQ.js.map +1 -0
- package/dist/chunk-GMZVQDC6.js +54 -0
- package/dist/chunk-GMZVQDC6.js.map +1 -0
- package/dist/chunk-ILYZVHYT.js +39 -0
- package/dist/chunk-ILYZVHYT.js.map +1 -0
- package/dist/chunk-INZKL5US.js +484 -0
- package/dist/chunk-INZKL5US.js.map +1 -0
- package/dist/chunk-JYI2GKLJ.js +334 -0
- package/dist/chunk-JYI2GKLJ.js.map +1 -0
- package/dist/cli.js +9 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +15 -449
- package/dist/index.js +11 -5175
- package/dist/index.js.map +1 -1
- package/dist/process-lifecycle-A55YCNJN.js +8 -0
- package/dist/room-server-4U4TBSS5.js +13 -0
- package/dist/room-server-4U4TBSS5.js.map +1 -0
- package/dist/room-server-BO0iOvhH.d.ts +144 -0
- package/dist/room-server.d.ts +7 -0
- package/dist/room-server.js +13 -0
- package/dist/room-server.js.map +1 -0
- package/dist/room.d.ts +360 -0
- package/dist/room.js +17 -0
- package/dist/room.js.map +1 -0
- package/package.json +13 -15
- package/dist/chunk-AYTGY3H3.js +0 -67
- package/dist/chunk-AYTGY3H3.js.map +0 -1
- package/dist/chunk-LWVOQ5PH.js.map +0 -1
- package/dist/process-lifecycle-M4XOAN4Q.js +0 -8
- /package/dist/{process-lifecycle-M4XOAN4Q.js.map → process-lifecycle-A55YCNJN.js.map} +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ROOM_SERVER_HEARTBEAT,
|
|
3
|
+
createRoomServer
|
|
4
|
+
} from "./chunk-INZKL5US.js";
|
|
5
|
+
import "./chunk-JYI2GKLJ.js";
|
|
6
|
+
import "./chunk-5YSBR6YK.js";
|
|
7
|
+
import "./chunk-64G5AWIQ.js";
|
|
8
|
+
import "./chunk-2BHF5ZCS.js";
|
|
9
|
+
export {
|
|
10
|
+
DEFAULT_ROOM_SERVER_HEARTBEAT,
|
|
11
|
+
createRoomServer
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=room-server-4U4TBSS5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { RoomLimits } from '@air-jam/sdk/room-protocol';
|
|
2
|
+
import { Server, IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
+
import { AirJamDevBrowserLogSource, AirJamDevLogEventName, AirJamDevBrowserConsoleCategory } from '@air-jam/sdk/protocol';
|
|
4
|
+
import { Bindings, Logger } from 'pino';
|
|
5
|
+
import { MemoryRoomHost, RoomGate } from './room.js';
|
|
6
|
+
|
|
7
|
+
type AuthMode = "disabled" | "required";
|
|
8
|
+
type ProxyHeaderTrustMode = "auto" | "enabled" | "disabled";
|
|
9
|
+
declare const loadServerEnv: (env?: Record<string, string | undefined>) => {
|
|
10
|
+
nodeEnv: string;
|
|
11
|
+
port: number;
|
|
12
|
+
bindHost: string | undefined;
|
|
13
|
+
rateLimitWindowMs: number;
|
|
14
|
+
hostRegistrationRateLimitMax: number;
|
|
15
|
+
controllerJoinRateLimitMax: number;
|
|
16
|
+
allowedOrigins: string[] | "*";
|
|
17
|
+
devLogCollectorEnabled: boolean;
|
|
18
|
+
devLogDir: string | undefined;
|
|
19
|
+
authMode: AuthMode;
|
|
20
|
+
proxyHeaderTrustMode: ProxyHeaderTrustMode;
|
|
21
|
+
masterKey: string | undefined;
|
|
22
|
+
logLevel: string | undefined;
|
|
23
|
+
maintenanceMode: boolean;
|
|
24
|
+
};
|
|
25
|
+
type ServerEnvConfig = ReturnType<typeof loadServerEnv>;
|
|
26
|
+
|
|
27
|
+
interface BrowserLogEntry {
|
|
28
|
+
time?: string;
|
|
29
|
+
occurredAt?: string;
|
|
30
|
+
level: "debug" | "info" | "warn" | "error";
|
|
31
|
+
source: AirJamDevBrowserLogSource;
|
|
32
|
+
message: string;
|
|
33
|
+
sourceSeq?: number;
|
|
34
|
+
repeatCount?: number;
|
|
35
|
+
event?: AirJamDevLogEventName;
|
|
36
|
+
data?: unknown[];
|
|
37
|
+
stack?: string;
|
|
38
|
+
code?: string;
|
|
39
|
+
consoleCategory?: AirJamDevBrowserConsoleCategory;
|
|
40
|
+
role?: "host" | "controller";
|
|
41
|
+
traceId?: string;
|
|
42
|
+
roomId?: string;
|
|
43
|
+
controllerId?: string;
|
|
44
|
+
runtimeEpoch?: number;
|
|
45
|
+
runtimeKind?: string;
|
|
46
|
+
}
|
|
47
|
+
interface BrowserLogSessionMetadata {
|
|
48
|
+
appId?: string;
|
|
49
|
+
traceId?: string;
|
|
50
|
+
roomId?: string;
|
|
51
|
+
controllerId?: string;
|
|
52
|
+
role?: "host" | "controller";
|
|
53
|
+
origin?: string;
|
|
54
|
+
pathname?: string;
|
|
55
|
+
href?: string;
|
|
56
|
+
title?: string;
|
|
57
|
+
userAgent?: string;
|
|
58
|
+
}
|
|
59
|
+
interface BrowserLogBatchPayload {
|
|
60
|
+
mode: "reset" | "append";
|
|
61
|
+
sessionId: string;
|
|
62
|
+
metadata: BrowserLogSessionMetadata;
|
|
63
|
+
entries: BrowserLogEntry[];
|
|
64
|
+
}
|
|
65
|
+
interface BrowserLogUnloadPayload {
|
|
66
|
+
sessionId: string;
|
|
67
|
+
metadata: BrowserLogSessionMetadata;
|
|
68
|
+
entry: BrowserLogEntry;
|
|
69
|
+
}
|
|
70
|
+
declare class DevLogCollector {
|
|
71
|
+
readonly enabled: boolean;
|
|
72
|
+
readonly logDir: string;
|
|
73
|
+
readonly latestFilePath: string;
|
|
74
|
+
private writeQueue;
|
|
75
|
+
private nextCollectorSeq;
|
|
76
|
+
constructor(options: {
|
|
77
|
+
enabled: boolean;
|
|
78
|
+
logDir: string;
|
|
79
|
+
});
|
|
80
|
+
enqueueServerLogLine(line: string): void;
|
|
81
|
+
enqueueBrowserBatch(payload: BrowserLogBatchPayload): void;
|
|
82
|
+
enqueueBrowserUnload(payload: BrowserLogUnloadPayload): void;
|
|
83
|
+
flush(): Promise<void>;
|
|
84
|
+
private appendEvent;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type ServerLogger = Logger;
|
|
88
|
+
interface CreateServerLoggerOptions {
|
|
89
|
+
level?: string;
|
|
90
|
+
}
|
|
91
|
+
declare const createServerLogger: (bindings?: Bindings, parent?: ServerLogger, devLogCollector?: DevLogCollector | null, options?: CreateServerLoggerOptions) => ServerLogger;
|
|
92
|
+
|
|
93
|
+
interface ServerLoggingOptions {
|
|
94
|
+
logger?: ServerLogger;
|
|
95
|
+
devLogCollector?: DevLogCollector | false;
|
|
96
|
+
devLogDir?: string;
|
|
97
|
+
}
|
|
98
|
+
declare const createServerLogging: (options: ServerLoggingOptions, envConfig: ServerEnvConfig) => {
|
|
99
|
+
logger: ServerLogger;
|
|
100
|
+
devLogCollector: false | DevLogCollector;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
type AllowedOrigins = string[] | "*";
|
|
104
|
+
|
|
105
|
+
interface RoomServerHeartbeat {
|
|
106
|
+
/** How often the server pings each socket at the protocol level. */
|
|
107
|
+
readonly intervalMs: number;
|
|
108
|
+
/** How long a socket may stay silent, answering no ping, before it is dropped. */
|
|
109
|
+
readonly silenceMs: number;
|
|
110
|
+
}
|
|
111
|
+
declare const DEFAULT_ROOM_SERVER_HEARTBEAT: RoomServerHeartbeat;
|
|
112
|
+
interface CreateRoomServerOptions extends ServerLoggingOptions {
|
|
113
|
+
readonly host?: string;
|
|
114
|
+
readonly port?: number;
|
|
115
|
+
readonly envConfig?: ServerEnvConfig;
|
|
116
|
+
readonly allowedOrigins?: AllowedOrigins;
|
|
117
|
+
/** Replaces the gate the environment chooses: open to all, or the master key. */
|
|
118
|
+
readonly gate?: RoomGate;
|
|
119
|
+
/** The limits the environment's gates open rooms with. */
|
|
120
|
+
readonly limits?: RoomLimits;
|
|
121
|
+
readonly heartbeat?: RoomServerHeartbeat;
|
|
122
|
+
/**
|
|
123
|
+
* Answers HTTP requests for paths the room server does not own, as when
|
|
124
|
+
* one origin serves a built game beside its rooms. Without it they get 404.
|
|
125
|
+
*/
|
|
126
|
+
readonly otherRequests?: (request: IncomingMessage, response: ServerResponse) => void;
|
|
127
|
+
}
|
|
128
|
+
interface RoomServerRuntime {
|
|
129
|
+
readonly httpServer: Server;
|
|
130
|
+
readonly rooms: MemoryRoomHost;
|
|
131
|
+
start(portOverride?: number): Promise<number>;
|
|
132
|
+
/** Stops every room as "restarting", so its devices come back, then closes the server. */
|
|
133
|
+
stop(): Promise<void>;
|
|
134
|
+
getPort(): number | null;
|
|
135
|
+
flushDevLogs(): Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The room server for self-hosters, local development and Studio
|
|
139
|
+
* workspaces: rooms in memory behind `node:http` and `ws`, at the protocol's
|
|
140
|
+
* paths. `air-jam-server start` runs it from the environment.
|
|
141
|
+
*/
|
|
142
|
+
declare const createRoomServer: (options?: CreateRoomServerOptions) => RoomServerRuntime;
|
|
143
|
+
|
|
144
|
+
export { type CreateRoomServerOptions as C, DEFAULT_ROOM_SERVER_HEARTBEAT as D, type RoomServerRuntime as R, type ServerLogger as S, type ServerEnvConfig as a, createServerLogging as b, createServerLogger as c, type RoomServerHeartbeat as d, createRoomServer as e, loadServerEnv as l };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { C as CreateRoomServerOptions, D as DEFAULT_ROOM_SERVER_HEARTBEAT, d as RoomServerHeartbeat, R as RoomServerRuntime, e as createRoomServer } from './room-server-BO0iOvhH.js';
|
|
2
|
+
import '@air-jam/sdk/room-protocol';
|
|
3
|
+
import 'node:http';
|
|
4
|
+
import '@air-jam/sdk/protocol';
|
|
5
|
+
import 'pino';
|
|
6
|
+
import './room.js';
|
|
7
|
+
import '@air-jam/sdk/room-session';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ROOM_SERVER_HEARTBEAT,
|
|
3
|
+
createRoomServer
|
|
4
|
+
} from "./chunk-INZKL5US.js";
|
|
5
|
+
import "./chunk-JYI2GKLJ.js";
|
|
6
|
+
import "./chunk-5YSBR6YK.js";
|
|
7
|
+
import "./chunk-64G5AWIQ.js";
|
|
8
|
+
import "./chunk-2BHF5ZCS.js";
|
|
9
|
+
export {
|
|
10
|
+
DEFAULT_ROOM_SERVER_HEARTBEAT,
|
|
11
|
+
createRoomServer
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=room-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/room.d.ts
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { SeatId, SeatKind, HostHello, RoomLimits, StateDocument, RoomCloseReason, RoomRole, RoomAcceptor, RoomAddress, RoomConnection, RoomConnectionHandlers } from '@air-jam/sdk/room-protocol';
|
|
2
|
+
import { RoomClock } from '@air-jam/sdk/room-session';
|
|
3
|
+
|
|
4
|
+
/** Whatever the gate attached when it admitted the host, such as app and game for hosted rooms. */
|
|
5
|
+
type RoomLabels = Readonly<Record<string, string>>;
|
|
6
|
+
type RoomCloseCause = "ended" | "host-gone" | "expired" | "operator" | "restarting";
|
|
7
|
+
type SeatLeaveCause = "left" | "removed" | "dropped";
|
|
8
|
+
type RoomEvent = {
|
|
9
|
+
readonly kind: "opened";
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: "seat-joined";
|
|
12
|
+
readonly seat: SeatId;
|
|
13
|
+
readonly seatKind: SeatKind;
|
|
14
|
+
/** The seat was held for a phone that dropped and has now returned. */
|
|
15
|
+
readonly resumed: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: "seat-dropped";
|
|
18
|
+
readonly seat: SeatId;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: "seat-left";
|
|
21
|
+
readonly seat: SeatId;
|
|
22
|
+
readonly cause: SeatLeaveCause;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "activity";
|
|
25
|
+
readonly activity: string | null;
|
|
26
|
+
/** The activity this one replaced, so the fact reads on its own. */
|
|
27
|
+
readonly previous: string | null;
|
|
28
|
+
} | {
|
|
29
|
+
readonly kind: "closed";
|
|
30
|
+
readonly cause: RoomCloseCause;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* What a room reports as it happens. The public server logs facts; hosted
|
|
34
|
+
* rooms deliver them to the platform as usage.
|
|
35
|
+
*/
|
|
36
|
+
type RoomFact = {
|
|
37
|
+
readonly at: number;
|
|
38
|
+
readonly code: string;
|
|
39
|
+
readonly instance: string;
|
|
40
|
+
readonly labels: RoomLabels;
|
|
41
|
+
} & RoomEvent;
|
|
42
|
+
|
|
43
|
+
interface RoomGateRequest {
|
|
44
|
+
readonly hello: HostHello;
|
|
45
|
+
/** The connection's origin header, when the transport has one. */
|
|
46
|
+
readonly origin: string | null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The gate answers whether a host may open a room, before the room exists.
|
|
50
|
+
* It runs in the host's front door, not in the room, so it may take its time.
|
|
51
|
+
*/
|
|
52
|
+
type RoomGateDecision = {
|
|
53
|
+
readonly outcome: "open";
|
|
54
|
+
readonly limits: RoomLimits;
|
|
55
|
+
readonly labels: RoomLabels;
|
|
56
|
+
readonly activity: string | null;
|
|
57
|
+
readonly activityChangeable: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** Admission is queued; the front door tells the host its place. */
|
|
60
|
+
| {
|
|
61
|
+
readonly outcome: "wait";
|
|
62
|
+
readonly position: number;
|
|
63
|
+
} | {
|
|
64
|
+
readonly outcome: "refuse";
|
|
65
|
+
readonly reason: "unauthorised" | "try-later";
|
|
66
|
+
};
|
|
67
|
+
interface RoomGate {
|
|
68
|
+
admit(request: RoomGateRequest): RoomGateDecision | Promise<RoomGateDecision>;
|
|
69
|
+
}
|
|
70
|
+
/** Admits every host, as a local or private server does. */
|
|
71
|
+
declare const createOpenRoomGate: (limits?: RoomLimits) => RoomGate;
|
|
72
|
+
/**
|
|
73
|
+
* Admits hosts whose credential is the server's shared master key. Such a
|
|
74
|
+
* host runs one game, so it may not change what is on screen.
|
|
75
|
+
*/
|
|
76
|
+
declare const createMasterKeyRoomGate: (masterKey: string, limits?: RoomLimits) => RoomGate;
|
|
77
|
+
|
|
78
|
+
interface SavedChannel {
|
|
79
|
+
readonly channel: string;
|
|
80
|
+
readonly revision: number;
|
|
81
|
+
readonly document: StateDocument;
|
|
82
|
+
readonly fingerprint?: string;
|
|
83
|
+
readonly private?: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A room's durable state. Saved state outlives a deploy, so a newer release
|
|
88
|
+
* must read what an older one wrote: raise the schema with every change and
|
|
89
|
+
* migrate older ones when restoring.
|
|
90
|
+
*/
|
|
91
|
+
declare const ROOM_SAVE_SCHEMA = 1;
|
|
92
|
+
/** Chosen by the host that holds the connection; opaque to the room. */
|
|
93
|
+
type ConnectionId = string;
|
|
94
|
+
interface SavedRoomRecord {
|
|
95
|
+
readonly code: string;
|
|
96
|
+
readonly instance: string;
|
|
97
|
+
readonly hostKey: string;
|
|
98
|
+
readonly limits: RoomLimits;
|
|
99
|
+
readonly labels: RoomLabels;
|
|
100
|
+
readonly activity: string | null;
|
|
101
|
+
readonly activityChangeable: boolean;
|
|
102
|
+
readonly openedAt: number;
|
|
103
|
+
readonly seatsWanted: number;
|
|
104
|
+
readonly locked: boolean;
|
|
105
|
+
readonly nextSeatNumber: number;
|
|
106
|
+
readonly hostConnection: ConnectionId | null;
|
|
107
|
+
/** When the room closes unless its host returns; null while the host is in. */
|
|
108
|
+
readonly hostAwayUntil: number | null;
|
|
109
|
+
}
|
|
110
|
+
interface SavedSeat {
|
|
111
|
+
readonly id: SeatId;
|
|
112
|
+
readonly key: string;
|
|
113
|
+
readonly kind: SeatKind;
|
|
114
|
+
/** The player's own label, shown whenever no local seat label covers it. */
|
|
115
|
+
readonly label: string;
|
|
116
|
+
readonly localSeatLabel?: string;
|
|
117
|
+
readonly avatarId?: string;
|
|
118
|
+
readonly color: string;
|
|
119
|
+
/** The page the seat's phone last joined from. */
|
|
120
|
+
readonly page?: string;
|
|
121
|
+
readonly connection: ConnectionId | null;
|
|
122
|
+
/** When the seat is freed unless its phone returns; null while connected. */
|
|
123
|
+
readonly holdUntil: number | null;
|
|
124
|
+
}
|
|
125
|
+
interface SavedRoom {
|
|
126
|
+
readonly schema: number;
|
|
127
|
+
readonly room: SavedRoomRecord;
|
|
128
|
+
readonly seats: Readonly<Record<SeatId, SavedSeat>>;
|
|
129
|
+
readonly channels: Readonly<Record<string, SavedChannel>>;
|
|
130
|
+
}
|
|
131
|
+
/** The durable slices that changed since the last save; null marks one deleted. */
|
|
132
|
+
interface SavedRoomChanges {
|
|
133
|
+
readonly schema: number;
|
|
134
|
+
readonly room?: SavedRoomRecord;
|
|
135
|
+
readonly seats: Readonly<Record<SeatId, SavedSeat | null>>;
|
|
136
|
+
readonly channels: Readonly<Record<string, SavedChannel | null>>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface RoomSetup {
|
|
140
|
+
readonly code: string;
|
|
141
|
+
readonly instance: string;
|
|
142
|
+
/** The opening host's key; only it can be the host of this room. */
|
|
143
|
+
readonly hostKey: string;
|
|
144
|
+
readonly limits: RoomLimits;
|
|
145
|
+
readonly labels: RoomLabels;
|
|
146
|
+
/** What is on screen as the room opens, such as the game a hosted grant names. */
|
|
147
|
+
readonly activity: string | null;
|
|
148
|
+
/** Whether the host may change it, as a launcher does when it starts a game. */
|
|
149
|
+
readonly activityChangeable: boolean;
|
|
150
|
+
}
|
|
151
|
+
type RoomEffect = {
|
|
152
|
+
readonly send: ConnectionId;
|
|
153
|
+
readonly data: string | Uint8Array;
|
|
154
|
+
} | {
|
|
155
|
+
readonly close: ConnectionId;
|
|
156
|
+
readonly reason: RoomCloseReason;
|
|
157
|
+
} | {
|
|
158
|
+
readonly fact: RoomFact;
|
|
159
|
+
};
|
|
160
|
+
type RoomStopReason = "operator" | "restarting";
|
|
161
|
+
interface RoomDescription {
|
|
162
|
+
readonly code: string;
|
|
163
|
+
readonly instance: string;
|
|
164
|
+
readonly labels: RoomLabels;
|
|
165
|
+
readonly openedAt: number;
|
|
166
|
+
readonly closed: boolean;
|
|
167
|
+
readonly activity: string | null;
|
|
168
|
+
readonly limits: RoomLimits;
|
|
169
|
+
readonly seatsWanted: number;
|
|
170
|
+
readonly locked: boolean;
|
|
171
|
+
readonly host: {
|
|
172
|
+
readonly connected: boolean;
|
|
173
|
+
readonly awayUntil: number | null;
|
|
174
|
+
};
|
|
175
|
+
readonly seats: ReadonlyArray<{
|
|
176
|
+
readonly id: SeatId;
|
|
177
|
+
readonly kind: SeatKind;
|
|
178
|
+
readonly label: string;
|
|
179
|
+
readonly connected: boolean;
|
|
180
|
+
readonly holdUntil: number | null;
|
|
181
|
+
}>;
|
|
182
|
+
readonly channels: ReadonlyArray<{
|
|
183
|
+
readonly channel: string;
|
|
184
|
+
readonly revision: number;
|
|
185
|
+
readonly weight: number;
|
|
186
|
+
}>;
|
|
187
|
+
/** Frames handled since this room was opened or restored. */
|
|
188
|
+
readonly counters: Readonly<RoomCounters>;
|
|
189
|
+
}
|
|
190
|
+
interface RoomCounters {
|
|
191
|
+
inputs: number;
|
|
192
|
+
states: number;
|
|
193
|
+
requests: number;
|
|
194
|
+
signals: number;
|
|
195
|
+
/** Frames over their lane's rate; a phone's latest input among them still arrives when the rate allows. */
|
|
196
|
+
overRate: number;
|
|
197
|
+
strikes: number;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* One host, its seats and what flows between them. Bytes and the current time
|
|
201
|
+
* go in; frames to send, connections to close and facts come out. The room
|
|
202
|
+
* never waits, sets a timer, reads a clock or draws a random number: every
|
|
203
|
+
* deadline is a timestamp in its state, and `nextWake` says when the host
|
|
204
|
+
* should call `wake`. Every entry point first applies the deadlines that have
|
|
205
|
+
* passed, so a late wake changes nothing a device can observe.
|
|
206
|
+
*/
|
|
207
|
+
declare class Room {
|
|
208
|
+
private readonly code;
|
|
209
|
+
private readonly instance;
|
|
210
|
+
private readonly hostKey;
|
|
211
|
+
private readonly limits;
|
|
212
|
+
private readonly labels;
|
|
213
|
+
private readonly activityChangeable;
|
|
214
|
+
private readonly openedAt;
|
|
215
|
+
private readonly seats;
|
|
216
|
+
private readonly seatsByKey;
|
|
217
|
+
private readonly connections;
|
|
218
|
+
private readonly channels;
|
|
219
|
+
private readonly counters;
|
|
220
|
+
/** Each phone's latest input that arrived over its rate, delivered when its rate window ends. */
|
|
221
|
+
private readonly heldInputs;
|
|
222
|
+
private hostConnection;
|
|
223
|
+
private hostAwayUntil;
|
|
224
|
+
private activity;
|
|
225
|
+
private seatsWanted;
|
|
226
|
+
private locked;
|
|
227
|
+
private nextSeatNumber;
|
|
228
|
+
private closed;
|
|
229
|
+
private roomChanged;
|
|
230
|
+
private readonly changedSeats;
|
|
231
|
+
private readonly changedChannels;
|
|
232
|
+
private effects;
|
|
233
|
+
private constructor();
|
|
234
|
+
static open(setup: RoomSetup, now: number): {
|
|
235
|
+
room: Room;
|
|
236
|
+
effects: RoomEffect[];
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Rebuilds a room from its saved state and the connections still open, as
|
|
240
|
+
* a Durable Object does when it wakes. Devices whose connection closed
|
|
241
|
+
* while the room was away are treated as having dropped now. State saved by
|
|
242
|
+
* a newer release cannot be read: every connection is told the server is
|
|
243
|
+
* restarting and there is no room.
|
|
244
|
+
*/
|
|
245
|
+
static restore(saved: SavedRoom, live: readonly ConnectionId[], now: number): {
|
|
246
|
+
room: Room | null;
|
|
247
|
+
effects: RoomEffect[];
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* A device's first frame. `role` comes from the path it connected to, so
|
|
251
|
+
* the path alone decides who may act as a host.
|
|
252
|
+
*/
|
|
253
|
+
connect(connection: ConnectionId, role: RoomRole, hello: string, now: number): RoomEffect[];
|
|
254
|
+
receive(connection: ConnectionId, data: string | Uint8Array, now: number): RoomEffect[];
|
|
255
|
+
disconnect(connection: ConnectionId, now: number): RoomEffect[];
|
|
256
|
+
wake(now: number): RoomEffect[];
|
|
257
|
+
stop(reason: RoomStopReason, now: number): RoomEffect[];
|
|
258
|
+
/** The earliest moment something is due, or null once the room is closed. */
|
|
259
|
+
nextWake(): number | null;
|
|
260
|
+
save(): SavedRoomChanges | null;
|
|
261
|
+
describe(): RoomDescription;
|
|
262
|
+
private run;
|
|
263
|
+
private settle;
|
|
264
|
+
private reconnect;
|
|
265
|
+
private connectHost;
|
|
266
|
+
private connectPhone;
|
|
267
|
+
private createSeat;
|
|
268
|
+
private receiveHostText;
|
|
269
|
+
private handleHostFrame;
|
|
270
|
+
private receivePhoneText;
|
|
271
|
+
private handlePhoneFrame;
|
|
272
|
+
private receiveInput;
|
|
273
|
+
private forwardInput;
|
|
274
|
+
/**
|
|
275
|
+
* A frame the room does not act on still spends its lane's flood
|
|
276
|
+
* allowance; one that does not parse is also a strike, and one nested too
|
|
277
|
+
* deep breaks the limits outright.
|
|
278
|
+
*/
|
|
279
|
+
private ignore;
|
|
280
|
+
private strike;
|
|
281
|
+
/** Sizes are a property of the content, so a breach is final rather than counted. */
|
|
282
|
+
private breakLimits;
|
|
283
|
+
/** What follows a connection ending while its host or seat stays. */
|
|
284
|
+
private release;
|
|
285
|
+
private hostLeft;
|
|
286
|
+
private seatLeft;
|
|
287
|
+
private freeSeat;
|
|
288
|
+
private closeRoom;
|
|
289
|
+
private announceSeat;
|
|
290
|
+
private seatView;
|
|
291
|
+
private seatViews;
|
|
292
|
+
private toHost;
|
|
293
|
+
private toPhones;
|
|
294
|
+
private send;
|
|
295
|
+
private closeConnection;
|
|
296
|
+
private fact;
|
|
297
|
+
private record;
|
|
298
|
+
private savedSeat;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
interface MemoryRoomHostOptions {
|
|
302
|
+
readonly gate: RoomGate;
|
|
303
|
+
/** Whether a host may ask for its room's code, as a local server allows; hosted rooms choose. */
|
|
304
|
+
readonly codesMayBeAsked: boolean;
|
|
305
|
+
readonly clock?: RoomClock;
|
|
306
|
+
/**
|
|
307
|
+
* Runs `flush` once the work of the current turn is done. Input bound for
|
|
308
|
+
* one host that became ready in the same turn leaves as one message; the
|
|
309
|
+
* default packs what one synchronous run produced.
|
|
310
|
+
*/
|
|
311
|
+
readonly afterTurn?: (flush: () => void) => void;
|
|
312
|
+
readonly onFact?: (fact: RoomFact) => void;
|
|
313
|
+
/** A gate that failed; the host was told to try later. */
|
|
314
|
+
readonly onGateError?: (error: unknown) => void;
|
|
315
|
+
/** How long a queued host waits before the gate is asked again. */
|
|
316
|
+
readonly gateRetryMs?: number;
|
|
317
|
+
}
|
|
318
|
+
/** How long a connection may stay open without saying hello. */
|
|
319
|
+
declare const HELLO_DEADLINE_MS = 15000;
|
|
320
|
+
/**
|
|
321
|
+
* Rooms held in memory, for the Node server and for in-process loopback
|
|
322
|
+
* links. It owns only wiring: it routes a connection by its path, runs the
|
|
323
|
+
* gate before a room exists, calls the room with the role from the path,
|
|
324
|
+
* applies the effects the room returns, keeps one timer per room for its
|
|
325
|
+
* next deadline and packs host-bound input that is ready together. Every
|
|
326
|
+
* room rule is the room's own.
|
|
327
|
+
*/
|
|
328
|
+
declare class MemoryRoomHost implements RoomAcceptor {
|
|
329
|
+
private readonly options;
|
|
330
|
+
private readonly rooms;
|
|
331
|
+
private readonly connections;
|
|
332
|
+
private readonly pendingInput;
|
|
333
|
+
private flushScheduled;
|
|
334
|
+
private nextConnection;
|
|
335
|
+
private stopped;
|
|
336
|
+
private readonly clock;
|
|
337
|
+
private readonly afterTurn;
|
|
338
|
+
constructor(options: MemoryRoomHostOptions);
|
|
339
|
+
accept(address: RoomAddress, origin: string | null, transport: RoomConnection): RoomConnectionHandlers;
|
|
340
|
+
/** Stops every room as the server goes down; its devices are told to come back. */
|
|
341
|
+
stop(): void;
|
|
342
|
+
describe(): RoomDescription[];
|
|
343
|
+
private receive;
|
|
344
|
+
private hello;
|
|
345
|
+
private admit;
|
|
346
|
+
private bind;
|
|
347
|
+
private closed;
|
|
348
|
+
private call;
|
|
349
|
+
private apply;
|
|
350
|
+
private scheduleWake;
|
|
351
|
+
private retire;
|
|
352
|
+
private queueInput;
|
|
353
|
+
/** Sends what is queued for a host before anything that follows it, keeping order. */
|
|
354
|
+
private flushInput;
|
|
355
|
+
private closeConnection;
|
|
356
|
+
private forget;
|
|
357
|
+
private freeCode;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export { type ConnectionId, HELLO_DEADLINE_MS, MemoryRoomHost, type MemoryRoomHostOptions, ROOM_SAVE_SCHEMA, Room, type RoomCloseCause, type RoomDescription, type RoomEffect, type RoomEvent, type RoomFact, type RoomGate, type RoomGateDecision, type RoomGateRequest, type RoomLabels, type RoomSetup, type RoomStopReason, type SavedChannel, type SavedRoom, type SavedRoomChanges, type SavedRoomRecord, type SavedSeat, type SeatLeaveCause, createMasterKeyRoomGate, createOpenRoomGate };
|
package/dist/room.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HELLO_DEADLINE_MS,
|
|
3
|
+
MemoryRoomHost,
|
|
4
|
+
ROOM_SAVE_SCHEMA,
|
|
5
|
+
Room,
|
|
6
|
+
createMasterKeyRoomGate,
|
|
7
|
+
createOpenRoomGate
|
|
8
|
+
} from "./chunk-64G5AWIQ.js";
|
|
9
|
+
export {
|
|
10
|
+
HELLO_DEADLINE_MS,
|
|
11
|
+
MemoryRoomHost,
|
|
12
|
+
ROOM_SAVE_SCHEMA,
|
|
13
|
+
Room,
|
|
14
|
+
createMasterKeyRoomGate,
|
|
15
|
+
createOpenRoomGate
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=room.js.map
|
package/dist/room.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@air-jam/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22.0.0"
|
|
6
6
|
},
|
|
7
|
-
"description": "
|
|
7
|
+
"description": "The Air Jam room server — rooms, seats, state and input for phone-controller multiplayer party games, over one WebSocket per device.",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"air-jam",
|
|
10
10
|
"airjam",
|
|
@@ -16,13 +16,11 @@
|
|
|
16
16
|
"party-games",
|
|
17
17
|
"phone-controller",
|
|
18
18
|
"websocket",
|
|
19
|
-
"socket.io",
|
|
20
19
|
"real-time",
|
|
21
20
|
"realtime",
|
|
22
21
|
"room-management",
|
|
23
22
|
"game-server",
|
|
24
23
|
"node",
|
|
25
|
-
"express",
|
|
26
24
|
"game-development",
|
|
27
25
|
"gamedev"
|
|
28
26
|
],
|
|
@@ -48,6 +46,14 @@
|
|
|
48
46
|
".": {
|
|
49
47
|
"types": "./dist/index.d.ts",
|
|
50
48
|
"import": "./dist/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./room": {
|
|
51
|
+
"types": "./dist/room.d.ts",
|
|
52
|
+
"import": "./dist/room.js"
|
|
53
|
+
},
|
|
54
|
+
"./room-server": {
|
|
55
|
+
"types": "./dist/room-server.d.ts",
|
|
56
|
+
"import": "./dist/room-server.js"
|
|
51
57
|
}
|
|
52
58
|
},
|
|
53
59
|
"files": [
|
|
@@ -55,23 +61,16 @@
|
|
|
55
61
|
"dist"
|
|
56
62
|
],
|
|
57
63
|
"dependencies": {
|
|
58
|
-
"@air-jam/sdk": "0.
|
|
59
|
-
"@types/express": "^5.0.6",
|
|
60
|
-
"color": "^5.0.3",
|
|
64
|
+
"@air-jam/sdk": "1.0.0-beta.2",
|
|
61
65
|
"commander": "^14.0.0",
|
|
62
|
-
"cors": "^2.8.5",
|
|
63
66
|
"dotenv": "^17.2.3",
|
|
64
|
-
"express": "^5.2.1",
|
|
65
67
|
"pino": "^10.3.1",
|
|
66
|
-
"
|
|
67
|
-
"uuid": "^13.0.2",
|
|
68
|
+
"ws": "^8.18.3",
|
|
68
69
|
"zod": "^4.2.1"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
|
-
"@types/cors": "^2.8.17",
|
|
72
72
|
"@types/node": "^24.10.1",
|
|
73
|
-
"@types/
|
|
74
|
-
"socket.io-client": "^4.8.1",
|
|
73
|
+
"@types/ws": "^8.18.1",
|
|
75
74
|
"tsup": "^8.5.1",
|
|
76
75
|
"tsx": "^4.19.2",
|
|
77
76
|
"typescript": "~5.9.3",
|
|
@@ -84,7 +83,6 @@
|
|
|
84
83
|
"build": "node ../../scripts/ensure-workspace-package-build.mjs @air-jam/sdk && tsup",
|
|
85
84
|
"test": "node ../../scripts/ensure-workspace-package-build.mjs @air-jam/sdk && vitest run --config vitest.config.ts",
|
|
86
85
|
"test:watch": "vitest --config vitest.config.ts",
|
|
87
|
-
"perf:sanity": "tsx scripts/perf-sanity.ts",
|
|
88
86
|
"typecheck": "node ../../scripts/ensure-workspace-package-build.mjs @air-jam/sdk && tsc --noEmit && tsc -p tests/tsconfig.json --noEmit"
|
|
89
87
|
}
|
|
90
88
|
}
|