@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.
Files changed (80) hide show
  1. package/esm/common/index.d.ts +2 -0
  2. package/esm/common/index.js +2 -0
  3. package/esm/common/relay-blobs.d.ts +36 -2
  4. package/esm/common/relay-blobs.js +33 -5
  5. package/esm/common/relay-chat-store.d.ts +69 -0
  6. package/esm/common/relay-chat-store.js +50 -0
  7. package/esm/common/relay-hub-charter.d.ts +2 -0
  8. package/esm/common/relay-hub-charter.js +3 -0
  9. package/esm/common/relay-hub-log.d.ts +65 -0
  10. package/esm/common/relay-hub-log.js +147 -0
  11. package/esm/common/relay-hub.d.ts +3 -0
  12. package/esm/common/relay-hub.js +18 -0
  13. package/esm/common/relay-hubs-admins.d.ts +1 -0
  14. package/esm/common/relay-hubs-admins.js +10 -6
  15. package/esm/common/relay-hubs-chats.d.ts +73 -0
  16. package/esm/common/relay-hubs-chats.js +367 -0
  17. package/esm/common/relay-hubs-connection.d.ts +3 -1
  18. package/esm/common/relay-hubs-connection.js +7 -0
  19. package/esm/common/relay-hubs-protocol.d.ts +16 -0
  20. package/esm/common/relay-hubs.d.ts +2 -2
  21. package/esm/common/relay-hubs.js +14 -11
  22. package/esm/common/relay-info.d.ts +23 -1
  23. package/esm/common/relay-info.js +25 -2
  24. package/esm/common/relay-protocol.d.ts +60 -1
  25. package/esm/common/relay-protocol.js +15 -0
  26. package/esm/common/relay-room-chat.d.ts +126 -4
  27. package/esm/common/relay-room-chat.js +230 -6
  28. package/esm/guest/guest-i18n.d.ts +2 -0
  29. package/esm/guest/guest-i18n.js +8 -0
  30. package/esm/guest/guest.js +8 -5
  31. package/esm/node/index.d.ts +1 -0
  32. package/esm/node/index.js +1 -0
  33. package/esm/node/relay-chat-files.d.ts +52 -0
  34. package/esm/node/relay-chat-files.js +224 -0
  35. package/esm/node/relay-hub-files.d.ts +11 -1
  36. package/esm/node/relay-hub-files.js +8 -1
  37. package/esm/node/relay-server.d.ts +9 -1
  38. package/esm/node/relay-server.js +29 -18
  39. package/lib/common/index.d.ts +2 -0
  40. package/lib/common/index.js +2 -0
  41. package/lib/common/relay-blobs.d.ts +36 -2
  42. package/lib/common/relay-blobs.js +34 -6
  43. package/lib/common/relay-chat-store.d.ts +70 -0
  44. package/lib/common/relay-chat-store.js +54 -0
  45. package/lib/common/relay-hub-charter.d.ts +2 -0
  46. package/lib/common/relay-hub-charter.js +3 -0
  47. package/lib/common/relay-hub-log.d.ts +66 -0
  48. package/lib/common/relay-hub-log.js +151 -0
  49. package/lib/common/relay-hub.d.ts +3 -0
  50. package/lib/common/relay-hub.js +18 -0
  51. package/lib/common/relay-hubs-admins.d.ts +1 -0
  52. package/lib/common/relay-hubs-admins.js +9 -5
  53. package/lib/common/relay-hubs-chats.d.ts +74 -0
  54. package/lib/common/relay-hubs-chats.js +371 -0
  55. package/lib/common/relay-hubs-connection.d.ts +3 -1
  56. package/lib/common/relay-hubs-connection.js +7 -0
  57. package/lib/common/relay-hubs-protocol.d.ts +16 -0
  58. package/lib/common/relay-hubs.d.ts +2 -2
  59. package/lib/common/relay-hubs.js +14 -11
  60. package/lib/common/relay-info.d.ts +23 -1
  61. package/lib/common/relay-info.js +26 -3
  62. package/lib/common/relay-protocol.d.ts +60 -1
  63. package/lib/common/relay-protocol.js +16 -1
  64. package/lib/common/relay-room-chat.d.ts +126 -4
  65. package/lib/common/relay-room-chat.js +231 -7
  66. package/lib/guest/guest-i18n.d.ts +2 -0
  67. package/lib/guest/guest-i18n.js +8 -0
  68. package/lib/guest/guest.js +7 -4
  69. package/lib/node/index.d.ts +1 -0
  70. package/lib/node/index.js +1 -0
  71. package/lib/node/relay-chat-files.d.ts +53 -0
  72. package/lib/node/relay-chat-files.js +228 -0
  73. package/lib/node/relay-hub-files.d.ts +11 -1
  74. package/lib/node/relay-hub-files.js +8 -1
  75. package/lib/node/relay-server.d.ts +9 -1
  76. package/lib/node/relay-server.js +27 -16
  77. package/package.json +3 -3
  78. package/viewer/join.html +4 -4
  79. package/viewer/page.html +10 -10
  80. package/viewer/room.html +15 -15
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RelayRoomChat = exports.RelayRoomChatUtil = exports.RELAY_CHAT_TEXT_MAX = exports.RELAY_CHAT_PARTS = exports.RELAY_CHAT_PART_BYTES = exports.RELAY_CHAT_KEY = void 0;
3
+ exports.RelayRoomChat = exports.RelayRoomChatUtil = exports.RELAY_CHAT_WINDOW = exports.RELAY_CHAT_THUMB_CHARS = exports.RELAY_CHAT_IMAGE_BYTES = exports.RELAY_CHAT_IMAGES = exports.RELAY_CHAT_TEXT_MAX = exports.RELAY_CHAT_PARTS = exports.RELAY_CHAT_PART_BYTES = exports.RELAY_CHAT_KEY = exports.RELAY_CHAT_FILES = exports.RELAY_CHAT_VIDEO_MS = exports.RELAY_CHAT_VOICE_MS = exports.RELAY_CHAT_FILE_BYTES = void 0;
4
+ /** The bytes of a file of each kind at most: what passes between members in a minute or two. */
5
+ exports.RELAY_CHAT_FILE_BYTES = { file: 50 * 1024 * 1024, video: 30 * 1024 * 1024, voice: 2 * 1024 * 1024 };
6
+ /** How long a voice message and a video are at most. */
7
+ exports.RELAY_CHAT_VOICE_MS = 60000;
8
+ exports.RELAY_CHAT_VIDEO_MS = 3 * 60000;
9
+ /** The files of a line at most. */
10
+ exports.RELAY_CHAT_FILES = 9;
4
11
  /** The keys of what is said, `chat:<member>:<n>`: each member writes only its own, so none can write as another. */
5
12
  exports.RELAY_CHAT_KEY = 'chat:';
6
13
  /** The bytes of JSON of one part at most, well under what the relay takes of a value once sealed. */
@@ -8,6 +15,15 @@ exports.RELAY_CHAT_PART_BYTES = 8 * 1024;
8
15
  /** The parts of each member kept: the oldest is cleared as a new one starts. */
9
16
  exports.RELAY_CHAT_PARTS = 6;
10
17
  exports.RELAY_CHAT_TEXT_MAX = 2000;
18
+ /** The pictures of a line at most, as WeChat sends nine at once. */
19
+ exports.RELAY_CHAT_IMAGES = 9;
20
+ /** The bytes of a picture at most. */
21
+ exports.RELAY_CHAT_IMAGE_BYTES = 2 * 1024 * 1024;
22
+ /** The characters of the data URL of a thumbnail at most. */
23
+ exports.RELAY_CHAT_THUMB_CHARS = 900;
24
+ const IMAGE_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
25
+ /** Lines a chat holds at once: the latest; older ones are read as the page asks (RelayRoomChat.older). */
26
+ exports.RELAY_CHAT_WINDOW = 500;
11
27
  const TRIES = 6;
12
28
  var RelayRoomChatUtil;
13
29
  (function (RelayRoomChatUtil) {
@@ -47,17 +63,141 @@ var RelayRoomChatUtil;
47
63
  ...(line.person === true && to.length && line.double !== true && !line.agent ? { person: true } : {}),
48
64
  ...(typeof line.re === 'string' ? { re: line.re } : {}),
49
65
  ...(line.task === true && to.length ? { task: true } : {}),
66
+ ...images(line.images),
67
+ ...files(line.files),
50
68
  };
51
69
  }
52
70
  RelayRoomChatUtil.extra = extra;
71
+ /** The files of a stored line, as far as each is well formed. */
72
+ function files(value) {
73
+ if (!Array.isArray(value)) {
74
+ return {};
75
+ }
76
+ const files = [];
77
+ for (const file of value.slice(0, exports.RELAY_CHAT_FILES)) {
78
+ const kind = file === null || file === void 0 ? void 0 : file.kind;
79
+ if (!file ||
80
+ (kind !== 'file' && kind !== 'voice' && kind !== 'video') ||
81
+ typeof file.id !== 'string' ||
82
+ !/^[a-f0-9]{24}$/.test(file.id) ||
83
+ typeof file.sha !== 'string' ||
84
+ !/^[0-9a-f]{64}$/.test(file.sha) ||
85
+ !Number.isInteger(file.bytes) ||
86
+ file.bytes <= 0 ||
87
+ file.bytes > exports.RELAY_CHAT_FILE_BYTES[kind]) {
88
+ continue;
89
+ }
90
+ const name = [...(typeof file.name === 'string' ? file.name : '')]
91
+ .filter(char => char.charCodeAt(0) >= 32 && char !== '/' && char !== '\\')
92
+ .join('')
93
+ .slice(0, 120) || kind;
94
+ const type = typeof file.type === 'string' && /^[\w.+-]+\/[\w.+-]+$/.test(file.type) ? file.type.slice(0, 100) : 'application/octet-stream';
95
+ const most = kind === 'voice' ? exports.RELAY_CHAT_VOICE_MS : exports.RELAY_CHAT_VIDEO_MS;
96
+ const ms = kind !== 'file' && Number.isFinite(file.ms) ? Math.min(Math.max(Math.round(file.ms), 0), most) : undefined;
97
+ const size = kind === 'video' && Number.isInteger(file.w) && Number.isInteger(file.h) && file.w > 0 && file.h > 0;
98
+ const thumb = kind === 'video' &&
99
+ typeof file.thumb === 'string' &&
100
+ file.thumb.length <= exports.RELAY_CHAT_THUMB_CHARS &&
101
+ /^data:image\/(jpeg|png|webp);base64,/.test(file.thumb)
102
+ ? file.thumb
103
+ : undefined;
104
+ files.push({
105
+ id: file.id,
106
+ kind,
107
+ name,
108
+ type,
109
+ bytes: file.bytes,
110
+ sha: file.sha,
111
+ ...(ms !== undefined ? { ms } : {}),
112
+ ...(size ? { w: file.w, h: file.h } : {}),
113
+ ...(thumb ? { thumb } : {}),
114
+ });
115
+ }
116
+ return files.length ? { files } : {};
117
+ }
118
+ RelayRoomChatUtil.files = files;
119
+ /** The pictures of a stored line, as far as each is well formed. */
120
+ function images(value) {
121
+ if (!Array.isArray(value)) {
122
+ return {};
123
+ }
124
+ const images = [];
125
+ for (const image of value.slice(0, exports.RELAY_CHAT_IMAGES)) {
126
+ if (image &&
127
+ typeof image.id === 'string' &&
128
+ /^[A-Za-z0-9-]{8,64}$/.test(image.id) &&
129
+ typeof image.type === 'string' &&
130
+ IMAGE_TYPES.includes(image.type) &&
131
+ typeof image.sha === 'string' &&
132
+ /^[0-9a-f]{64}$/.test(image.sha) &&
133
+ Number.isInteger(image.w) &&
134
+ Number.isInteger(image.h) &&
135
+ Number.isInteger(image.bytes) &&
136
+ image.w > 0 &&
137
+ image.h > 0 &&
138
+ image.bytes > 0 &&
139
+ image.bytes <= exports.RELAY_CHAT_IMAGE_BYTES) {
140
+ const thumb = typeof image.thumb === 'string' && image.thumb.length <= exports.RELAY_CHAT_THUMB_CHARS && /^data:image\/(jpeg|png|webp);base64,/.test(image.thumb)
141
+ ? image.thumb
142
+ : undefined;
143
+ const blob = image.blob;
144
+ const ok = !!blob &&
145
+ typeof blob.id === 'string' &&
146
+ /^[A-Za-z0-9_-]{16,64}$/.test(blob.id) &&
147
+ typeof blob.read === 'string' &&
148
+ /^[A-Za-z0-9_-]{43}$/.test(blob.read) &&
149
+ typeof blob.key === 'string' &&
150
+ /^[A-Za-z0-9_-]{43}$/.test(blob.key) &&
151
+ Number.isFinite(blob.until);
152
+ images.push({
153
+ id: image.id,
154
+ type: image.type,
155
+ w: image.w,
156
+ h: image.h,
157
+ bytes: image.bytes,
158
+ sha: image.sha,
159
+ ...(thumb ? { thumb } : {}),
160
+ ...(ok && blob ? { blob: { id: blob.id, read: blob.read, key: blob.key, until: blob.until } } : {}),
161
+ });
162
+ }
163
+ }
164
+ return images.length ? { images } : {};
165
+ }
166
+ /** What a line says in a word where only text shows (the list of chats, a notice, a page of guests). */
167
+ function preview(line, picture, words = { file: '[file]', voice: '[voice]', video: '[video]' }) {
168
+ var _a;
169
+ var _b;
170
+ const pictures = ((_a = line.images) === null || _a === void 0 ? void 0 : _a.length) ? (line.images.length > 1 ? `${picture}×${line.images.length}` : picture) : '';
171
+ const files = ((_b = line.files) !== null && _b !== void 0 ? _b : []).map(file => (file.kind === 'file' ? `${words.file} ${file.name}` : words[file.kind]));
172
+ return [pictures, ...files, line.text].filter(Boolean).join(' ');
173
+ }
174
+ RelayRoomChatUtil.preview = preview;
53
175
  function stored(lines) {
54
- return lines.map(({ from: _from, ...line }) => line);
176
+ return lines.map(({ from: _from, seq: _seq, pending: _pending, failed: _failed, ...line }) => line);
55
177
  }
56
178
  RelayRoomChatUtil.stored = stored;
179
+ /** A line of the log, as its member signed it: well formed, or none. */
180
+ function signed(member, value, seq) {
181
+ const line = value;
182
+ if (!line || typeof line.id !== 'string' || typeof line.text !== 'string' || typeof line.at !== 'number') {
183
+ return undefined;
184
+ }
185
+ const name = typeof line.name === 'string' ? line.name.slice(0, 64) : '';
186
+ const text = line.text.slice(0, exports.RELAY_CHAT_TEXT_MAX);
187
+ return { id: line.id.slice(0, 40), from: member, name, text, at: line.at, ...extra(line), ...(seq ? { seq } : {}) };
188
+ }
189
+ RelayRoomChatUtil.signed = signed;
57
190
  function bytes(lines) {
58
191
  return new TextEncoder().encode(JSON.stringify(lines)).length;
59
192
  }
60
193
  RelayRoomChatUtil.bytes = bytes;
194
+ /** An error of a call a Ta service of before does not know (JSON-RPC's method not found, or its words). */
195
+ function unknownMethod(error) {
196
+ var _a;
197
+ const found = error;
198
+ return (found === null || found === void 0 ? void 0 : found.code) === -32601 || /method not found|not a function|unknown method|no such method/i.test(String((_a = found === null || found === void 0 ? void 0 : found.message) !== null && _a !== void 0 ? _a : error));
199
+ }
200
+ RelayRoomChatUtil.unknownMethod = unknownMethod;
61
201
  function id() {
62
202
  return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
63
203
  }
@@ -75,6 +215,9 @@ class RelayRoomChat {
75
215
  this.parts = new Map();
76
216
  this.listeners = new Set();
77
217
  this.all = [];
218
+ /** Older lines are kept than those read (the log, RelayRoomChatRooms.readChat). */
219
+ this.olderKept = false;
220
+ this.log = typeof rooms.readChat === 'function' && typeof rooms.say === 'function';
78
221
  }
79
222
  /** All that is said, the earliest first. */
80
223
  get lines() {
@@ -84,7 +227,26 @@ class RelayRoomChat {
84
227
  this.listeners.add(listener);
85
228
  return () => this.listeners.delete(listener);
86
229
  }
230
+ /** Whether there are older lines than those read: `older` reads them. */
231
+ get more() {
232
+ return this.olderKept;
233
+ }
87
234
  async load() {
235
+ if (this.log && this.rooms.readChat) {
236
+ const read = await this.rooms.readChat(this.room, { limit: exports.RELAY_CHAT_WINDOW }).catch((error) => {
237
+ if (!RelayRoomChatUtil.unknownMethod(error)) {
238
+ throw error;
239
+ }
240
+ this.log = false;
241
+ return undefined;
242
+ });
243
+ if (read) {
244
+ this.olderKept = read.more;
245
+ this.all = Array.isArray(read.lines) ? read.lines : [];
246
+ this.tell();
247
+ return;
248
+ }
249
+ }
88
250
  const state = await this.rooms.getState(this.room, exports.RELAY_CHAT_KEY);
89
251
  this.parts.clear();
90
252
  for (const [key, value] of Object.entries(state)) {
@@ -92,8 +254,60 @@ class RelayRoomChat {
92
254
  }
93
255
  this.changed();
94
256
  }
257
+ /** Lines before those read, a page of them: how many came. */
258
+ async older(limit = 100) {
259
+ const first = this.all[0];
260
+ if (!this.log || !this.rooms.readChat || !first || !this.olderKept) {
261
+ return 0;
262
+ }
263
+ const read = await this.rooms.readChat(this.room, { before: first.id, limit });
264
+ const known = new Set(this.all.map(line => line.id));
265
+ const lines = read.lines.filter(line => !known.has(line.id));
266
+ this.olderKept = read.more;
267
+ this.all = [...lines, ...this.all];
268
+ this.tell();
269
+ return lines.length;
270
+ }
271
+ /**
272
+ * What happened in the room, as its event tells: a line of the log (`chat`), or a key of the state set (`state`,
273
+ * the chat of a Ta service of before). Whether it was of the chat.
274
+ */
275
+ hear(event) {
276
+ if (event.room !== undefined && event.room !== this.room) {
277
+ return false;
278
+ }
279
+ if (event.type === 'chat' && event.line) {
280
+ this.heardLine(event.line);
281
+ return true;
282
+ }
283
+ return event.type === 'state' && typeof event.key === 'string' && this.heard(event.key, event);
284
+ }
285
+ /** A line said or taken: one of the same id is replaced (sent, refused), a new one comes last. */
286
+ heardLine(line) {
287
+ const index = this.all.findIndex(each => each.id === line.id);
288
+ if (index >= 0) {
289
+ const next = [...this.all];
290
+ next[index] = line;
291
+ this.all = next;
292
+ }
293
+ else {
294
+ const next = [...this.all, line];
295
+ // A line taken while one of this Ta waits goes before it: the pending come last.
296
+ const pending = next.findIndex(each => each.pending);
297
+ if (pending >= 0 && !line.pending) {
298
+ next.splice(next.length - 1, 1);
299
+ next.splice(pending, 0, line);
300
+ }
301
+ this.all = next.length > exports.RELAY_CHAT_WINDOW * 2 ? next.slice(-exports.RELAY_CHAT_WINDOW) : next;
302
+ this.olderKept || (this.olderKept = next.length > this.all.length);
303
+ }
304
+ this.tell();
305
+ }
95
306
  /** A key of the room set, as its event tells: whether it was of the chat. */
96
307
  heard(key, value) {
308
+ if (this.log) {
309
+ return !!RelayRoomChatUtil.parse(key);
310
+ }
97
311
  if (!RelayRoomChatUtil.parse(key)) {
98
312
  return false;
99
313
  }
@@ -110,17 +324,24 @@ class RelayRoomChat {
110
324
  * again on what another client of the same Ta wrote first. The line said, or undefined when there was nothing to say.
111
325
  */
112
326
  async say(text, self, extra = {}) {
113
- var _a;
114
- var _b, _c;
327
+ var _a, _b, _c;
328
+ var _d, _e;
115
329
  const said = text.trim().slice(0, exports.RELAY_CHAT_TEXT_MAX);
116
- if (!said) {
330
+ if (!said && !((_a = extra.images) === null || _a === void 0 ? void 0 : _a.length) && !((_b = extra.files) === null || _b === void 0 ? void 0 : _b.length)) {
117
331
  return undefined;
118
332
  }
333
+ if (this.log && this.rooms.say) {
334
+ const line = await this.rooms.say(this.room, said, RelayRoomChatUtil.extra(extra));
335
+ if (line) {
336
+ this.heardLine(line);
337
+ }
338
+ return line;
339
+ }
119
340
  for (let tries = 0; tries < TRIES; tries++) {
120
341
  const latest = this.latest(self.member);
121
342
  // After what it said last, even within the same millisecond: the lines of a member keep their order.
122
343
  const last = latest === null || latest === void 0 ? void 0 : latest.lines[latest.lines.length - 1];
123
- const at = Math.max(Date.now(), ((_b = last === null || last === void 0 ? void 0 : last.at) !== null && _b !== void 0 ? _b : 0) + 1);
344
+ const at = Math.max(Date.now(), ((_d = last === null || last === void 0 ? void 0 : last.at) !== null && _d !== void 0 ? _d : 0) + 1);
124
345
  const line = {
125
346
  id: RelayRoomChatUtil.id(),
126
347
  from: self.member,
@@ -134,7 +355,7 @@ class RelayRoomChat {
134
355
  const lines = fits && latest ? [...latest.lines, line] : [line];
135
356
  const key = RelayRoomChatUtil.key(self.member, part);
136
357
  const value = RelayRoomChatUtil.stored(lines);
137
- const result = await this.rooms.setState(this.room, key, value, (_c = (_a = this.parts.get(key)) === null || _a === void 0 ? void 0 : _a.version) !== null && _c !== void 0 ? _c : 0);
358
+ const result = await this.rooms.setState(this.room, key, value, (_e = (_c = this.parts.get(key)) === null || _c === void 0 ? void 0 : _c.version) !== null && _e !== void 0 ? _e : 0);
138
359
  if (result.ok) {
139
360
  this.put(key, { value, version: result.version, by: self.member });
140
361
  this.changed();
@@ -173,6 +394,9 @@ class RelayRoomChat {
173
394
  }
174
395
  changed() {
175
396
  this.all = [...this.parts.values()].flatMap(part => part.lines).sort((a, b) => a.at - b.at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
397
+ this.tell();
398
+ }
399
+ tell() {
176
400
  for (const listener of this.listeners) {
177
401
  listener();
178
402
  }
@@ -10,6 +10,8 @@ declare const zh: {
10
10
  namePlaceholder: string;
11
11
  join: string;
12
12
  joining: string;
13
+ picture: string;
14
+ file: string;
13
15
  keep: string;
14
16
  haveTa: string;
15
17
  waiting: string;
@@ -13,6 +13,8 @@ const zh = {
13
13
  namePlaceholder: '大家看到的名字',
14
14
  join: '申请加入',
15
15
  joining: '正在申请…',
16
+ picture: '[图片,在 Ta 里看]',
17
+ file: '[文件、语音或视频,在 Ta 里看]',
16
18
  keep: '你的名字和一把只属于这个浏览器的钥匙保存在本机;清除浏览器数据后要重新申请。',
17
19
  haveTa: '装了 Ta?在 Ta 应用里扫码或粘贴这个链接,还能一起玩小镇等游戏。',
18
20
  waiting: '已向{by}申请',
@@ -61,6 +63,8 @@ const zhTw = {
61
63
  namePlaceholder: '大家看到的名字',
62
64
  join: '申請加入',
63
65
  joining: '正在申請…',
66
+ picture: '[圖片,在 Ta 裡看]',
67
+ file: '[檔案、語音或影片,在 Ta 裡看]',
64
68
  keep: '你的名字和一把只屬於這個瀏覽器的鑰匙儲存在本機;清除瀏覽器資料後要重新申請。',
65
69
  haveTa: '裝了 Ta?在 Ta 應用裡掃碼或貼上這個連結,還能一起玩小鎮等遊戲。',
66
70
  waiting: '已向{by}申請',
@@ -109,6 +113,8 @@ const en = {
109
113
  namePlaceholder: 'What everyone sees',
110
114
  join: 'Ask to join',
111
115
  joining: 'Asking…',
116
+ picture: '[Picture: see it in Ta]',
117
+ file: '[File, voice or video: see it in Ta]',
112
118
  keep: 'Your name and a key of this browser alone are kept on this device; clear its data and you ask again.',
113
119
  haveTa: 'Have Ta? Scan this link in the Ta app or paste it there, to play the Town and other games together too.',
114
120
  waiting: 'Asked {by}',
@@ -157,6 +163,8 @@ const ja = {
157
163
  namePlaceholder: 'みんなに見える名前',
158
164
  join: '参加をリクエスト',
159
165
  joining: 'リクエスト中…',
166
+ picture: '[画像:Ta で表示]',
167
+ file: '[ファイル・ボイス・動画:Ta で表示]',
160
168
  keep: 'あなたの名前とこのブラウザ専用のキーはこのデバイスに保存されます。ブラウザデータをクリアすると再度リクエストが必要です。',
161
169
  haveTa: 'Ta をインストール済みですか?Ta アプリでこのリンクをスキャンするかペーストして、タウンなどのゲームも一緒にプレイできます。',
162
170
  waiting: '{by}さんにリクエスト済み',
@@ -101,9 +101,12 @@ class GuestPage {
101
101
  }
102
102
  start() {
103
103
  this.hubs.onEvent(event => {
104
- var _a;
105
- if (event.type === 'state' && event.room === this.link.room) {
106
- (_a = this.chat) === null || _a === void 0 ? void 0 : _a.heard(event.key, event);
104
+ var _a, _b;
105
+ if (event.type === 'chat' && event.room === this.link.room) {
106
+ (_a = this.chat) === null || _a === void 0 ? void 0 : _a.hear(event);
107
+ }
108
+ else if (event.type === 'state' && event.room === this.link.room) {
109
+ (_b = this.chat) === null || _b === void 0 ? void 0 : _b.heard(event.key, event);
107
110
  if (event.key.startsWith(relay_room_app_1.RELAY_BOARD_KEY)) {
108
111
  this.heardBoard(event.key, event.value, event.by);
109
112
  }
@@ -328,7 +331,7 @@ class GuestPage {
328
331
  if (separator) {
329
332
  nodes.push(div('when', guest_i18n_1.GuestI18n.time(line.at)));
330
333
  }
331
- const bubble = div('bubble', viewer_markdown_1.ViewerMarkdown.render(line.text));
334
+ const bubble = div('bubble', viewer_markdown_1.ViewerMarkdown.render(relay_room_chat_1.RelayRoomChatUtil.preview(line, t('picture'), { file: t('file'), voice: t('file'), video: t('file') })));
332
335
  bubble.title = guest_i18n_1.GuestI18n.time(line.at);
333
336
  if (line.from === self && !line.agent) {
334
337
  nodes.push(div('mine', bubble));
@@ -1,4 +1,5 @@
1
1
  export * from '../common';
2
+ export * from './relay-chat-files';
2
3
  export * from './relay-file-storage';
3
4
  export * from './relay-files-host';
4
5
  export * from './relay-host';
package/lib/node/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("../common"), exports);
18
+ __exportStar(require("./relay-chat-files"), exports);
18
19
  __exportStar(require("./relay-file-storage"), exports);
19
20
  __exportStar(require("./relay-files-host"), exports);
20
21
  __exportStar(require("./relay-host"), exports);
@@ -0,0 +1,53 @@
1
+ import { type RelayChatState, type RelayChatStore } from '../common/relay-chat-store';
2
+ import type { RelayChatLine } from '../common/relay-room-chat';
3
+ /**
4
+ * The key what is said in the rooms is sealed with on this computer (docs/design/ta-chat-history.md 12): in the
5
+ * keychain of macOS (the service `Ta chats`, an account of the agent directory), elsewhere or with
6
+ * `TA_CHATS_KEY=file` in `chats/.key`, readable by the user alone. Made the first time.
7
+ */
8
+ export declare namespace RelayChatKeys {
9
+ const SERVICE = "Ta chats";
10
+ function local(agentDir: string, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): () => Promise<Uint8Array>;
11
+ }
12
+ /**
13
+ * What is said in the rooms, kept in `chats/<room>/` of the agent directory (docs/design/ta-chat-history.md 8): a
14
+ * file a month (`2026-11.log`), lines only added, each sealed on its own (AES-256-GCM), so that a line cut short by a
15
+ * crash loses that line alone; and the state of the log (`state`), sealed, written whole. A month goes as a file.
16
+ */
17
+ export declare class RelayChatFiles implements RelayChatStore {
18
+ readonly dir: string;
19
+ protected readonly key: () => Promise<Uint8Array>;
20
+ protected readonly now: () => number;
21
+ /** The lines of each room read, as long as nothing was added that is not in them. */
22
+ protected readonly cache: Map<string, {
23
+ lines: RelayChatLine[];
24
+ months: number;
25
+ all: boolean;
26
+ }>;
27
+ constructor(dir: string, key: () => Promise<Uint8Array>, now?: () => number);
28
+ read(room: string, options: {
29
+ before?: string;
30
+ limit: number;
31
+ }): Promise<{
32
+ lines: RelayChatLine[];
33
+ more: boolean;
34
+ }>;
35
+ append(room: string, lines: RelayChatLine[]): Promise<void>;
36
+ state(room: string): Promise<RelayChatState | undefined>;
37
+ setState(room: string, state: RelayChatState): Promise<void>;
38
+ forget(room: string): Promise<void>;
39
+ /** The bytes of what is kept of a room; with `before`, of the months `clear` would take (those wholly before it). */
40
+ usage(room: string, before?: number): Promise<number>;
41
+ /** All the months of a room, or those wholly before `before`; a month after it stays whole. */
42
+ clear(room: string, before?: number): Promise<void>;
43
+ /** When the month of a file (`2026-11.log`) ends, UTC. */
44
+ static monthEnd(month: string): number;
45
+ protected roomDir(room: string): string;
46
+ /** The months kept of a room, the earliest first. */
47
+ protected months(room: string): string[];
48
+ protected readMonth(room: string, month: string): Promise<RelayChatLine[]>;
49
+ /** base64url of a nonce of 12 bytes, the text sealed and its tag. */
50
+ static seal(key: Uint8Array, text: string): string;
51
+ static open(key: Uint8Array, sealed: string): string | undefined;
52
+ }
53
+ //# sourceMappingURL=relay-chat-files.d.ts.map