@celljs/ta-relay 4.22.0 → 4.24.0
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/esm/common/index.d.ts +2 -0
- package/esm/common/index.js +2 -0
- package/esm/common/relay-blobs.d.ts +36 -2
- package/esm/common/relay-blobs.js +33 -5
- package/esm/common/relay-chat-store.d.ts +69 -0
- package/esm/common/relay-chat-store.js +50 -0
- package/esm/common/relay-hub-charter.d.ts +2 -0
- package/esm/common/relay-hub-charter.js +3 -0
- package/esm/common/relay-hub-log.d.ts +65 -0
- package/esm/common/relay-hub-log.js +147 -0
- package/esm/common/relay-hub.d.ts +3 -0
- package/esm/common/relay-hub.js +18 -0
- package/esm/common/relay-hubs-admins.d.ts +1 -0
- package/esm/common/relay-hubs-admins.js +10 -6
- package/esm/common/relay-hubs-chats.d.ts +73 -0
- package/esm/common/relay-hubs-chats.js +367 -0
- package/esm/common/relay-hubs-connection.d.ts +3 -1
- package/esm/common/relay-hubs-connection.js +7 -0
- package/esm/common/relay-hubs-protocol.d.ts +16 -0
- package/esm/common/relay-hubs.d.ts +2 -2
- package/esm/common/relay-hubs.js +14 -11
- package/esm/common/relay-info.d.ts +23 -1
- package/esm/common/relay-info.js +25 -2
- package/esm/common/relay-protocol.d.ts +60 -1
- package/esm/common/relay-protocol.js +15 -0
- package/esm/common/relay-room-chat.d.ts +126 -4
- package/esm/common/relay-room-chat.js +230 -6
- package/esm/guest/guest-i18n.d.ts +2 -0
- package/esm/guest/guest-i18n.js +8 -0
- package/esm/guest/guest.js +8 -5
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/relay-chat-files.d.ts +52 -0
- package/esm/node/relay-chat-files.js +224 -0
- package/esm/node/relay-hub-files.d.ts +11 -1
- package/esm/node/relay-hub-files.js +8 -1
- package/esm/node/relay-server.d.ts +9 -1
- package/esm/node/relay-server.js +29 -18
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/common/relay-blobs.d.ts +36 -2
- package/lib/common/relay-blobs.js +34 -6
- package/lib/common/relay-chat-store.d.ts +70 -0
- package/lib/common/relay-chat-store.js +54 -0
- package/lib/common/relay-hub-charter.d.ts +2 -0
- package/lib/common/relay-hub-charter.js +3 -0
- package/lib/common/relay-hub-log.d.ts +66 -0
- package/lib/common/relay-hub-log.js +151 -0
- package/lib/common/relay-hub.d.ts +3 -0
- package/lib/common/relay-hub.js +18 -0
- package/lib/common/relay-hubs-admins.d.ts +1 -0
- package/lib/common/relay-hubs-admins.js +9 -5
- package/lib/common/relay-hubs-chats.d.ts +74 -0
- package/lib/common/relay-hubs-chats.js +371 -0
- package/lib/common/relay-hubs-connection.d.ts +3 -1
- package/lib/common/relay-hubs-connection.js +7 -0
- package/lib/common/relay-hubs-protocol.d.ts +16 -0
- package/lib/common/relay-hubs.d.ts +2 -2
- package/lib/common/relay-hubs.js +14 -11
- package/lib/common/relay-info.d.ts +23 -1
- package/lib/common/relay-info.js +26 -3
- package/lib/common/relay-protocol.d.ts +60 -1
- package/lib/common/relay-protocol.js +16 -1
- package/lib/common/relay-room-chat.d.ts +126 -4
- package/lib/common/relay-room-chat.js +231 -7
- package/lib/guest/guest-i18n.d.ts +2 -0
- package/lib/guest/guest-i18n.js +8 -0
- package/lib/guest/guest.js +7 -4
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/relay-chat-files.d.ts +53 -0
- package/lib/node/relay-chat-files.js +228 -0
- package/lib/node/relay-hub-files.d.ts +11 -1
- package/lib/node/relay-hub-files.js +8 -1
- package/lib/node/relay-server.d.ts +9 -1
- package/lib/node/relay-server.js +27 -16
- package/package.json +3 -3
- package/viewer/join.html +4 -4
- package/viewer/page.html +10 -10
- package/viewer/room.html +15 -15
package/lib/common/relay-info.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RelayInfoUtil = exports.RELAY_LEGACY_INFO = exports.RELAY_INFO_PATH = void 0;
|
|
3
|
+
exports.RelayInfoUtil = exports.RELAY_LEGACY_INFO = exports.RELAY_MEDIA_DEFAULT_DAYS = exports.RELAY_MEDIA_MAX = exports.RELAY_INFO_PATH = void 0;
|
|
4
4
|
const relay_protocol_1 = require("./relay-protocol");
|
|
5
5
|
/** What a relay says of itself (docs/design/ta-relays.md 3.1): GET RELAY_INFO_PATH. */
|
|
6
6
|
exports.RELAY_INFO_PATH = '/v1/info';
|
|
7
|
+
/** The most an operator may let a relay keep of a picture: as long and as large as a copy of content. */
|
|
8
|
+
exports.RELAY_MEDIA_MAX = { days: 30, bytes: 2 * 1024 * 1024 };
|
|
9
|
+
/**
|
|
10
|
+
* Days a relay keeps a picture of a chat unless its operator says otherwise: short, so that what it keeps stays small
|
|
11
|
+
* however many use it, long enough for the others to open a chat the sender left while away.
|
|
12
|
+
*/
|
|
13
|
+
exports.RELAY_MEDIA_DEFAULT_DAYS = 1;
|
|
7
14
|
/** A relay that answers no RELAY_INFO_PATH, made before it: all it can do, with the limits of then. */
|
|
8
15
|
exports.RELAY_LEGACY_INFO = {
|
|
9
16
|
v: 1,
|
|
@@ -21,10 +28,24 @@ exports.RELAY_LEGACY_INFO = {
|
|
|
21
28
|
};
|
|
22
29
|
var RelayInfoUtil;
|
|
23
30
|
(function (RelayInfoUtil) {
|
|
24
|
-
function of(persistent) {
|
|
25
|
-
return { ...exports.RELAY_LEGACY_INFO, persistent };
|
|
31
|
+
function of(persistent, media) {
|
|
32
|
+
return { ...exports.RELAY_LEGACY_INFO, persistent, ...(media ? { media } : {}) };
|
|
26
33
|
}
|
|
27
34
|
RelayInfoUtil.of = of;
|
|
35
|
+
/**
|
|
36
|
+
* What the operator of a relay lets it keep of the pictures of chats, from its settings (`TA_MEDIA_DAYS`,
|
|
37
|
+
* `TA_MEDIA_MAX_MB`): RELAY_MEDIA_DEFAULT_DAYS unless set, none with 0, within RELAY_MEDIA_MAX.
|
|
38
|
+
*/
|
|
39
|
+
function media(days, megabytes) {
|
|
40
|
+
const set = days !== undefined && days !== null && String(days).trim() !== '';
|
|
41
|
+
const kept = Math.min(Math.floor(set ? Number(days) || 0 : exports.RELAY_MEDIA_DEFAULT_DAYS), exports.RELAY_MEDIA_MAX.days);
|
|
42
|
+
if (!(kept > 0)) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const bytes = Number(megabytes) > 0 ? Math.floor(Number(megabytes) * 1024 * 1024) : exports.RELAY_MEDIA_MAX.bytes;
|
|
46
|
+
return { days: kept, bytes: Math.min(bytes, exports.RELAY_MEDIA_MAX.bytes) };
|
|
47
|
+
}
|
|
48
|
+
RelayInfoUtil.media = media;
|
|
28
49
|
/** The answer of RELAY_INFO_PATH: JSON, readable by any page (it says nothing secret). */
|
|
29
50
|
function response(info) {
|
|
30
51
|
return new Response(JSON.stringify(info), {
|
|
@@ -85,11 +106,13 @@ var RelayInfoUtil;
|
|
|
85
106
|
limits[key] = given;
|
|
86
107
|
}
|
|
87
108
|
}
|
|
109
|
+
const kept = info.media && media(info.media.days, (Number(info.media.bytes) || 0) / (1024 * 1024));
|
|
88
110
|
return {
|
|
89
111
|
v: 1,
|
|
90
112
|
capabilities: info.capabilities.filter((capability) => known.includes(capability)),
|
|
91
113
|
limits,
|
|
92
114
|
persistent: info.persistent !== false,
|
|
115
|
+
...(kept ? { media: kept } : {}),
|
|
93
116
|
};
|
|
94
117
|
}
|
|
95
118
|
RelayInfoUtil.parse = parse;
|
|
@@ -39,6 +39,11 @@ export declare const RELAY_VIEWER_HEADERS: {
|
|
|
39
39
|
};
|
|
40
40
|
/** The copies of content kept on the relay, sealed, for when the computer that shared it is off (RelayBlobs). */
|
|
41
41
|
export declare const RELAY_BLOB_PATH = "/v1/blob/";
|
|
42
|
+
/**
|
|
43
|
+
* Sealed copies of the pictures of chats (docs/design/ta-chat-history.md 7), only on a relay whose operator lets it
|
|
44
|
+
* (RelayInfo.media): none by default, what it keeps costing more the more people use it.
|
|
45
|
+
*/
|
|
46
|
+
export declare const RELAY_MEDIA_PATH = "/v1/media/";
|
|
42
47
|
/** The page a pairing link opens in a browser: the link is for the app, and the key in it stays in the fragment. */
|
|
43
48
|
export declare const RELAY_PAIR_PAGE = "<!doctype html><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width\"><title>Ta</title>\n<body style=\"font:16px system-ui;max-width:32em;margin:3em auto;padding:0 1em\">\n<h1>Ta</h1><p>Open this link in the Ta app, or paste it there, to reach your Ta from this device.</p>\n<p>\u6253\u5F00 Ta \u5E94\u7528\uFF0C\u7C98\u8D34\u8FD9\u4E2A\u94FE\u63A5\uFF0C\u5C31\u80FD\u4ECE\u8FD9\u53F0\u8BBE\u5907\u8FDE\u5230\u4F60\u7684 Ta\u3002</p><p><a id=\"open\" style=\"display:inline-block;padding:10px 18px;border-radius:20px;background:#111;color:#fff;text-decoration:none;font-weight:600\">Open in Ta \u00B7 \u5728 Ta \u4E2D\u6253\u5F00</a></p>\n<script>document.getElementById('open').href='ta://open?link='+encodeURIComponent(location.href)</script></body>";
|
|
44
49
|
/** The page a link of an extension opens in a browser. */
|
|
@@ -200,6 +205,26 @@ export declare const RELAY_HUB_ASK_DAYS = 7;
|
|
|
200
205
|
export declare const RELAY_HUB_IDLE_DAYS = 90;
|
|
201
206
|
/** Messages of a connection in a second. */
|
|
202
207
|
export declare const RELAY_HUB_RATE = 40;
|
|
208
|
+
/**
|
|
209
|
+
* One message of the log of a room (docs/design/ta-chat-history.md 5): its number in the room, the member who posted it,
|
|
210
|
+
* sealed and signed as a message is, and when the relay took it. What is said in a room goes here, not in the state.
|
|
211
|
+
*/
|
|
212
|
+
export interface RelayHubLogItem {
|
|
213
|
+
s: number;
|
|
214
|
+
m: string;
|
|
215
|
+
d: string;
|
|
216
|
+
at: number;
|
|
217
|
+
}
|
|
218
|
+
/** The log of a room keeps so many messages, so many characters at most: past them the oldest go, read or not. */
|
|
219
|
+
export declare const RELAY_HUB_LOG_MAX = 5000;
|
|
220
|
+
export declare const RELAY_HUB_LOG_CHARS: number;
|
|
221
|
+
/** Days a message is kept once every member has it, and at most. */
|
|
222
|
+
export declare const RELAY_HUB_LOG_KEEP_DAYS = 7;
|
|
223
|
+
export declare const RELAY_HUB_LOG_MAX_DAYS = 30;
|
|
224
|
+
/** Messages of the log in one answer to `sync`. */
|
|
225
|
+
export declare const RELAY_HUB_SYNC_PAGE = 200;
|
|
226
|
+
/** Messages from before they joined a newcomer may read at most, as the charter of the room says (history, 0 by default). */
|
|
227
|
+
export declare const RELAY_HUB_HISTORY_MAX = 500;
|
|
203
228
|
/**
|
|
204
229
|
* The sealed list of the members of a room, signed by its owner (or an admin); `v` grows with each change. After a
|
|
205
230
|
* member was taken out or left, `k` holds the keys of the room's epochs sealed for each member left
|
|
@@ -259,6 +284,24 @@ export type RelayHubRequest = {
|
|
|
259
284
|
d: string;
|
|
260
285
|
v?: number;
|
|
261
286
|
own?: true;
|
|
287
|
+
}
|
|
288
|
+
/** Adds to the log (`mid` the id of the line: the same again is the same message), answered by `done` with its number in `v`. */
|
|
289
|
+
| {
|
|
290
|
+
t: 'post';
|
|
291
|
+
id: number;
|
|
292
|
+
mid: string;
|
|
293
|
+
d: string;
|
|
294
|
+
}
|
|
295
|
+
/** The log after the number `after`, a page of it (RELAY_HUB_SYNC_PAGE at most), answered by `log`. */
|
|
296
|
+
| {
|
|
297
|
+
t: 'sync';
|
|
298
|
+
after: number;
|
|
299
|
+
limit?: number;
|
|
300
|
+
}
|
|
301
|
+
/** This member has the log up to `seq`: the relay may let go of what all have, once old enough. */
|
|
302
|
+
| {
|
|
303
|
+
t: 'ack';
|
|
304
|
+
seq: number;
|
|
262
305
|
} | {
|
|
263
306
|
t: 'invite';
|
|
264
307
|
hash: string;
|
|
@@ -266,11 +309,14 @@ export type RelayHubRequest = {
|
|
|
266
309
|
} | {
|
|
267
310
|
t: 'admins';
|
|
268
311
|
admins: string[];
|
|
269
|
-
}
|
|
312
|
+
}
|
|
313
|
+
/** `history`: messages from before they joined the newcomer may read (RELAY_HUB_HISTORY_MAX at most), 0 by default. */
|
|
314
|
+
| {
|
|
270
315
|
t: 'admit';
|
|
271
316
|
ask: string;
|
|
272
317
|
answer: string;
|
|
273
318
|
roster: RelayHubRoster;
|
|
319
|
+
history?: number;
|
|
274
320
|
} | {
|
|
275
321
|
t: 'refuse';
|
|
276
322
|
ask: string;
|
|
@@ -307,6 +353,19 @@ export type RelayHubEvent = {
|
|
|
307
353
|
t: 'msg';
|
|
308
354
|
from: string;
|
|
309
355
|
d: string;
|
|
356
|
+
}
|
|
357
|
+
/** A page of the log: `first` and `last` the numbers it holds now, `more` when there is more after the page. */
|
|
358
|
+
| {
|
|
359
|
+
t: 'log';
|
|
360
|
+
items: RelayHubLogItem[];
|
|
361
|
+
first: number;
|
|
362
|
+
last: number;
|
|
363
|
+
more: boolean;
|
|
364
|
+
}
|
|
365
|
+
/** Another member posted. */
|
|
366
|
+
| {
|
|
367
|
+
t: 'post';
|
|
368
|
+
item: RelayHubLogItem;
|
|
310
369
|
} | {
|
|
311
370
|
t: 'state';
|
|
312
371
|
entry: RelayHubEntry;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RELAY_HUB_RATE = exports.RELAY_HUB_IDLE_DAYS = exports.RELAY_HUB_ASK_DAYS = exports.RELAY_PICTURE_MAX_CHARS = exports.RELAY_PICTURE_KEY = exports.RELAY_HUB_MAX_ASKS = exports.RELAY_HUB_MAX_STATE = exports.RELAY_HUB_MAX_KEYS = exports.RELAY_HUB_MAX_VALUE = exports.RELAY_FRIENDS_MAX = exports.RELAY_INVITE_MAX_DAYS = exports.RELAY_ROOM_CAPACITY_MAX = exports.RELAY_ROOM_MAX_MEMBERS = exports.RELAY_HUB_MAX_MEMBERS = exports.RELAY_ROOM_PATH = exports.RELAY_HUB_PATH = exports.RELAY_PROOF = exports.RELAY_STALE_MS = exports.RELAY_PING_MS = exports.RELAY_PONG = exports.RELAY_PING = exports.RelayCloseCode = exports.RELAY_ID = exports.RELAY_BLOB_MAX_DAYS = exports.RELAY_CONTENT_MAX_BYTES = exports.RELAY_SHARE_DAYS = exports.RELAY_SHARE_CHUNK_BYTES = exports.RELAY_SHARE_MAX_BYTES = exports.RELAY_SHARE_PAGE = exports.RELAY_PAIR_PAGE = exports.RELAY_BLOB_PATH = exports.RELAY_VIEWER_HEADERS = exports.RELAY_FRAME_HEADER_CSP = exports.RELAY_FRAME_CSP = exports.RELAY_FRAME_PATH = exports.RELAY_CONTENT_PATH = exports.RELAY_SHARE_PATH = exports.RELAY_PAIR_PATH = exports.RELAY_CONNECT_PATH = exports.RELAY_HOST_PATH = exports.RELAY_DEFAULT_URL = void 0;
|
|
3
|
+
exports.RELAY_HUB_HISTORY_MAX = exports.RELAY_HUB_SYNC_PAGE = exports.RELAY_HUB_LOG_MAX_DAYS = exports.RELAY_HUB_LOG_KEEP_DAYS = exports.RELAY_HUB_LOG_CHARS = exports.RELAY_HUB_LOG_MAX = exports.RELAY_HUB_RATE = exports.RELAY_HUB_IDLE_DAYS = exports.RELAY_HUB_ASK_DAYS = exports.RELAY_PICTURE_MAX_CHARS = exports.RELAY_PICTURE_KEY = exports.RELAY_HUB_MAX_ASKS = exports.RELAY_HUB_MAX_STATE = exports.RELAY_HUB_MAX_KEYS = exports.RELAY_HUB_MAX_VALUE = exports.RELAY_FRIENDS_MAX = exports.RELAY_INVITE_MAX_DAYS = exports.RELAY_ROOM_CAPACITY_MAX = exports.RELAY_ROOM_MAX_MEMBERS = exports.RELAY_HUB_MAX_MEMBERS = exports.RELAY_ROOM_PATH = exports.RELAY_HUB_PATH = exports.RELAY_PROOF = exports.RELAY_STALE_MS = exports.RELAY_PING_MS = exports.RELAY_PONG = exports.RELAY_PING = exports.RelayCloseCode = exports.RELAY_ID = exports.RELAY_BLOB_MAX_DAYS = exports.RELAY_CONTENT_MAX_BYTES = exports.RELAY_SHARE_DAYS = exports.RELAY_SHARE_CHUNK_BYTES = exports.RELAY_SHARE_MAX_BYTES = exports.RELAY_SHARE_PAGE = exports.RELAY_PAIR_PAGE = exports.RELAY_MEDIA_PATH = exports.RELAY_BLOB_PATH = exports.RELAY_VIEWER_HEADERS = exports.RELAY_FRAME_HEADER_CSP = exports.RELAY_FRAME_CSP = exports.RELAY_FRAME_PATH = exports.RELAY_CONTENT_PATH = exports.RELAY_SHARE_PATH = exports.RELAY_PAIR_PATH = exports.RELAY_CONNECT_PATH = exports.RELAY_HOST_PATH = exports.RELAY_DEFAULT_URL = void 0;
|
|
4
4
|
exports.relayDefaultUrl = relayDefaultUrl;
|
|
5
5
|
/** The relay of Ta, on Cloudflare Workers (apps/ta-relay), when the user names none. */
|
|
6
6
|
exports.RELAY_DEFAULT_URL = 'https://relay.cellbang.com';
|
|
@@ -48,6 +48,11 @@ exports.RELAY_VIEWER_HEADERS = {
|
|
|
48
48
|
};
|
|
49
49
|
/** The copies of content kept on the relay, sealed, for when the computer that shared it is off (RelayBlobs). */
|
|
50
50
|
exports.RELAY_BLOB_PATH = '/v1/blob/';
|
|
51
|
+
/**
|
|
52
|
+
* Sealed copies of the pictures of chats (docs/design/ta-chat-history.md 7), only on a relay whose operator lets it
|
|
53
|
+
* (RelayInfo.media): none by default, what it keeps costing more the more people use it.
|
|
54
|
+
*/
|
|
55
|
+
exports.RELAY_MEDIA_PATH = '/v1/media/';
|
|
51
56
|
/** Open in Ta on the plain pages of the relay: the link of the page, its fragment too, to the Ta app (RelayOpenInTa). */
|
|
52
57
|
const OPEN_IN_TA = `<p><a id="open" style="display:inline-block;padding:10px 18px;border-radius:20px;background:#111;color:#fff;text-decoration:none;font-weight:600">Open in Ta · 在 Ta 中打开</a></p>
|
|
53
58
|
<script>document.getElementById('open').href='ta://open?link='+encodeURIComponent(location.href)</script>`;
|
|
@@ -137,4 +142,14 @@ exports.RELAY_HUB_ASK_DAYS = 7;
|
|
|
137
142
|
exports.RELAY_HUB_IDLE_DAYS = 90;
|
|
138
143
|
/** Messages of a connection in a second. */
|
|
139
144
|
exports.RELAY_HUB_RATE = 40;
|
|
145
|
+
/** The log of a room keeps so many messages, so many characters at most: past them the oldest go, read or not. */
|
|
146
|
+
exports.RELAY_HUB_LOG_MAX = 5000;
|
|
147
|
+
exports.RELAY_HUB_LOG_CHARS = 4 * 1024 * 1024;
|
|
148
|
+
/** Days a message is kept once every member has it, and at most. */
|
|
149
|
+
exports.RELAY_HUB_LOG_KEEP_DAYS = 7;
|
|
150
|
+
exports.RELAY_HUB_LOG_MAX_DAYS = 30;
|
|
151
|
+
/** Messages of the log in one answer to `sync`. */
|
|
152
|
+
exports.RELAY_HUB_SYNC_PAGE = 200;
|
|
153
|
+
/** Messages from before they joined a newcomer may read at most, as the charter of the room says (history, 0 by default). */
|
|
154
|
+
exports.RELAY_HUB_HISTORY_MAX = 500;
|
|
140
155
|
//# sourceMappingURL=relay-protocol.js.map
|
|
@@ -4,13 +4,26 @@ export interface RelayRoomChatValue {
|
|
|
4
4
|
version: number;
|
|
5
5
|
by: string;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* What a chat reads and sets: RelayHubs, or TaRoomServer of Ta. With `readChat` and `say`, what is said is the log of
|
|
9
|
+
* the room, kept on this computer (docs/design/ta-chat-history.md); without them (a Ta service of before), the state.
|
|
10
|
+
*/
|
|
8
11
|
export interface RelayRoomChatRooms {
|
|
9
12
|
getState(room: string, prefix?: string): Promise<Record<string, RelayRoomChatValue>>;
|
|
10
13
|
setState(room: string, key: string, value: unknown, version?: number): Promise<{
|
|
11
14
|
ok: boolean;
|
|
12
15
|
version: number;
|
|
13
16
|
}>;
|
|
17
|
+
/** The latest lines kept, before the line `before` (its id) when given, the earliest first: `more` when there are older. */
|
|
18
|
+
readChat?(room: string, options?: {
|
|
19
|
+
before?: string;
|
|
20
|
+
limit?: number;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
lines: RelayChatLine[];
|
|
23
|
+
more: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
/** Says it as this Ta: the line, `pending` till the relay has it. */
|
|
26
|
+
say?(room: string, text: string, extra?: RelayChatLineExtra): Promise<RelayChatLine | undefined>;
|
|
14
27
|
}
|
|
15
28
|
/** One thing said in a room. */
|
|
16
29
|
export interface RelayChatLine {
|
|
@@ -48,16 +61,85 @@ export interface RelayChatLine {
|
|
|
48
61
|
* its own, says how it goes under `tasks:<member>` of the state, and answers with `re` when it ends.
|
|
49
62
|
*/
|
|
50
63
|
task?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Pictures sent with it (docs/design/ta-composer.md 3): what they are, not their bytes, which stay on the computers of
|
|
66
|
+
* the members (the sender's, and each one's that fetched them) and go from one to another through the room, sealed.
|
|
67
|
+
*/
|
|
68
|
+
images?: RelayChatImage[];
|
|
69
|
+
/**
|
|
70
|
+
* Files, a voice message or a video sent with it (docs/design/ta-chat-history.md 7): what they are, not their
|
|
71
|
+
* bytes, which go from member to member through the room and are never kept on the relay.
|
|
72
|
+
*/
|
|
73
|
+
files?: RelayChatFile[];
|
|
74
|
+
/** Its number in the log of the room; none for a line of before the log, or one not sent yet. */
|
|
75
|
+
seq?: number;
|
|
76
|
+
/** Said here, not yet taken by the relay: it goes once it can. */
|
|
77
|
+
pending?: true;
|
|
78
|
+
/** Said here, refused by the relay (too large): it never went. */
|
|
79
|
+
failed?: true;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A picture of a line (RelayChatLine.images): its id among the pictures of the sender, its type, size and the SHA-256 of
|
|
83
|
+
* its bytes, which whoever fetches it checks; a blurred thumbnail of a few hundred bytes to show until it comes.
|
|
84
|
+
*/
|
|
85
|
+
export interface RelayChatImage {
|
|
86
|
+
id: string;
|
|
87
|
+
type: string;
|
|
88
|
+
w: number;
|
|
89
|
+
h: number;
|
|
90
|
+
bytes: number;
|
|
91
|
+
sha: string;
|
|
92
|
+
thumb?: string;
|
|
93
|
+
/**
|
|
94
|
+
* A copy on the relay of the room while it lasts (docs/design/ta-chat-history.md 7), for whoever comes when no
|
|
95
|
+
* member who has it is online: its id there, what reads it and what opens it (AES-256-GCM), till when.
|
|
96
|
+
*/
|
|
97
|
+
blob?: RelayChatBlob;
|
|
98
|
+
}
|
|
99
|
+
/** A sealed copy of a picture on the relay (RelayChatImage.blob): the relay reads neither it nor what opens it. */
|
|
100
|
+
export interface RelayChatBlob {
|
|
101
|
+
id: string;
|
|
102
|
+
/** base64url, 32 bytes: the token that reads it (the relay keeps its SHA-256). */
|
|
103
|
+
read: string;
|
|
104
|
+
/** base64url, 32 bytes: the key it is sealed with. */
|
|
105
|
+
key: string;
|
|
106
|
+
until: number;
|
|
107
|
+
}
|
|
108
|
+
/** What a file of a line is: any file, a voice message (`ms` long), a video (`ms` long, `w` × `h`, a blurred frame). */
|
|
109
|
+
export type RelayChatFileKind = 'file' | 'voice' | 'video';
|
|
110
|
+
/**
|
|
111
|
+
* A file of a line (RelayChatLine.files): its id among the files of the sender, its name, type, size and the SHA-256
|
|
112
|
+
* of its bytes, which whoever fetches it checks.
|
|
113
|
+
*/
|
|
114
|
+
export interface RelayChatFile {
|
|
115
|
+
id: string;
|
|
116
|
+
kind: RelayChatFileKind;
|
|
117
|
+
name: string;
|
|
118
|
+
type: string;
|
|
119
|
+
bytes: number;
|
|
120
|
+
sha: string;
|
|
121
|
+
ms?: number;
|
|
122
|
+
w?: number;
|
|
123
|
+
h?: number;
|
|
124
|
+
thumb?: string;
|
|
51
125
|
}
|
|
126
|
+
/** The bytes of a file of each kind at most: what passes between members in a minute or two. */
|
|
127
|
+
export declare const RELAY_CHAT_FILE_BYTES: Record<RelayChatFileKind, number>;
|
|
128
|
+
/** How long a voice message and a video are at most. */
|
|
129
|
+
export declare const RELAY_CHAT_VOICE_MS = 60000;
|
|
130
|
+
export declare const RELAY_CHAT_VIDEO_MS: number;
|
|
131
|
+
/** The files of a line at most. */
|
|
132
|
+
export declare const RELAY_CHAT_FILES = 9;
|
|
52
133
|
/** An agent of a member's Ta, in a room (RelayChatLine.agent). */
|
|
53
134
|
export interface RelayChatAgent {
|
|
54
135
|
id: string;
|
|
55
136
|
name: string;
|
|
56
137
|
}
|
|
57
138
|
/** What a line adds to its text: who said it and to whom (RelayRoomChat.say). */
|
|
58
|
-
export type RelayChatLineExtra = Pick<RelayChatLine, 'double' | 'agent' | 'to' | 'person' | 're' | 'task'>;
|
|
59
|
-
/** What is kept of a line: `from` is the key's. */
|
|
60
|
-
type
|
|
139
|
+
export type RelayChatLineExtra = Pick<RelayChatLine, 'double' | 'agent' | 'to' | 'person' | 're' | 'task' | 'images' | 'files'>;
|
|
140
|
+
/** What is kept of a line, and what a member signs of it in the log: `from` is the key's, or the signer's. */
|
|
141
|
+
export type RelayChatStored = Omit<RelayChatLine, 'from' | 'seq' | 'pending' | 'failed'>;
|
|
142
|
+
type StoredLine = RelayChatStored;
|
|
61
143
|
/** The keys of what is said, `chat:<member>:<n>`: each member writes only its own, so none can write as another. */
|
|
62
144
|
export declare const RELAY_CHAT_KEY = "chat:";
|
|
63
145
|
/** The bytes of JSON of one part at most, well under what the relay takes of a value once sealed. */
|
|
@@ -65,6 +147,14 @@ export declare const RELAY_CHAT_PART_BYTES: number;
|
|
|
65
147
|
/** The parts of each member kept: the oldest is cleared as a new one starts. */
|
|
66
148
|
export declare const RELAY_CHAT_PARTS = 6;
|
|
67
149
|
export declare const RELAY_CHAT_TEXT_MAX = 2000;
|
|
150
|
+
/** The pictures of a line at most, as WeChat sends nine at once. */
|
|
151
|
+
export declare const RELAY_CHAT_IMAGES = 9;
|
|
152
|
+
/** The bytes of a picture at most. */
|
|
153
|
+
export declare const RELAY_CHAT_IMAGE_BYTES: number;
|
|
154
|
+
/** The characters of the data URL of a thumbnail at most. */
|
|
155
|
+
export declare const RELAY_CHAT_THUMB_CHARS = 900;
|
|
156
|
+
/** Lines a chat holds at once: the latest; older ones are read as the page asks (RelayRoomChat.older). */
|
|
157
|
+
export declare const RELAY_CHAT_WINDOW = 500;
|
|
68
158
|
export declare namespace RelayRoomChatUtil {
|
|
69
159
|
function key(member: string, part: number): string;
|
|
70
160
|
function parse(key: string): {
|
|
@@ -75,8 +165,16 @@ export declare namespace RelayRoomChatUtil {
|
|
|
75
165
|
function lines(member: string, value: unknown, by: string): RelayChatLine[] | undefined;
|
|
76
166
|
/** What a stored line adds, as far as it is well formed. */
|
|
77
167
|
function extra(line: Record<string, unknown>): RelayChatLineExtra;
|
|
168
|
+
/** The files of a stored line, as far as each is well formed. */
|
|
169
|
+
function files(value: unknown): Pick<RelayChatLine, 'files'>;
|
|
170
|
+
/** What a line says in a word where only text shows (the list of chats, a notice, a page of guests). */
|
|
171
|
+
function preview(line: Pick<RelayChatLine, 'text' | 'images' | 'files'>, picture: string, words?: Record<RelayChatFileKind, string>): string;
|
|
78
172
|
function stored(lines: RelayChatLine[]): StoredLine[];
|
|
173
|
+
/** A line of the log, as its member signed it: well formed, or none. */
|
|
174
|
+
function signed(member: string, value: unknown, seq?: number): RelayChatLine | undefined;
|
|
79
175
|
function bytes(lines: StoredLine[]): number;
|
|
176
|
+
/** An error of a call a Ta service of before does not know (JSON-RPC's method not found, or its words). */
|
|
177
|
+
function unknownMethod(error: unknown): boolean;
|
|
80
178
|
function id(): string;
|
|
81
179
|
}
|
|
82
180
|
interface Part {
|
|
@@ -96,11 +194,34 @@ export declare class RelayRoomChat {
|
|
|
96
194
|
protected readonly parts: Map<string, Part>;
|
|
97
195
|
protected readonly listeners: Set<() => void>;
|
|
98
196
|
protected all: readonly RelayChatLine[];
|
|
197
|
+
/** Older lines are kept than those read (the log, RelayRoomChatRooms.readChat). */
|
|
198
|
+
protected olderKept: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* What is said is the log (RelayRoomChatRooms.readChat): until a Ta service of before, whose proxy names every
|
|
201
|
+
* method all the same, fails it; then the state, as before.
|
|
202
|
+
*/
|
|
203
|
+
protected log: boolean;
|
|
99
204
|
constructor(rooms: RelayRoomChatRooms, room: string);
|
|
100
205
|
/** All that is said, the earliest first. */
|
|
101
206
|
get lines(): readonly RelayChatLine[];
|
|
102
207
|
subscribe(listener: () => void): () => void;
|
|
208
|
+
/** Whether there are older lines than those read: `older` reads them. */
|
|
209
|
+
get more(): boolean;
|
|
103
210
|
load(): Promise<void>;
|
|
211
|
+
/** Lines before those read, a page of them: how many came. */
|
|
212
|
+
older(limit?: number): Promise<number>;
|
|
213
|
+
/**
|
|
214
|
+
* What happened in the room, as its event tells: a line of the log (`chat`), or a key of the state set (`state`,
|
|
215
|
+
* the chat of a Ta service of before). Whether it was of the chat.
|
|
216
|
+
*/
|
|
217
|
+
hear(event: {
|
|
218
|
+
type: string;
|
|
219
|
+
room?: string;
|
|
220
|
+
key?: string;
|
|
221
|
+
line?: RelayChatLine;
|
|
222
|
+
} & Partial<RelayRoomChatValue>): boolean;
|
|
223
|
+
/** A line said or taken: one of the same id is replaced (sent, refused), a new one comes last. */
|
|
224
|
+
heardLine(line: RelayChatLine): void;
|
|
104
225
|
/** A key of the room set, as its event tells: whether it was of the chat. */
|
|
105
226
|
heard(key: string, value: RelayRoomChatValue): boolean;
|
|
106
227
|
/**
|
|
@@ -115,6 +236,7 @@ export declare class RelayRoomChat {
|
|
|
115
236
|
protected latest(member: string): Part | undefined;
|
|
116
237
|
protected put(key: string, value: RelayRoomChatValue): void;
|
|
117
238
|
protected changed(): void;
|
|
239
|
+
protected tell(): void;
|
|
118
240
|
}
|
|
119
241
|
export {};
|
|
120
242
|
//# sourceMappingURL=relay-room-chat.d.ts.map
|