@hadoku/rooms-protocol 0.45.60 → 0.45.62
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/feed.d.ts +62 -0
- package/dist/feed.d.ts.map +1 -0
- package/dist/feed.js +82 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +2 -2
package/dist/feed.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The room feed wire contract: the server says a room (or the room list)
|
|
3
|
+
* changed, instead of a browser asking on a timer.
|
|
4
|
+
*
|
|
5
|
+
* Modelled on hadoku-cardtable's `apps/server/src/room/feed.ts` /
|
|
6
|
+
* `apps/ui/src/rooms/feed.ts` (platform plan v2, line 371), which cut a lobby
|
|
7
|
+
* that was read every 1.5s per open tab (~7,500 reads in 6h from five rooms)
|
|
8
|
+
* down to "read once, then read again only when told". This file is the part
|
|
9
|
+
* both ends must agree on; the socket plumbing is `@wolffm/rooms-server`'s
|
|
10
|
+
* `book/feed.ts` (server) and `@wolffm/rooms-client` (browser) — neither of
|
|
11
|
+
* which this file knows about, so a third transport (an iframe relaying over
|
|
12
|
+
* `postMessage`, say) could speak the same contract without this package
|
|
13
|
+
* caring how.
|
|
14
|
+
*
|
|
15
|
+
* ## A ping, not the payload
|
|
16
|
+
*
|
|
17
|
+
* `RoomChanged` names WHICH room changed (or that the LIST changed) and
|
|
18
|
+
* nothing else. What actually changed is the caller's to decide how to answer
|
|
19
|
+
* — a generic package has no opinion on what a room looks like once read, and
|
|
20
|
+
* baking a payload in here would mean re-deriving per-caller visibility rules
|
|
21
|
+
* (who sees what) a second time, just for this channel.
|
|
22
|
+
*
|
|
23
|
+
* ## Watching is a set, sent whole
|
|
24
|
+
*
|
|
25
|
+
* One message names everything a socket follows — specific room ids, and
|
|
26
|
+
* whether it follows the list — and REPLACES whatever it sent before. A
|
|
27
|
+
* reconnect sends the set again, so the server keeps no memory of a socket it
|
|
28
|
+
* lost.
|
|
29
|
+
*/
|
|
30
|
+
/** A room id, or the aggregate "the list moved" marker. */
|
|
31
|
+
export declare const ROOM_FEED_CHANNEL: {
|
|
32
|
+
/** client → server, with an ack. Payload: `RoomWatch`. */
|
|
33
|
+
readonly watch: "room-feed:watch";
|
|
34
|
+
/** server → client. Payload: `RoomChanged`. */
|
|
35
|
+
readonly changed: "room-feed:changed";
|
|
36
|
+
};
|
|
37
|
+
/** More than one screen ever follows at once; a ceiling, not a budget. */
|
|
38
|
+
export declare const ROOM_WATCH_MAX = 32;
|
|
39
|
+
/** The longest room id a watch may name. */
|
|
40
|
+
export declare const ROOM_FEED_ID_MAX = 128;
|
|
41
|
+
export interface RoomWatch {
|
|
42
|
+
rooms: string[];
|
|
43
|
+
list: boolean;
|
|
44
|
+
}
|
|
45
|
+
export type RoomChanged = {
|
|
46
|
+
room: string;
|
|
47
|
+
} | {
|
|
48
|
+
list: true;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Parse a `watch` off the wire: null for anything that is not exactly one.
|
|
52
|
+
* Hand-rolled rather than a schema library, to keep this package at zero
|
|
53
|
+
* dependencies (`seats.ts`, `session.ts` and `resync.ts` all do the same).
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseRoomWatch(raw: unknown): RoomWatch | null;
|
|
56
|
+
/** Parse a `changed` ping off the wire: null for anything that is not exactly one. */
|
|
57
|
+
export declare function parseRoomChanged(raw: unknown): RoomChanged | null;
|
|
58
|
+
/** True when `changed` is the aggregate list marker rather than a specific room. */
|
|
59
|
+
export declare function changedIsList(changed: RoomChanged): changed is {
|
|
60
|
+
list: true;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=feed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../src/feed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,2DAA2D;AAC3D,eAAO,MAAM,iBAAiB;IAC5B,0DAA0D;;IAE1D,+CAA+C;;CAEvC,CAAC;AAEX,0EAA0E;AAC1E,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC;AAE5D;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAQ7D;AAED,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAcjE;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,IAAI;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CAE7E"}
|
package/dist/feed.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The room feed wire contract: the server says a room (or the room list)
|
|
3
|
+
* changed, instead of a browser asking on a timer.
|
|
4
|
+
*
|
|
5
|
+
* Modelled on hadoku-cardtable's `apps/server/src/room/feed.ts` /
|
|
6
|
+
* `apps/ui/src/rooms/feed.ts` (platform plan v2, line 371), which cut a lobby
|
|
7
|
+
* that was read every 1.5s per open tab (~7,500 reads in 6h from five rooms)
|
|
8
|
+
* down to "read once, then read again only when told". This file is the part
|
|
9
|
+
* both ends must agree on; the socket plumbing is `@wolffm/rooms-server`'s
|
|
10
|
+
* `book/feed.ts` (server) and `@wolffm/rooms-client` (browser) — neither of
|
|
11
|
+
* which this file knows about, so a third transport (an iframe relaying over
|
|
12
|
+
* `postMessage`, say) could speak the same contract without this package
|
|
13
|
+
* caring how.
|
|
14
|
+
*
|
|
15
|
+
* ## A ping, not the payload
|
|
16
|
+
*
|
|
17
|
+
* `RoomChanged` names WHICH room changed (or that the LIST changed) and
|
|
18
|
+
* nothing else. What actually changed is the caller's to decide how to answer
|
|
19
|
+
* — a generic package has no opinion on what a room looks like once read, and
|
|
20
|
+
* baking a payload in here would mean re-deriving per-caller visibility rules
|
|
21
|
+
* (who sees what) a second time, just for this channel.
|
|
22
|
+
*
|
|
23
|
+
* ## Watching is a set, sent whole
|
|
24
|
+
*
|
|
25
|
+
* One message names everything a socket follows — specific room ids, and
|
|
26
|
+
* whether it follows the list — and REPLACES whatever it sent before. A
|
|
27
|
+
* reconnect sends the set again, so the server keeps no memory of a socket it
|
|
28
|
+
* lost.
|
|
29
|
+
*/
|
|
30
|
+
/** A room id, or the aggregate "the list moved" marker. */
|
|
31
|
+
export const ROOM_FEED_CHANNEL = {
|
|
32
|
+
/** client → server, with an ack. Payload: `RoomWatch`. */
|
|
33
|
+
watch: 'room-feed:watch',
|
|
34
|
+
/** server → client. Payload: `RoomChanged`. */
|
|
35
|
+
changed: 'room-feed:changed',
|
|
36
|
+
};
|
|
37
|
+
/** More than one screen ever follows at once; a ceiling, not a budget. */
|
|
38
|
+
export const ROOM_WATCH_MAX = 32;
|
|
39
|
+
/** The longest room id a watch may name. */
|
|
40
|
+
export const ROOM_FEED_ID_MAX = 128;
|
|
41
|
+
/**
|
|
42
|
+
* Parse a `watch` off the wire: null for anything that is not exactly one.
|
|
43
|
+
* Hand-rolled rather than a schema library, to keep this package at zero
|
|
44
|
+
* dependencies (`seats.ts`, `session.ts` and `resync.ts` all do the same).
|
|
45
|
+
*/
|
|
46
|
+
export function parseRoomWatch(raw) {
|
|
47
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
|
|
48
|
+
return null;
|
|
49
|
+
const { rooms, list, ...rest } = raw;
|
|
50
|
+
if (Object.keys(rest).length > 0)
|
|
51
|
+
return null;
|
|
52
|
+
if (!Array.isArray(rooms) || rooms.length > ROOM_WATCH_MAX)
|
|
53
|
+
return null;
|
|
54
|
+
if (!rooms.every((r) => typeof r === 'string' && r.length > 0 && r.length <= ROOM_FEED_ID_MAX))
|
|
55
|
+
return null;
|
|
56
|
+
if (typeof list !== 'boolean')
|
|
57
|
+
return null;
|
|
58
|
+
return { rooms: [...new Set(rooms)], list };
|
|
59
|
+
}
|
|
60
|
+
/** Parse a `changed` ping off the wire: null for anything that is not exactly one. */
|
|
61
|
+
export function parseRoomChanged(raw) {
|
|
62
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
|
|
63
|
+
return null;
|
|
64
|
+
const rec = raw;
|
|
65
|
+
if ('room' in rec) {
|
|
66
|
+
const { room, ...rest } = rec;
|
|
67
|
+
if (Object.keys(rest).length > 0)
|
|
68
|
+
return null;
|
|
69
|
+
return typeof room === 'string' && room.length > 0 ? { room } : null;
|
|
70
|
+
}
|
|
71
|
+
if ('list' in rec) {
|
|
72
|
+
const { list, ...rest } = rec;
|
|
73
|
+
if (Object.keys(rest).length > 0)
|
|
74
|
+
return null;
|
|
75
|
+
return list === true ? { list: true } : null;
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
/** True when `changed` is the aggregate list marker rather than a specific room. */
|
|
80
|
+
export function changedIsList(changed) {
|
|
81
|
+
return 'list' in changed;
|
|
82
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/rooms-protocol",
|
|
3
|
-
"version": "0.45.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.45.62",
|
|
4
|
+
"gitHead": "2e965af2d4374dfa5345cfeca2f6e57932034ffb",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Room, identity and seating protocol — the wire contract shared by rooms-server and rooms-client.",
|