@cardonjs/realtime-do 0.0.0-stage → 0.2.3
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/LICENSE +21 -0
- package/README.md +558 -2
- package/dist/client.d.ts +56 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +286 -0
- package/dist/client.js.map +1 -0
- package/dist/connect.d.ts +27 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +82 -0
- package/dist/connect.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/presence.d.ts +68 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +88 -0
- package/dist/presence.js.map +1 -0
- package/dist/protocol.d.ts +50 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +86 -0
- package/dist/protocol.js.map +1 -0
- package/dist/publisher.d.ts +39 -0
- package/dist/publisher.d.ts.map +1 -0
- package/dist/publisher.js +101 -0
- package/dist/publisher.js.map +1 -0
- package/dist/room.d.ts +58 -0
- package/dist/room.d.ts.map +1 -0
- package/dist/room.js +400 -0
- package/dist/room.js.map +1 -0
- package/dist/testing.d.ts +65 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +99 -0
- package/dist/testing.js.map +1 -0
- package/dist/validation.d.ts +39 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +106 -0
- package/dist/validation.js.map +1 -0
- package/llms.txt +189 -0
- package/package.json +58 -3
package/dist/client.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reconnecting browser client for a room. Zero dependencies and no Workers types: it runs in the
|
|
3
|
+
* browser. Import it from `@cardonjs/realtime-do/client`.
|
|
4
|
+
*
|
|
5
|
+
* The socket only signals "something changed": events are hints, and `onResync` reloads the
|
|
6
|
+
* state from the API after every reconnect and on each fallback poll while disconnected.
|
|
7
|
+
*/
|
|
8
|
+
import { EVENT_TYPE_PATTERN, NAME_PATTERN } from "./validation.js";
|
|
9
|
+
/** A connection that stays open this long resets the backoff. */
|
|
10
|
+
const STABLE_AFTER_MS = 10_000;
|
|
11
|
+
const CLOSE_PROTOCOL = 1008;
|
|
12
|
+
const CLOSE_REAUTHENTICATE = 4000;
|
|
13
|
+
function isLocalHost(hostname) {
|
|
14
|
+
return (hostname === "localhost" ||
|
|
15
|
+
hostname.endsWith(".localhost") ||
|
|
16
|
+
hostname === "127.0.0.1" ||
|
|
17
|
+
hostname === "[::1]");
|
|
18
|
+
}
|
|
19
|
+
function resolveUrl(raw) {
|
|
20
|
+
const invalid = () => new TypeError("createRealtimeClient: url must be a wss: URL or a path (ws: only from an http: page on a local development host, to a local host).");
|
|
21
|
+
if (typeof raw !== "string" || raw === "")
|
|
22
|
+
throw invalid();
|
|
23
|
+
const location = globalThis.location;
|
|
24
|
+
let url;
|
|
25
|
+
try {
|
|
26
|
+
url = location === undefined ? new URL(raw) : new URL(raw, location.href);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw invalid();
|
|
30
|
+
}
|
|
31
|
+
if (url.protocol === "https:")
|
|
32
|
+
url.protocol = "wss:";
|
|
33
|
+
else if (url.protocol === "http:")
|
|
34
|
+
url.protocol = "ws:";
|
|
35
|
+
if (url.username !== "" || url.password !== "")
|
|
36
|
+
throw invalid();
|
|
37
|
+
const localDevelopment = location !== undefined &&
|
|
38
|
+
location.protocol === "http:" &&
|
|
39
|
+
isLocalHost(location.hostname) &&
|
|
40
|
+
isLocalHost(url.hostname);
|
|
41
|
+
if (url.protocol !== "wss:" && !(url.protocol === "ws:" && localDevelopment))
|
|
42
|
+
throw invalid();
|
|
43
|
+
url.hash = "";
|
|
44
|
+
return url.href;
|
|
45
|
+
}
|
|
46
|
+
function integer(name, value, fallback, min) {
|
|
47
|
+
if (value === undefined)
|
|
48
|
+
return fallback;
|
|
49
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < min) {
|
|
50
|
+
throw new TypeError(`createRealtimeClient: ${name} must be an integer of at least ${min}.`);
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
/** A frozen event, or `undefined` for anything that is not a well-formed event frame. */
|
|
55
|
+
function parseFrame(data) {
|
|
56
|
+
if (typeof data !== "string")
|
|
57
|
+
return undefined;
|
|
58
|
+
let value;
|
|
59
|
+
try {
|
|
60
|
+
value = JSON.parse(data);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
66
|
+
return undefined;
|
|
67
|
+
const { channel, type, data: payload } = value;
|
|
68
|
+
if (typeof channel !== "string" || !NAME_PATTERN.test(channel))
|
|
69
|
+
return undefined;
|
|
70
|
+
if (typeof type !== "string" || !EVENT_TYPE_PATTERN.test(type))
|
|
71
|
+
return undefined;
|
|
72
|
+
return Object.freeze(payload === undefined
|
|
73
|
+
? { channel, type }
|
|
74
|
+
: { channel, type, data: payload });
|
|
75
|
+
}
|
|
76
|
+
// Browsers and Workers type the clear functions differently for "no timer"; never pass one.
|
|
77
|
+
function stopTimeout(timer) {
|
|
78
|
+
if (timer !== undefined)
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
}
|
|
81
|
+
function stopInterval(timer) {
|
|
82
|
+
if (timer !== undefined)
|
|
83
|
+
clearInterval(timer);
|
|
84
|
+
}
|
|
85
|
+
/** Runs a callback; neither a throw nor a rejection breaks the client. */
|
|
86
|
+
function safely(callback) {
|
|
87
|
+
try {
|
|
88
|
+
const result = callback();
|
|
89
|
+
if (result instanceof Promise)
|
|
90
|
+
result.catch(() => undefined);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// The app's callback failed; the client keeps going.
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Opens the socket and keeps it open: exponential backoff with full jitter between
|
|
98
|
+
* `minBackoffMs` and `maxBackoffMs` (reset once a connection stays open for 10 s), `"ping"`
|
|
99
|
+
* every `pingIntervalMs` with a `pongTimeoutMs` deadline, and fallback polling through
|
|
100
|
+
* `onResync` while disconnected.
|
|
101
|
+
*
|
|
102
|
+
* Close codes: 1008 stops for good (status `"closed"`); 4000 reconnects after a random delay
|
|
103
|
+
* below `minBackoffMs` (sockets that expire together do not come back together); anything
|
|
104
|
+
* else reconnects with backoff.
|
|
105
|
+
*
|
|
106
|
+
* Call `close()` when the API refuses the user (e.g. `onResync` gets a 401 or 403): the
|
|
107
|
+
* client cannot tell, and keeps retrying otherwise.
|
|
108
|
+
*/
|
|
109
|
+
export function createRealtimeClient(options) {
|
|
110
|
+
if (typeof options !== "object" || options === null) {
|
|
111
|
+
throw new TypeError("createRealtimeClient: options must be an object.");
|
|
112
|
+
}
|
|
113
|
+
if (typeof options.onEvent !== "function" || typeof options.onResync !== "function") {
|
|
114
|
+
throw new TypeError("createRealtimeClient: onEvent and onResync must be functions.");
|
|
115
|
+
}
|
|
116
|
+
if (options.onStatus !== undefined && typeof options.onStatus !== "function") {
|
|
117
|
+
throw new TypeError("createRealtimeClient: onStatus must be a function.");
|
|
118
|
+
}
|
|
119
|
+
const url = resolveUrl(options.url);
|
|
120
|
+
const pollIntervalMs = integer("pollIntervalMs", options.pollIntervalMs, 30_000, 0);
|
|
121
|
+
const pingIntervalMs = integer("pingIntervalMs", options.pingIntervalMs, 25_000, 1);
|
|
122
|
+
const pongTimeoutMs = integer("pongTimeoutMs", options.pongTimeoutMs, 10_000, 1);
|
|
123
|
+
const minBackoffMs = integer("minBackoffMs", options.minBackoffMs, 1000, 1);
|
|
124
|
+
const maxBackoffMs = integer("maxBackoffMs", options.maxBackoffMs, 30_000, minBackoffMs);
|
|
125
|
+
const random = options.random ?? Math.random;
|
|
126
|
+
if (typeof random !== "function") {
|
|
127
|
+
throw new TypeError("createRealtimeClient: random must be a function.");
|
|
128
|
+
}
|
|
129
|
+
const candidate = options.WebSocket ?? globalThis.WebSocket;
|
|
130
|
+
if (typeof candidate !== "function") {
|
|
131
|
+
throw new TypeError("createRealtimeClient: no WebSocket implementation is available.");
|
|
132
|
+
}
|
|
133
|
+
const Socket = candidate;
|
|
134
|
+
let status = "connecting";
|
|
135
|
+
let stopped = false;
|
|
136
|
+
let socket;
|
|
137
|
+
let attempt = 0;
|
|
138
|
+
let opened = false;
|
|
139
|
+
let reconnectTimer;
|
|
140
|
+
let stableTimer;
|
|
141
|
+
let pongTimer;
|
|
142
|
+
let pingTimer;
|
|
143
|
+
let pollTimer;
|
|
144
|
+
const setStatus = (next) => {
|
|
145
|
+
if (status === next)
|
|
146
|
+
return;
|
|
147
|
+
status = next;
|
|
148
|
+
safely(() => options.onStatus?.(next));
|
|
149
|
+
};
|
|
150
|
+
const resync = () => safely(() => options.onResync());
|
|
151
|
+
const stopPolling = () => {
|
|
152
|
+
stopInterval(pollTimer);
|
|
153
|
+
pollTimer = undefined;
|
|
154
|
+
};
|
|
155
|
+
const startPolling = () => {
|
|
156
|
+
if (pollIntervalMs > 0 && pollTimer === undefined) {
|
|
157
|
+
pollTimer = setInterval(() => {
|
|
158
|
+
if (!stopped)
|
|
159
|
+
resync();
|
|
160
|
+
}, pollIntervalMs);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
/** Detaches the current socket so none of its late events are handled. */
|
|
164
|
+
const release = () => {
|
|
165
|
+
const current = socket;
|
|
166
|
+
socket = undefined;
|
|
167
|
+
stopInterval(pingTimer);
|
|
168
|
+
stopTimeout(pongTimer);
|
|
169
|
+
stopTimeout(stableTimer);
|
|
170
|
+
pingTimer = pongTimer = stableTimer = undefined;
|
|
171
|
+
if (current) {
|
|
172
|
+
current.onopen = current.onmessage = current.onclose = current.onerror = null;
|
|
173
|
+
}
|
|
174
|
+
return current;
|
|
175
|
+
};
|
|
176
|
+
const backoff = () => {
|
|
177
|
+
const cap = Math.min(maxBackoffMs, minBackoffMs * 2 ** (attempt + 1));
|
|
178
|
+
attempt++;
|
|
179
|
+
return Math.min(maxBackoffMs, minBackoffMs + Math.floor(random() * (cap - minBackoffMs)));
|
|
180
|
+
};
|
|
181
|
+
const scheduleReconnect = (reauthenticate) => {
|
|
182
|
+
if (stopped)
|
|
183
|
+
return;
|
|
184
|
+
setStatus("reconnecting");
|
|
185
|
+
if (stopped)
|
|
186
|
+
return; // `onStatus` called close().
|
|
187
|
+
startPolling();
|
|
188
|
+
stopTimeout(reconnectTimer);
|
|
189
|
+
// 4000: soon, but spread over [0, minBackoffMs) so expired sockets do not return as a herd.
|
|
190
|
+
const delay = reauthenticate ? Math.floor(random() * minBackoffMs) : backoff();
|
|
191
|
+
reconnectTimer = setTimeout(connect, Math.min(Math.max(delay, 0), maxBackoffMs));
|
|
192
|
+
};
|
|
193
|
+
function connect() {
|
|
194
|
+
reconnectTimer = undefined;
|
|
195
|
+
if (stopped)
|
|
196
|
+
return;
|
|
197
|
+
let ws;
|
|
198
|
+
try {
|
|
199
|
+
ws = new Socket(url);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
scheduleReconnect(false);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
socket = ws;
|
|
206
|
+
ws.onopen = () => {
|
|
207
|
+
stopPolling();
|
|
208
|
+
const reconnected = opened;
|
|
209
|
+
opened = true;
|
|
210
|
+
setStatus("open");
|
|
211
|
+
if (stopped)
|
|
212
|
+
return; // `onStatus` called close().
|
|
213
|
+
stableTimer = setTimeout(() => {
|
|
214
|
+
attempt = 0;
|
|
215
|
+
}, STABLE_AFTER_MS);
|
|
216
|
+
pingTimer = setInterval(() => {
|
|
217
|
+
try {
|
|
218
|
+
ws.send("ping");
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
// The close event follows.
|
|
222
|
+
}
|
|
223
|
+
if (pongTimer === undefined) {
|
|
224
|
+
pongTimer = setTimeout(() => {
|
|
225
|
+
// No pong: the connection is dead even if the browser has not noticed.
|
|
226
|
+
const dead = release();
|
|
227
|
+
try {
|
|
228
|
+
dead?.close(1000, "No pong");
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
// Already closing.
|
|
232
|
+
}
|
|
233
|
+
scheduleReconnect(false);
|
|
234
|
+
}, pongTimeoutMs);
|
|
235
|
+
}
|
|
236
|
+
}, pingIntervalMs);
|
|
237
|
+
if (reconnected)
|
|
238
|
+
resync();
|
|
239
|
+
};
|
|
240
|
+
ws.onmessage = (event) => {
|
|
241
|
+
if (event.data === "pong") {
|
|
242
|
+
stopTimeout(pongTimer);
|
|
243
|
+
pongTimer = undefined;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const parsed = parseFrame(event.data);
|
|
247
|
+
if (parsed !== undefined)
|
|
248
|
+
safely(() => options.onEvent(parsed));
|
|
249
|
+
};
|
|
250
|
+
ws.onclose = (event) => {
|
|
251
|
+
release();
|
|
252
|
+
if (event.code === CLOSE_PROTOCOL) {
|
|
253
|
+
stop();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
scheduleReconnect(event.code === CLOSE_REAUTHENTICATE);
|
|
257
|
+
};
|
|
258
|
+
// An error is always followed by a close event.
|
|
259
|
+
ws.onerror = () => undefined;
|
|
260
|
+
}
|
|
261
|
+
function stop() {
|
|
262
|
+
stopped = true;
|
|
263
|
+
stopTimeout(reconnectTimer);
|
|
264
|
+
reconnectTimer = undefined;
|
|
265
|
+
stopPolling();
|
|
266
|
+
const current = release();
|
|
267
|
+
try {
|
|
268
|
+
current?.close(1000, "Closed");
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
// Already closing.
|
|
272
|
+
}
|
|
273
|
+
setStatus("closed");
|
|
274
|
+
}
|
|
275
|
+
connect();
|
|
276
|
+
return {
|
|
277
|
+
get status() {
|
|
278
|
+
return status;
|
|
279
|
+
},
|
|
280
|
+
close() {
|
|
281
|
+
if (!stopped)
|
|
282
|
+
stop();
|
|
283
|
+
},
|
|
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ED,OAAO,EAAE,CAAC;IAEV,OAAO;QACL,IAAI,MAAM;YACR,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,KAAK;YACH,IAAI,CAAC,OAAO;gBAAE,IAAI,EAAE,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type RoomIdentity } from "./protocol.js";
|
|
2
|
+
export interface ConnectOptions {
|
|
3
|
+
readonly identity: RoomIdentity;
|
|
4
|
+
/** Chosen by the server; a client cannot subscribe to anything. 1 to 8, no repeats. */
|
|
5
|
+
readonly channels: readonly string[];
|
|
6
|
+
/** Exact origins allowed to open the socket, e.g. ["https://app.example.com"]. Required. */
|
|
7
|
+
readonly allowedOrigins: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Checks the upgrade and the `Origin`, then asks the room for a socket. Resolves with the 101
|
|
11
|
+
* response to return from the route.
|
|
12
|
+
*
|
|
13
|
+
* - Not a `GET` WebSocket upgrade: `ValidationError` (400).
|
|
14
|
+
* - `Origin` missing or not exactly in `allowedOrigins`: `ForbiddenError` (403). Browsers send
|
|
15
|
+
* the cookie on a cross-site upgrade, so this stops cross-site WebSocket hijacking.
|
|
16
|
+
* - The room is full, the identity has too many connections, or `disconnect` revoked it less
|
|
17
|
+
* than 60 seconds ago: `RateLimitedError` (429).
|
|
18
|
+
*
|
|
19
|
+
* Authorize the room in the route before calling this: the room's `onConnect` is not a gate.
|
|
20
|
+
* Never forward the client request to the room stub yourself; only this function and
|
|
21
|
+
* `realtime()` may call it.
|
|
22
|
+
*
|
|
23
|
+
* Invalid arguments (room, identity, channels, origins, binding) are programming errors and
|
|
24
|
+
* throw a `TypeError` before anything else.
|
|
25
|
+
*/
|
|
26
|
+
export declare function connectToRoom(namespace: DurableObjectNamespace, room: string, request: Request, options: ConnectOptions): Promise<Response>;
|
|
27
|
+
//# sourceMappingURL=connect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAKA,OAAO,EAML,KAAK,YAAY,EAGlB,MAAM,eAAe,CAAC;AAGvB,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,uFAAuF;IACvF,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,4FAA4F;IAC5F,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5C;AA+BD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,sBAAsB,EACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,QAAQ,CAAC,CA4BnB"}
|
package/dist/connect.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opens a WebSocket on a room, from a route that has already authenticated the caller and
|
|
3
|
+
* authorized the room. Runs in the Worker; the socket is held by the room.
|
|
4
|
+
*/
|
|
5
|
+
import { ForbiddenError, RateLimitedError, ValidationError } from "@cardonjs/core";
|
|
6
|
+
import { asciiJson, assertNamespace, CONNECT_HEADER, INTERNAL_ORIGIN, PATH, roomStub, validIdentity, } from "./protocol.js";
|
|
7
|
+
import { assertValidChannels, assertValidRoom } from "./validation.js";
|
|
8
|
+
/** Hosts where an `http:` origin is acceptable: local development only. */
|
|
9
|
+
function isLocalHost(hostname) {
|
|
10
|
+
return (hostname === "localhost" ||
|
|
11
|
+
hostname.endsWith(".localhost") ||
|
|
12
|
+
hostname === "127.0.0.1" ||
|
|
13
|
+
hostname === "[::1]");
|
|
14
|
+
}
|
|
15
|
+
function validOrigins(value) {
|
|
16
|
+
const message = "connectToRoom: allowedOrigins must be a non-empty array of exact origins (https://host[:port]; http: only for localhost, *.localhost, 127.0.0.1 or [::1]), without wildcards.";
|
|
17
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
18
|
+
throw new TypeError(message);
|
|
19
|
+
for (const origin of value) {
|
|
20
|
+
if (typeof origin !== "string")
|
|
21
|
+
throw new TypeError(message);
|
|
22
|
+
let parsed;
|
|
23
|
+
try {
|
|
24
|
+
parsed = new URL(origin);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
throw new TypeError(message);
|
|
28
|
+
}
|
|
29
|
+
const scheme = parsed.protocol === "https:" || (parsed.protocol === "http:" && isLocalHost(parsed.hostname));
|
|
30
|
+
if (!scheme || parsed.origin !== origin)
|
|
31
|
+
throw new TypeError(message);
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Checks the upgrade and the `Origin`, then asks the room for a socket. Resolves with the 101
|
|
37
|
+
* response to return from the route.
|
|
38
|
+
*
|
|
39
|
+
* - Not a `GET` WebSocket upgrade: `ValidationError` (400).
|
|
40
|
+
* - `Origin` missing or not exactly in `allowedOrigins`: `ForbiddenError` (403). Browsers send
|
|
41
|
+
* the cookie on a cross-site upgrade, so this stops cross-site WebSocket hijacking.
|
|
42
|
+
* - The room is full, the identity has too many connections, or `disconnect` revoked it less
|
|
43
|
+
* than 60 seconds ago: `RateLimitedError` (429).
|
|
44
|
+
*
|
|
45
|
+
* Authorize the room in the route before calling this: the room's `onConnect` is not a gate.
|
|
46
|
+
* Never forward the client request to the room stub yourself; only this function and
|
|
47
|
+
* `realtime()` may call it.
|
|
48
|
+
*
|
|
49
|
+
* Invalid arguments (room, identity, channels, origins, binding) are programming errors and
|
|
50
|
+
* throw a `TypeError` before anything else.
|
|
51
|
+
*/
|
|
52
|
+
export async function connectToRoom(namespace, room, request, options) {
|
|
53
|
+
assertNamespace(namespace, "connectToRoom");
|
|
54
|
+
assertValidRoom(room);
|
|
55
|
+
if (typeof options !== "object" || options === null) {
|
|
56
|
+
throw new TypeError("connectToRoom: options must be an object.");
|
|
57
|
+
}
|
|
58
|
+
const identity = validIdentity(options.identity);
|
|
59
|
+
assertValidChannels(options.channels);
|
|
60
|
+
const channels = [...options.channels];
|
|
61
|
+
const allowedOrigins = validOrigins(options.allowedOrigins);
|
|
62
|
+
if (request.method !== "GET" || request.headers.get("upgrade")?.toLowerCase() !== "websocket") {
|
|
63
|
+
throw new ValidationError("A WebSocket upgrade is required.");
|
|
64
|
+
}
|
|
65
|
+
const origin = request.headers.get("origin");
|
|
66
|
+
if (origin === null || !allowedOrigins.includes(origin))
|
|
67
|
+
throw new ForbiddenError();
|
|
68
|
+
// A new request: no client header (cookies, authorization) reaches the room.
|
|
69
|
+
const response = await roomStub(namespace, room).fetch(`${INTERNAL_ORIGIN}${PATH.connect}`, {
|
|
70
|
+
headers: {
|
|
71
|
+
upgrade: "websocket",
|
|
72
|
+
// Cannot throw: ids are well-formed and everything outside printable ASCII is escaped.
|
|
73
|
+
[CONNECT_HEADER]: asciiJson({ room, identity, channels }),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (response.status === 101 && response.webSocket)
|
|
77
|
+
return response;
|
|
78
|
+
if (response.status === 429)
|
|
79
|
+
throw new RateLimitedError();
|
|
80
|
+
throw new Error(`connectToRoom: the room refused the connection (status ${response.status}).`);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EACL,SAAS,EACT,eAAe,EACf,cAAc,EACd,eAAe,EACf,IAAI,EAEJ,QAAQ,EACR,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAUvE,2EAA2E;AAC3E,SAAS,WAAW,CAAC,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,IAAI,gBAAgB,EAAE,CAAC;IAC1D,MAAM,IAAI,KAAK,CAAC,0DAA0D,QAAQ,CAAC,MAAM,IAAI,CAAC,CAAC;AACjG,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { type ConnectOptions, connectToRoom } from "./connect.js";
|
|
2
|
+
export type { Presence, PresenceConnection, PresenceOptions } from "./presence.js";
|
|
3
|
+
export type { RoomIdentity } from "./protocol.js";
|
|
4
|
+
export { type RealtimePublisher, realtime } from "./publisher.js";
|
|
5
|
+
export { defineRoom, type RoomClass, type RoomHookContext, type RoomOptions, } from "./room.js";
|
|
6
|
+
export { assertValidChannel, assertValidChannels, assertValidRoom, type JsonValue, type RealtimeEvent, validEvent, } from "./validation.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClE,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACnF,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,KAAK,iBAAiB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EACL,UAAU,EACV,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,WAAW,GACjB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,UAAU,GACX,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { connectToRoom } from "./connect.js";
|
|
2
|
+
export { realtime } from "./publisher.js";
|
|
3
|
+
export { defineRoom, } from "./room.js";
|
|
4
|
+
export { assertValidChannel, assertValidChannels, assertValidRoom, validEvent, } from "./validation.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlE,OAAO,EAA0B,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EACL,UAAU,GAIX,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EAGf,UAAU,GACX,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presence: who is connected to a room, since when, and when the room last answered their
|
|
3
|
+
* `"ping"`. The query and the selection (filters, order, limit) are shared by the room, the
|
|
4
|
+
* publisher and the fake, so the three agree. Every failure is a `TypeError` whose message never
|
|
5
|
+
* includes the value (identity ids are personal data).
|
|
6
|
+
*/
|
|
7
|
+
import { type RoomIdentity } from "./protocol.js";
|
|
8
|
+
export interface PresenceOptions {
|
|
9
|
+
/** Only this identity's connections. */
|
|
10
|
+
readonly identity?: RoomIdentity;
|
|
11
|
+
/** Only connections on this channel. */
|
|
12
|
+
readonly channel?: string;
|
|
13
|
+
/** Only connections seen (connected or answered a `"ping"`) in the last N seconds, 1 to 86 400. */
|
|
14
|
+
readonly activeWithinSeconds?: number;
|
|
15
|
+
/** At most this many connections in the result. Default 100, 1 to 1000. */
|
|
16
|
+
readonly limit?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface PresenceConnection {
|
|
19
|
+
/** Only `id` and `kind`. */
|
|
20
|
+
readonly identity: RoomIdentity;
|
|
21
|
+
readonly channels: readonly string[];
|
|
22
|
+
readonly connectedAt: Date;
|
|
23
|
+
/** The last `"ping"` the room answered, or `connectedAt` when there was none yet. */
|
|
24
|
+
readonly lastSeenAt: Date;
|
|
25
|
+
}
|
|
26
|
+
export interface Presence {
|
|
27
|
+
/** Open connections, oldest first, at most `limit`. */
|
|
28
|
+
readonly connections: readonly PresenceConnection[];
|
|
29
|
+
/** How many connections matched before `limit` was applied. */
|
|
30
|
+
readonly total: number;
|
|
31
|
+
}
|
|
32
|
+
/** A validated query: a frozen copy with `limit` filled in. */
|
|
33
|
+
export interface PresenceQuery {
|
|
34
|
+
readonly identity?: RoomIdentity;
|
|
35
|
+
readonly channel?: string;
|
|
36
|
+
readonly activeWithinSeconds?: number;
|
|
37
|
+
readonly limit: number;
|
|
38
|
+
}
|
|
39
|
+
/** One connection as the room (or the fake) sees it; times are epoch milliseconds. */
|
|
40
|
+
export interface PresenceRecord {
|
|
41
|
+
readonly identity: RoomIdentity;
|
|
42
|
+
readonly channels: readonly string[];
|
|
43
|
+
readonly connectedAt: number;
|
|
44
|
+
readonly lastSeenAt: number;
|
|
45
|
+
}
|
|
46
|
+
export declare const DEFAULT_PRESENCE_LIMIT = 100;
|
|
47
|
+
export declare const MAX_PRESENCE_LIMIT = 1000;
|
|
48
|
+
export declare const MAX_ACTIVE_WITHIN_SECONDS = 86400;
|
|
49
|
+
/** Validates presence options (`undefined` means none) and returns a frozen query. */
|
|
50
|
+
export declare function validPresenceQuery(options: unknown): PresenceQuery;
|
|
51
|
+
/** True when `value` is a usable epoch-milliseconds time. */
|
|
52
|
+
export declare function isTime(value: unknown): value is number;
|
|
53
|
+
/**
|
|
54
|
+
* Applies the query to the connections: filters, oldest first (a stable sort, so ties keep the
|
|
55
|
+
* input order), then `limit`. `total` counts the matches before `limit`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function selectPresence(records: readonly PresenceRecord[], query: PresenceQuery, now: number): {
|
|
58
|
+
records: PresenceRecord[];
|
|
59
|
+
total: number;
|
|
60
|
+
};
|
|
61
|
+
/** The public, frozen form of a record. */
|
|
62
|
+
export declare function presenceConnection(record: PresenceRecord): PresenceConnection;
|
|
63
|
+
/**
|
|
64
|
+
* Parses one entry of the room's answer. Throws a `TypeError` (without the value) when it is not
|
|
65
|
+
* well-formed.
|
|
66
|
+
*/
|
|
67
|
+
export declare function presenceRecord(value: unknown): PresenceRecord;
|
|
68
|
+
//# sourceMappingURL=presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../src/presence.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,eAAe,CAAC;AAGjE,MAAM,WAAW,eAAe;IAC9B,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC;IACjC,wCAAwC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,mGAAmG;IACnG,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IACtC,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,4BAA4B;IAC5B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;IAC3B,qFAAqF;IACrF,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,QAAQ;IACvB,uDAAuD;IACvD,QAAQ,CAAC,WAAW,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACpD,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,+DAA+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,sFAAsF;AACtF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,eAAO,MAAM,kBAAkB,OAAO,CAAC;AACvC,eAAO,MAAM,yBAAyB,QAAS,CAAC;AAShD,sFAAsF;AACtF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,CA+BlE;AAED,6DAA6D;AAC7D,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEtD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,SAAS,cAAc,EAAE,EAClC,KAAK,EAAE,aAAa,EACpB,GAAG,EAAE,MAAM,GACV;IAAE,OAAO,EAAE,cAAc,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAgB9C;AAED,2CAA2C;AAC3C,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,kBAAkB,CAO7E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAW7D"}
|
package/dist/presence.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presence: who is connected to a room, since when, and when the room last answered their
|
|
3
|
+
* `"ping"`. The query and the selection (filters, order, limit) are shared by the room, the
|
|
4
|
+
* publisher and the fake, so the three agree. Every failure is a `TypeError` whose message never
|
|
5
|
+
* includes the value (identity ids are personal data).
|
|
6
|
+
*/
|
|
7
|
+
import { validIdentity } from "./protocol.js";
|
|
8
|
+
import { assertValidChannel, assertValidChannels } from "./validation.js";
|
|
9
|
+
export const DEFAULT_PRESENCE_LIMIT = 100;
|
|
10
|
+
export const MAX_PRESENCE_LIMIT = 1000;
|
|
11
|
+
export const MAX_ACTIVE_WITHIN_SECONDS = 86_400;
|
|
12
|
+
function integerIn(name, value, min, max) {
|
|
13
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) {
|
|
14
|
+
throw new TypeError(`realtime: presence ${name} must be an integer from ${min} to ${max}.`);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
/** Validates presence options (`undefined` means none) and returns a frozen query. */
|
|
19
|
+
export function validPresenceQuery(options) {
|
|
20
|
+
if (options === undefined)
|
|
21
|
+
return Object.freeze({ limit: DEFAULT_PRESENCE_LIMIT });
|
|
22
|
+
if (typeof options !== "object" || options === null || Array.isArray(options)) {
|
|
23
|
+
throw new TypeError("realtime: presence options must be an object.");
|
|
24
|
+
}
|
|
25
|
+
const { identity, channel, activeWithinSeconds, limit } = options;
|
|
26
|
+
const query = {
|
|
27
|
+
limit: limit === undefined
|
|
28
|
+
? DEFAULT_PRESENCE_LIMIT
|
|
29
|
+
: integerIn("limit", limit, 1, MAX_PRESENCE_LIMIT),
|
|
30
|
+
};
|
|
31
|
+
if (identity !== undefined)
|
|
32
|
+
query.identity = validIdentity(identity);
|
|
33
|
+
if (channel !== undefined) {
|
|
34
|
+
assertValidChannel(channel);
|
|
35
|
+
query.channel = channel;
|
|
36
|
+
}
|
|
37
|
+
if (activeWithinSeconds !== undefined) {
|
|
38
|
+
query.activeWithinSeconds = integerIn("activeWithinSeconds", activeWithinSeconds, 1, MAX_ACTIVE_WITHIN_SECONDS);
|
|
39
|
+
}
|
|
40
|
+
return Object.freeze(query);
|
|
41
|
+
}
|
|
42
|
+
/** True when `value` is a usable epoch-milliseconds time. */
|
|
43
|
+
export function isTime(value) {
|
|
44
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Applies the query to the connections: filters, oldest first (a stable sort, so ties keep the
|
|
48
|
+
* input order), then `limit`. `total` counts the matches before `limit`.
|
|
49
|
+
*/
|
|
50
|
+
export function selectPresence(records, query, now) {
|
|
51
|
+
const since = query.activeWithinSeconds === undefined
|
|
52
|
+
? Number.NEGATIVE_INFINITY
|
|
53
|
+
: now - query.activeWithinSeconds * 1000;
|
|
54
|
+
const { identity, channel } = query;
|
|
55
|
+
const matches = records
|
|
56
|
+
.filter((record) => (identity === undefined ||
|
|
57
|
+
(record.identity.id === identity.id && record.identity.kind === identity.kind)) &&
|
|
58
|
+
(channel === undefined || record.channels.includes(channel)) &&
|
|
59
|
+
record.lastSeenAt >= since)
|
|
60
|
+
.sort((a, b) => a.connectedAt - b.connectedAt);
|
|
61
|
+
return { records: matches.slice(0, query.limit), total: matches.length };
|
|
62
|
+
}
|
|
63
|
+
/** The public, frozen form of a record. */
|
|
64
|
+
export function presenceConnection(record) {
|
|
65
|
+
return Object.freeze({
|
|
66
|
+
identity: Object.freeze({ id: record.identity.id, kind: record.identity.kind }),
|
|
67
|
+
channels: Object.freeze([...record.channels]),
|
|
68
|
+
connectedAt: new Date(record.connectedAt),
|
|
69
|
+
lastSeenAt: new Date(record.lastSeenAt),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Parses one entry of the room's answer. Throws a `TypeError` (without the value) when it is not
|
|
74
|
+
* well-formed.
|
|
75
|
+
*/
|
|
76
|
+
export function presenceRecord(value) {
|
|
77
|
+
if (typeof value !== "object" || value === null) {
|
|
78
|
+
throw new TypeError("realtime: a presence entry must be an object.");
|
|
79
|
+
}
|
|
80
|
+
const { identity, channels, connectedAt, lastSeenAt } = value;
|
|
81
|
+
const valid = validIdentity(identity);
|
|
82
|
+
assertValidChannels(channels);
|
|
83
|
+
if (!isTime(connectedAt) || !isTime(lastSeenAt) || lastSeenAt < connectedAt) {
|
|
84
|
+
throw new TypeError("realtime: a presence entry must hold valid times.");
|
|
85
|
+
}
|
|
86
|
+
return { identity: valid, channels: [...channels], connectedAt, lastSeenAt };
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=presence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.js","sourceRoot":"","sources":["../src/presence.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAqB,aAAa,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AA6C1E,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAC1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AACvC,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEhD,SAAS,SAAS,CAAC,IAAY,EAAE,KAAc,EAAE,GAAW,EAAE,GAAW;IACvE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,GAAG,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;QACxF,MAAM,IAAI,SAAS,CAAC,sBAAsB,IAAI,4BAA4B,GAAG,OAAO,GAAG,GAAG,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,kBAAkB,CAAC,OAAgB;IACjD,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,CAAC,CAAC;IACnF,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9E,MAAM,IAAI,SAAS,CAAC,+CAA+C,CAAC,CAAC;IACvE,CAAC;IACD,M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