@celljs/ta-relay 4.17.0 → 4.18.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 +1 -0
- package/esm/common/index.js +1 -0
- package/esm/common/relay-faces.d.ts +1 -1
- package/esm/common/relay-faces.js +56 -1
- package/esm/common/relay-files.d.ts +14 -3
- package/esm/common/relay-files.js +41 -16
- package/esm/common/relay-friend-sends.d.ts +64 -0
- package/esm/common/relay-friend-sends.js +126 -0
- package/esm/common/relay-group-invites.d.ts +76 -0
- package/esm/common/relay-group-invites.js +163 -0
- package/esm/common/relay-hubs-protocol.d.ts +3 -1
- package/esm/common/relay-hubs.d.ts +19 -0
- package/esm/common/relay-hubs.js +58 -0
- package/esm/common/relay-open-in-ta.d.ts +11 -0
- package/esm/common/relay-open-in-ta.js +34 -0
- package/esm/common/relay-protocol.d.ts +2 -2
- package/esm/common/relay-protocol.js +5 -2
- package/esm/guest/guest-i18n.d.ts +1 -0
- package/esm/guest/guest-i18n.js +45 -41
- package/esm/guest/guest-style.d.ts +1 -1
- package/esm/guest/guest-style.js +2 -0
- package/esm/guest/guest.js +7 -2
- package/esm/join/join-i18n.d.ts +1 -0
- package/esm/join/join-i18n.js +4 -0
- package/esm/join/join.js +4 -1
- package/esm/node/relay-files-host.d.ts +2 -0
- package/esm/node/relay-files-host.js +24 -5
- package/esm/viewer/viewer-i18n.d.ts +1 -0
- package/esm/viewer/viewer-i18n.js +4 -0
- package/esm/viewer/viewer-style.d.ts +1 -1
- package/esm/viewer/viewer-style.js +2 -0
- package/esm/viewer/viewer.js +3 -1
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/common/relay-faces.d.ts +1 -1
- package/lib/common/relay-faces.js +56 -1
- package/lib/common/relay-files.d.ts +14 -3
- package/lib/common/relay-files.js +42 -17
- package/lib/common/relay-friend-sends.d.ts +65 -0
- package/lib/common/relay-friend-sends.js +130 -0
- package/lib/common/relay-group-invites.d.ts +77 -0
- package/lib/common/relay-group-invites.js +167 -0
- package/lib/common/relay-hubs-protocol.d.ts +3 -1
- package/lib/common/relay-hubs.d.ts +19 -0
- package/lib/common/relay-hubs.js +58 -0
- package/lib/common/relay-open-in-ta.d.ts +12 -0
- package/lib/common/relay-open-in-ta.js +37 -0
- package/lib/common/relay-protocol.d.ts +2 -2
- package/lib/common/relay-protocol.js +5 -2
- package/lib/guest/guest-i18n.d.ts +1 -0
- package/lib/guest/guest-i18n.js +45 -41
- package/lib/guest/guest-style.d.ts +1 -1
- package/lib/guest/guest-style.js +2 -0
- package/lib/guest/guest.js +7 -2
- package/lib/join/join-i18n.d.ts +1 -0
- package/lib/join/join-i18n.js +4 -0
- package/lib/join/join.js +4 -1
- package/lib/node/relay-files-host.d.ts +2 -0
- package/lib/node/relay-files-host.js +23 -4
- package/lib/viewer/viewer-i18n.d.ts +1 -0
- package/lib/viewer/viewer-i18n.js +4 -0
- package/lib/viewer/viewer-style.d.ts +1 -1
- package/lib/viewer/viewer-style.js +2 -0
- package/lib/viewer/viewer.js +3 -1
- package/package.json +3 -3
- package/viewer/join.html +12 -3
- package/viewer/page.html +18 -9
- package/viewer/room.html +19 -8
package/esm/common/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './relay-conversation.js';
|
|
|
8
8
|
export * from './relay-faces.js';
|
|
9
9
|
export * from './relay-files.js';
|
|
10
10
|
export * from './relay-friends.js';
|
|
11
|
+
export * from './relay-group-invites.js';
|
|
11
12
|
export * from './relay-host-calls.js';
|
|
12
13
|
export * from './relay-hub.js';
|
|
13
14
|
export * from './relay-hub-util.js';
|
package/esm/common/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './relay-conversation.js';
|
|
|
8
8
|
export * from './relay-faces.js';
|
|
9
9
|
export * from './relay-files.js';
|
|
10
10
|
export * from './relay-friends.js';
|
|
11
|
+
export * from './relay-group-invites.js';
|
|
11
12
|
export * from './relay-host-calls.js';
|
|
12
13
|
export * from './relay-hub.js';
|
|
13
14
|
export * from './relay-hub-util.js';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* about while at work) are those of the page that draws them.
|
|
6
6
|
*/
|
|
7
7
|
/** How many faces there are. */
|
|
8
|
-
export const FACE_COUNT =
|
|
8
|
+
export const FACE_COUNT = 25;
|
|
9
9
|
const BLUE = '#4285F4';
|
|
10
10
|
const RED = '#EA4335';
|
|
11
11
|
const YELLOW = '#FBBC05';
|
|
@@ -45,6 +45,15 @@ const LOOKS = [
|
|
|
45
45
|
{ color: PINK, eye: '#4A1428', cheek: 'rgba(160, 20, 70, 0.3)', eyeY: 24, gap: 7.4 }, // drop
|
|
46
46
|
{ color: LILAC, eye: '#2A1A5E', cheek: CHEEK, eyeY: 25, gap: 8 }, // rabbit
|
|
47
47
|
{ color: YELLOW, eye: INK, cheek: CHEEK_WARM, eyeY: 25, gap: 7.4 }, // triangle
|
|
48
|
+
{ color: BLUE, eye: WHITE, cheek: CHEEK, eyeY: 19.5, gap: 8 }, // shield
|
|
49
|
+
{ color: CREAM, eye: '#4A3420', cheek: 'rgba(240, 120, 120, 0.5)', eyeY: 23.5, gap: 8 }, // house
|
|
50
|
+
{ color: GREEN, eye: WHITE, cheek: CHEEK, eyeY: 21, gap: 8 }, // trapezoid
|
|
51
|
+
{ color: PINK, eye: '#4A1428', cheek: 'rgba(160, 20, 70, 0.3)', eyeY: 19.5, gap: 8.4 }, // pill
|
|
52
|
+
{ color: RED, eye: WHITE, cheek: CHEEK_DEEP, accent: '#B3261E', eyeY: 20, gap: 8.4 }, // lantern
|
|
53
|
+
{ color: SKY, eye: WHITE, cheek: CHEEK, eyeY: 23.5, gap: 8 }, // cloud
|
|
54
|
+
{ color: VIOLET, eye: WHITE, cheek: CHEEK, accent: '#6B3FD4', eyeY: 22, gap: 8 }, // jar
|
|
55
|
+
{ color: TEAL, eye: WHITE, cheek: CHEEK, accent: '#1B8A84', eyeY: 25, gap: 7.6 }, // gourd
|
|
56
|
+
{ color: MINT, eye: '#1D3B27', cheek: CHEEK, accent: '#4AAE6C', eyeY: 22.5, gap: 9 }, // frog
|
|
48
57
|
];
|
|
49
58
|
/** The corners of a polygon of `count` sides around (cx, cy), the first straight up; `inner` makes it a star. */
|
|
50
59
|
function corners(count, radius, cx, cy, inner) {
|
|
@@ -138,6 +147,52 @@ function shape(face, look) {
|
|
|
138
147
|
]);
|
|
139
148
|
case 15:
|
|
140
149
|
return rounded('20,7 35,33 5,33', color, 6);
|
|
150
|
+
case 16:
|
|
151
|
+
return node('path', {
|
|
152
|
+
d: 'M20 6.5l12 4.2v8.4c0 7.4-4.9 12.6-12 15.9-7.1-3.3-12-8.5-12-15.9v-8.4Z',
|
|
153
|
+
fill: color,
|
|
154
|
+
stroke: color,
|
|
155
|
+
'stroke-width': 3,
|
|
156
|
+
'stroke-linejoin': 'round',
|
|
157
|
+
});
|
|
158
|
+
case 17:
|
|
159
|
+
return rounded('20,7 32.5,17.5 32.5,33 7.5,33 7.5,17.5', color, 4.5);
|
|
160
|
+
case 18:
|
|
161
|
+
return rounded('14,9 26,9 32.5,32 7.5,32', color, 6);
|
|
162
|
+
case 19:
|
|
163
|
+
return node('rect', { x: 4.5, y: 10.5, width: 31, height: 19.5, rx: 9.75, fill: color });
|
|
164
|
+
case 20:
|
|
165
|
+
return node('g', {}, [
|
|
166
|
+
node('rect', { x: 14, y: 5.5, width: 12, height: 4.5, rx: 1.6, fill: accent }),
|
|
167
|
+
node('rect', { x: 14, y: 30.5, width: 12, height: 4.5, rx: 1.6, fill: accent }),
|
|
168
|
+
node('ellipse', { cx: 20, cy: 20.25, rx: 15, ry: 12.25, fill: color }),
|
|
169
|
+
]);
|
|
170
|
+
case 21:
|
|
171
|
+
return node('g', {}, [
|
|
172
|
+
node('circle', { cx: 13.5, cy: 21.5, r: 7, fill: color }),
|
|
173
|
+
node('circle', { cx: 21.5, cy: 16.5, r: 9, fill: color }),
|
|
174
|
+
node('circle', { cx: 28.5, cy: 22.5, r: 6.5, fill: color }),
|
|
175
|
+
node('rect', { x: 5.5, y: 21, width: 29, height: 12, rx: 6, fill: color }),
|
|
176
|
+
]);
|
|
177
|
+
case 22:
|
|
178
|
+
return node('g', {}, [
|
|
179
|
+
node('rect', { x: 12.5, y: 5.5, width: 15, height: 5.5, rx: 2, fill: accent }),
|
|
180
|
+
node('rect', { x: 7.5, y: 9.5, width: 25, height: 25.5, rx: 6.5, fill: color }),
|
|
181
|
+
]);
|
|
182
|
+
case 23:
|
|
183
|
+
return node('g', {}, [
|
|
184
|
+
node('rect', { x: 18.8, y: 3.5, width: 2.4, height: 6, rx: 1.2, fill: accent }),
|
|
185
|
+
node('circle', { cx: 20, cy: 13, r: 6.5, fill: color }),
|
|
186
|
+
node('circle', { cx: 20, cy: 25, r: 11.5, fill: color }),
|
|
187
|
+
]);
|
|
188
|
+
case 24:
|
|
189
|
+
return node('g', {}, [
|
|
190
|
+
node('circle', { cx: 12, cy: 13, r: 5.5, fill: color }),
|
|
191
|
+
node('circle', { cx: 28, cy: 13, r: 5.5, fill: color }),
|
|
192
|
+
node('circle', { cx: 12, cy: 13, r: 2.2, fill: accent }),
|
|
193
|
+
node('circle', { cx: 28, cy: 13, r: 2.2, fill: accent }),
|
|
194
|
+
node('ellipse', { cx: 20, cy: 23.5, rx: 15.5, ry: 11.5, fill: color }),
|
|
195
|
+
]);
|
|
141
196
|
default:
|
|
142
197
|
return node('circle', { cx: 20, cy: 21, r: 14.5, fill: color });
|
|
143
198
|
}
|
|
@@ -47,9 +47,11 @@ export declare const RELAY_FILES_PREFIX = "/api/files/";
|
|
|
47
47
|
export declare const RELAY_FILE_CHUNK_BYTES: number;
|
|
48
48
|
/** The largest file a device reads this way: a video of a workspace is previewed by its first bytes, not all of it. */
|
|
49
49
|
export declare const RELAY_FILE_MAX_BYTES: number;
|
|
50
|
-
/** Files read at once on one channel; a page that loads its pictures asks for
|
|
50
|
+
/** Files read at once on one channel; a page that loads its pictures asks for more, which wait their turn. */
|
|
51
51
|
export declare const RELAY_FILES_MAX_PARALLEL = 4;
|
|
52
|
-
/**
|
|
52
|
+
/** Files waiting their turn on one channel, at most: past them a page asks for more than it can show. */
|
|
53
|
+
export declare const RELAY_FILES_MAX_WAITING = 256;
|
|
54
|
+
/** For one file, all of it, from when it is read, not while it waits its turn. */
|
|
53
55
|
export declare const RELAY_FILES_TIMEOUT_MS = 30000;
|
|
54
56
|
/** A file as the page gets it: its type as ta serve answers it, and the bytes. */
|
|
55
57
|
export interface RelayFileBytes {
|
|
@@ -65,6 +67,7 @@ export declare namespace RelayFilesUtil {
|
|
|
65
67
|
}
|
|
66
68
|
/** One file asked for, and what came of it so far. */
|
|
67
69
|
interface Pending {
|
|
70
|
+
readonly url: string;
|
|
68
71
|
readonly chunks: Uint8Array[];
|
|
69
72
|
received: number;
|
|
70
73
|
head?: {
|
|
@@ -73,7 +76,8 @@ interface Pending {
|
|
|
73
76
|
};
|
|
74
77
|
readonly resolve: (bytes: RelayFileBytes) => void;
|
|
75
78
|
readonly reject: (error: Error) => void;
|
|
76
|
-
|
|
79
|
+
/** Set once it is asked of the host: before, it waits its turn. */
|
|
80
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
77
81
|
}
|
|
78
82
|
export interface RelayFilesOptions {
|
|
79
83
|
/** For one file. Default RELAY_FILES_TIMEOUT_MS. */
|
|
@@ -90,9 +94,14 @@ export declare class RelayFiles {
|
|
|
90
94
|
protected opening?: Promise<void>;
|
|
91
95
|
protected called: number;
|
|
92
96
|
protected readonly pending: Map<number, Pending>;
|
|
97
|
+
/** Asked for but not yet of the host: no more than {@link RELAY_FILES_MAX_PARALLEL} are read at once. */
|
|
98
|
+
protected readonly waiting: number[];
|
|
99
|
+
protected asked: number;
|
|
93
100
|
constructor(pairing: RelayPairing, options?: RelayFilesOptions);
|
|
94
101
|
/** The bytes of a URL of {@link RELAY_FILES_PREFIX}, as ta serve answers them. */
|
|
95
102
|
get(url: string): Promise<RelayFileBytes>;
|
|
103
|
+
/** Asks the host for the files waiting, as many as it reads at once: more would be turned away. */
|
|
104
|
+
protected ask(): void;
|
|
96
105
|
/** Whether the channel is open: the page may keep one for as long as it shows files. */
|
|
97
106
|
get open(): boolean;
|
|
98
107
|
close(): void;
|
|
@@ -102,6 +111,8 @@ export declare class RelayFiles {
|
|
|
102
111
|
protected receive(text: string): void;
|
|
103
112
|
protected settle(id: number, error: Error): void;
|
|
104
113
|
protected finish(id: number, bytes: RelayFileBytes): void;
|
|
114
|
+
/** A file came or will not: the next one waiting is asked for. */
|
|
115
|
+
protected done(id: number): Pending | undefined;
|
|
105
116
|
/** The channel went: what was asked for is not coming. */
|
|
106
117
|
protected fail(error: Error): void;
|
|
107
118
|
}
|
|
@@ -6,9 +6,11 @@ export const RELAY_FILES_PREFIX = '/api/files/';
|
|
|
6
6
|
export const RELAY_FILE_CHUNK_BYTES = 192 * 1024;
|
|
7
7
|
/** The largest file a device reads this way: a video of a workspace is previewed by its first bytes, not all of it. */
|
|
8
8
|
export const RELAY_FILE_MAX_BYTES = 128 * 1024 * 1024;
|
|
9
|
-
/** Files read at once on one channel; a page that loads its pictures asks for
|
|
9
|
+
/** Files read at once on one channel; a page that loads its pictures asks for more, which wait their turn. */
|
|
10
10
|
export const RELAY_FILES_MAX_PARALLEL = 4;
|
|
11
|
-
/**
|
|
11
|
+
/** Files waiting their turn on one channel, at most: past them a page asks for more than it can show. */
|
|
12
|
+
export const RELAY_FILES_MAX_WAITING = 256;
|
|
13
|
+
/** For one file, all of it, from when it is read, not while it waits its turn. */
|
|
12
14
|
export const RELAY_FILES_TIMEOUT_MS = 30000;
|
|
13
15
|
export var RelayFilesUtil;
|
|
14
16
|
(function (RelayFilesUtil) {
|
|
@@ -39,6 +41,9 @@ export class RelayFiles {
|
|
|
39
41
|
this.options = options;
|
|
40
42
|
this.called = 1;
|
|
41
43
|
this.pending = new Map();
|
|
44
|
+
/** Asked for but not yet of the host: no more than {@link RELAY_FILES_MAX_PARALLEL} are read at once. */
|
|
45
|
+
this.waiting = [];
|
|
46
|
+
this.asked = 0;
|
|
42
47
|
}
|
|
43
48
|
/** The bytes of a URL of {@link RELAY_FILES_PREFIX}, as ta serve answers them. */
|
|
44
49
|
async get(url) {
|
|
@@ -48,13 +53,26 @@ export class RelayFiles {
|
|
|
48
53
|
await this.connect();
|
|
49
54
|
const id = this.called++;
|
|
50
55
|
return new Promise((resolve, reject) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.pending.set(id, { chunks: [], received: 0, resolve, reject, timer });
|
|
55
|
-
this.send({ t: 'get', id, url });
|
|
56
|
+
this.pending.set(id, { url, chunks: [], received: 0, resolve, reject });
|
|
57
|
+
this.waiting.push(id);
|
|
58
|
+
this.ask();
|
|
56
59
|
});
|
|
57
60
|
}
|
|
61
|
+
/** Asks the host for the files waiting, as many as it reads at once: more would be turned away. */
|
|
62
|
+
ask() {
|
|
63
|
+
var _a;
|
|
64
|
+
while (this.asked < RELAY_FILES_MAX_PARALLEL && this.waiting.length > 0) {
|
|
65
|
+
const id = this.waiting.shift();
|
|
66
|
+
const pending = this.pending.get(id);
|
|
67
|
+
if (!pending) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
this.asked++;
|
|
71
|
+
const timeout = (_a = this.options.timeoutMs) !== null && _a !== void 0 ? _a : RELAY_FILES_TIMEOUT_MS;
|
|
72
|
+
pending.timer = setTimeout(() => this.settle(id, new Error('The file took too long to come.')), timeout);
|
|
73
|
+
this.send({ t: 'get', id, url: pending.url });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
58
76
|
/** Whether the channel is open: the page may keep one for as long as it shows files. */
|
|
59
77
|
get open() {
|
|
60
78
|
var _a;
|
|
@@ -145,23 +163,30 @@ export class RelayFiles {
|
|
|
145
163
|
}
|
|
146
164
|
}
|
|
147
165
|
settle(id, error) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.pending.delete(id);
|
|
151
|
-
clearTimeout(pending.timer);
|
|
152
|
-
pending.reject(error);
|
|
153
|
-
}
|
|
166
|
+
var _a;
|
|
167
|
+
(_a = this.done(id)) === null || _a === void 0 ? void 0 : _a.reject(error);
|
|
154
168
|
}
|
|
155
169
|
finish(id, bytes) {
|
|
170
|
+
var _a;
|
|
171
|
+
(_a = this.done(id)) === null || _a === void 0 ? void 0 : _a.resolve(bytes);
|
|
172
|
+
}
|
|
173
|
+
/** A file came or will not: the next one waiting is asked for. */
|
|
174
|
+
done(id) {
|
|
156
175
|
const pending = this.pending.get(id);
|
|
157
|
-
if (pending) {
|
|
158
|
-
|
|
176
|
+
if (!pending) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
this.pending.delete(id);
|
|
180
|
+
if (pending.timer !== undefined) {
|
|
159
181
|
clearTimeout(pending.timer);
|
|
160
|
-
|
|
182
|
+
this.asked--;
|
|
161
183
|
}
|
|
184
|
+
this.ask();
|
|
185
|
+
return pending;
|
|
162
186
|
}
|
|
163
187
|
/** The channel went: what was asked for is not coming. */
|
|
164
188
|
fail(error) {
|
|
189
|
+
this.waiting.length = 0;
|
|
165
190
|
for (const [id] of [...this.pending]) {
|
|
166
191
|
this.settle(id, error);
|
|
167
192
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { RelayFriend, RelayHubsStore, RelayRoomInfo, RelayRoomRecord, RelayRoomValue } from './relay-hubs-protocol.js';
|
|
2
|
+
import { type RelayIdentity, type RelayPublicIdentity } from './relay-identity.js';
|
|
3
|
+
/** The keys of the room of friends of the one who sends that hold what it sent, one a friend and thing. */
|
|
4
|
+
export declare const RELAY_FRIEND_SEND = "send:";
|
|
5
|
+
/** What a friend sent the user: a link of Ta (a card, a conversation, an invitation), opened as every link is. */
|
|
6
|
+
export interface RelayFriendShare {
|
|
7
|
+
id: string;
|
|
8
|
+
link: string;
|
|
9
|
+
title: string;
|
|
10
|
+
by: {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
look?: string;
|
|
14
|
+
};
|
|
15
|
+
at: number;
|
|
16
|
+
/** The user opened it once. */
|
|
17
|
+
seen: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** What it reads and does of the rooms (RelayHubs). */
|
|
20
|
+
export interface RelayFriendSendRooms {
|
|
21
|
+
identity(): Promise<RelayIdentity>;
|
|
22
|
+
list(): RelayRoomInfo[];
|
|
23
|
+
record(room: string): RelayRoomRecord | undefined;
|
|
24
|
+
friends(): (RelayFriend & RelayPublicIdentity)[];
|
|
25
|
+
friendRoom(): Promise<RelayRoomInfo>;
|
|
26
|
+
getState(room: string, prefix?: string): Promise<Record<string, RelayRoomValue>>;
|
|
27
|
+
setState(room: string, key: string, value: unknown): Promise<{
|
|
28
|
+
ok: boolean;
|
|
29
|
+
version: number;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
/** What it keeps (`sends.json`): what the user opened and what they let go, by id, till it would be gone anyway. */
|
|
33
|
+
interface SendsBook {
|
|
34
|
+
seen: Record<string, number>;
|
|
35
|
+
gone: Record<string, number>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Links sent to friends from the share sheet (docs/design/ta-links.md 4), as invitations into group chats are: sealed
|
|
39
|
+
* for each friend (ECDH of the two, the friend's id the salt) and left in the sender's room of friends, where the
|
|
40
|
+
* friend's Ta reads it even after being away. The relay reads none of it; a friend opens it as any link of Ta, asked
|
|
41
|
+
* first wherever it would do something (join, add, import).
|
|
42
|
+
*/
|
|
43
|
+
export declare class RelayFriendSends {
|
|
44
|
+
protected readonly rooms: RelayFriendSendRooms;
|
|
45
|
+
protected readonly store: RelayHubsStore;
|
|
46
|
+
constructor(rooms: RelayFriendSendRooms, store: RelayHubsStore);
|
|
47
|
+
/** Sends a link to friends: how many it went to. */
|
|
48
|
+
send(friendIds: readonly string[], item: {
|
|
49
|
+
link: string;
|
|
50
|
+
title: string;
|
|
51
|
+
}): Promise<number>;
|
|
52
|
+
/** What friends sent the user, not let go, the latest first. */
|
|
53
|
+
list(): Promise<RelayFriendShare[]>;
|
|
54
|
+
/** The user opened one (`keep`), or let it go: no longer listed. */
|
|
55
|
+
answer(id: string, keep: boolean): void;
|
|
56
|
+
/** Whether a change of the state is of something a friend may have sent the user: the pages read again. */
|
|
57
|
+
static heard(record: RelayRoomRecord | undefined, key: string): boolean;
|
|
58
|
+
/** The key of a thing sent: neither it nor the friend can be read from it by the other friends. */
|
|
59
|
+
static keyOf(id: string, friend: string): Promise<string>;
|
|
60
|
+
protected book(): SendsBook;
|
|
61
|
+
/** What the user sent that no longer waits, taken out of the room of friends. */
|
|
62
|
+
protected prune(room: string, now: number): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { RelayBytes } from './relay-bytes.js';
|
|
2
|
+
import { RELAY_FRIENDS_KIND } from './relay-friends.js';
|
|
3
|
+
import { RelayIdentityUtil, RelayKeys } from './relay-identity.js';
|
|
4
|
+
/** The keys of the room of friends of the one who sends that hold what it sent, one a friend and thing. */
|
|
5
|
+
export const RELAY_FRIEND_SEND = 'send:';
|
|
6
|
+
/** How long a thing sent waits for the friend. */
|
|
7
|
+
const DAYS = 30;
|
|
8
|
+
const INFO = 'ta-friends/1 send';
|
|
9
|
+
const MAX_LINK = 2048;
|
|
10
|
+
const MAX_TITLE = 80;
|
|
11
|
+
/**
|
|
12
|
+
* Links sent to friends from the share sheet (docs/design/ta-links.md 4), as invitations into group chats are: sealed
|
|
13
|
+
* for each friend (ECDH of the two, the friend's id the salt) and left in the sender's room of friends, where the
|
|
14
|
+
* friend's Ta reads it even after being away. The relay reads none of it; a friend opens it as any link of Ta, asked
|
|
15
|
+
* first wherever it would do something (join, add, import).
|
|
16
|
+
*/
|
|
17
|
+
export class RelayFriendSends {
|
|
18
|
+
constructor(rooms, store) {
|
|
19
|
+
this.rooms = rooms;
|
|
20
|
+
this.store = store;
|
|
21
|
+
}
|
|
22
|
+
/** Sends a link to friends: how many it went to. */
|
|
23
|
+
async send(friendIds, item) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const link = String((_a = item.link) !== null && _a !== void 0 ? _a : '').trim();
|
|
26
|
+
if (!/^(https?|ta):\/\/\S+$/i.test(link) || link.length > MAX_LINK) {
|
|
27
|
+
throw new Error('Only a link of Ta goes to friends.');
|
|
28
|
+
}
|
|
29
|
+
const ids = new Set(friendIds);
|
|
30
|
+
const friends = this.rooms.friends().filter(friend => ids.has(friend.id));
|
|
31
|
+
if (friends.length === 0) {
|
|
32
|
+
throw new Error('None of them is a friend.');
|
|
33
|
+
}
|
|
34
|
+
const identity = await this.rooms.identity();
|
|
35
|
+
const mine = await this.rooms.friendRoom();
|
|
36
|
+
const now = Date.now();
|
|
37
|
+
await this.prune(mine.id, now);
|
|
38
|
+
const id = RelayBytes.toBase64(RelayBytes.random(12));
|
|
39
|
+
const opened = { id, link, title: String((_b = item.title) !== null && _b !== void 0 ? _b : '').slice(0, MAX_TITLE), at: now };
|
|
40
|
+
const expiresAt = now + DAYS * 86400000;
|
|
41
|
+
for (const friend of friends) {
|
|
42
|
+
const key = await RelayKeys.aesKey(await RelayIdentityUtil.agree(identity, friend.box, friend.id, INFO));
|
|
43
|
+
const sealed = { d: await RelayKeys.seal(key, JSON.stringify(opened)), expiresAt };
|
|
44
|
+
await this.rooms.setState(mine.id, await RelayFriendSends.keyOf(id, friend.id), sealed);
|
|
45
|
+
}
|
|
46
|
+
return friends.length;
|
|
47
|
+
}
|
|
48
|
+
/** What friends sent the user, not let go, the latest first. */
|
|
49
|
+
async list() {
|
|
50
|
+
var _a;
|
|
51
|
+
const identity = await this.rooms.identity();
|
|
52
|
+
const { seen, gone } = this.book();
|
|
53
|
+
const now = Date.now();
|
|
54
|
+
const found = [];
|
|
55
|
+
for (const room of this.rooms.list()) {
|
|
56
|
+
const record = this.rooms.record(room.id);
|
|
57
|
+
if (!record || record.own || record.kind !== RELAY_FRIENDS_KIND || room.status !== 'member' || !record.owner.box) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const owner = room.members.find(member => member.owner);
|
|
61
|
+
if (!owner || owner.id !== record.owner.id) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const key = await RelayKeys.aesKey(await RelayIdentityUtil.agree(identity, record.owner.box, identity.id, INFO));
|
|
65
|
+
for (const entry of Object.values(await this.rooms.getState(room.id, RELAY_FRIEND_SEND).catch(() => ({})))) {
|
|
66
|
+
const value = entry.value;
|
|
67
|
+
if (entry.by !== owner.member || !value || typeof value.d !== 'string' || Number(value.expiresAt) <= now) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const opened = await RelayKeys.open(key, value.d).then(text => JSON.parse(text), () => undefined);
|
|
71
|
+
if (!opened || typeof opened.id !== 'string' || typeof opened.link !== 'string' || gone[opened.id] !== undefined) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (!/^(https?|ta):\/\/\S+$/i.test(opened.link) || opened.link.length > MAX_LINK) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
found.push({
|
|
78
|
+
id: opened.id,
|
|
79
|
+
link: opened.link,
|
|
80
|
+
title: String((_a = opened.title) !== null && _a !== void 0 ? _a : '').slice(0, MAX_TITLE),
|
|
81
|
+
by: { id: owner.id, name: owner.name, ...(owner.look ? { look: owner.look } : {}) },
|
|
82
|
+
at: Number(opened.at) || now,
|
|
83
|
+
seen: seen[opened.id] !== undefined,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return found.sort((a, b) => b.at - a.at);
|
|
88
|
+
}
|
|
89
|
+
/** The user opened one (`keep`), or let it go: no longer listed. */
|
|
90
|
+
answer(id, keep) {
|
|
91
|
+
const book = this.book();
|
|
92
|
+
const now = Date.now();
|
|
93
|
+
const until = now + DAYS * 86400000;
|
|
94
|
+
const fresh = (map) => Object.fromEntries(Object.entries(map).filter(([, at]) => at > now));
|
|
95
|
+
book.seen = { ...fresh(book.seen), [id]: until };
|
|
96
|
+
book.gone = keep ? fresh(book.gone) : { ...fresh(book.gone), [id]: until };
|
|
97
|
+
this.store.write('sends', book);
|
|
98
|
+
}
|
|
99
|
+
/** Whether a change of the state is of something a friend may have sent the user: the pages read again. */
|
|
100
|
+
static heard(record, key) {
|
|
101
|
+
return !!record && !record.own && record.kind === RELAY_FRIENDS_KIND && key.startsWith(RELAY_FRIEND_SEND);
|
|
102
|
+
}
|
|
103
|
+
/** The key of a thing sent: neither it nor the friend can be read from it by the other friends. */
|
|
104
|
+
static async keyOf(id, friend) {
|
|
105
|
+
return RELAY_FRIEND_SEND + (await RelayKeys.hash(`${id}\n${friend}`)).slice(0, 22);
|
|
106
|
+
}
|
|
107
|
+
book() {
|
|
108
|
+
const book = this.store.read('sends');
|
|
109
|
+
const map = (value) => (value && typeof value === 'object' ? value : {});
|
|
110
|
+
return { seen: map(book === null || book === void 0 ? void 0 : book.seen), gone: map(book === null || book === void 0 ? void 0 : book.gone) };
|
|
111
|
+
}
|
|
112
|
+
/** What the user sent that no longer waits, taken out of the room of friends. */
|
|
113
|
+
async prune(room, now) {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
const self = (_b = (_a = this.rooms
|
|
116
|
+
.list()
|
|
117
|
+
.find(info => info.id === room)) === null || _a === void 0 ? void 0 : _a.members.find(member => member.self)) === null || _b === void 0 ? void 0 : _b.member;
|
|
118
|
+
for (const [key, entry] of Object.entries(await this.rooms.getState(room, RELAY_FRIEND_SEND))) {
|
|
119
|
+
const value = entry.value;
|
|
120
|
+
if (entry.by === self && value && Number(value.expiresAt) <= now) {
|
|
121
|
+
await this.rooms.setState(room, key, null).catch(() => undefined);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=relay-friend-sends.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { RelayFriend, RelayHubsStore, RelayRoomInfo, RelayRoomRecord, RelayRoomValue } from './relay-hubs-protocol.js';
|
|
2
|
+
import { type RelayIdentity, type RelayPublicIdentity } from './relay-identity.js';
|
|
3
|
+
/** The keys of the room of friends of the one who invites that hold its invitations to group chats, one a friend and chat. */
|
|
4
|
+
export declare const RELAY_GROUP_INVITE = "invite:";
|
|
5
|
+
/** One a friend invited the user into: a group chat of its own, the user's to join or not. */
|
|
6
|
+
export interface RelayGroupInvite {
|
|
7
|
+
/** The id of the room. */
|
|
8
|
+
room: string;
|
|
9
|
+
title: string;
|
|
10
|
+
by: {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
look?: string;
|
|
14
|
+
};
|
|
15
|
+
at: number;
|
|
16
|
+
expiresAt: number;
|
|
17
|
+
}
|
|
18
|
+
/** What it reads and does of the rooms (RelayHubs). */
|
|
19
|
+
export interface RelayGroupRooms {
|
|
20
|
+
identity(): Promise<RelayIdentity>;
|
|
21
|
+
list(): RelayRoomInfo[];
|
|
22
|
+
record(room: string): RelayRoomRecord | undefined;
|
|
23
|
+
save(): void;
|
|
24
|
+
friends(): (RelayFriend & RelayPublicIdentity)[];
|
|
25
|
+
friendRoom(): Promise<RelayRoomInfo>;
|
|
26
|
+
invite(room: string, options: {
|
|
27
|
+
days?: number;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
link: string;
|
|
30
|
+
expiresAt: number;
|
|
31
|
+
}>;
|
|
32
|
+
join(link: string): Promise<RelayRoomInfo>;
|
|
33
|
+
getState(room: string, prefix?: string): Promise<Record<string, RelayRoomValue>>;
|
|
34
|
+
setState(room: string, key: string, value: unknown): Promise<{
|
|
35
|
+
ok: boolean;
|
|
36
|
+
version: number;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
/** What it keeps (`groups.json`): the invitations the user turned down, by room, till they would no longer work. */
|
|
40
|
+
interface GroupsBook {
|
|
41
|
+
declined: Record<string, number>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Friends invited into a group chat (docs/design/ta-partners.md): the owner seals the invitation's link for each friend
|
|
45
|
+
* (ECDH of the two, the friend's id the salt) and leaves it in its room of friends, where the friend's Ta reads it even
|
|
46
|
+
* after being away; the friend joins on the user's word, and the owner's Ta lets in at once those it invited, by the
|
|
47
|
+
* identity their ask is signed with, and no one else: another who has the link only asks, as by any link.
|
|
48
|
+
*/
|
|
49
|
+
export declare class RelayGroupInvites {
|
|
50
|
+
protected readonly rooms: RelayGroupRooms;
|
|
51
|
+
protected readonly store: RelayHubsStore;
|
|
52
|
+
constructor(rooms: RelayGroupRooms, store: RelayHubsStore);
|
|
53
|
+
/** Invites friends into a group chat of the user's own: how many were. */
|
|
54
|
+
invite(roomId: string, friendIds: readonly string[]): Promise<number>;
|
|
55
|
+
/** Whether an ask to a room of the user's is of a friend it invited: let in at once. */
|
|
56
|
+
admits(record: RelayRoomRecord, ask: RelayPublicIdentity & {
|
|
57
|
+
guest?: boolean;
|
|
58
|
+
}): boolean;
|
|
59
|
+
/** One invited is in: its invitation goes. */
|
|
60
|
+
admitted(record: RelayRoomRecord, id: string): Promise<void>;
|
|
61
|
+
/** The group chats friends invited the user into, not joined nor turned down, the latest first. */
|
|
62
|
+
list(): Promise<RelayGroupInvite[]>;
|
|
63
|
+
/** The user's answer to an invitation: joined, or no longer listed. */
|
|
64
|
+
answer(roomId: string, accept: boolean): Promise<void>;
|
|
65
|
+
/** Whether a change of the state is of an invitation the user may have: the page reads them again. */
|
|
66
|
+
static heard(record: RelayRoomRecord | undefined, key: string): boolean;
|
|
67
|
+
/** The key of an invitation: neither the room nor the friend can be read from it by the other friends. */
|
|
68
|
+
static keyOf(room: string, friend: string): Promise<string>;
|
|
69
|
+
protected book(): GroupsBook;
|
|
70
|
+
/** The invitations of the user's own that no longer work, taken out of the room of friends. */
|
|
71
|
+
protected prune(room: string, now: number): Promise<void>;
|
|
72
|
+
protected read(): Promise<(RelayGroupInvite & {
|
|
73
|
+
link: string;
|
|
74
|
+
})[]>;
|
|
75
|
+
}
|
|
76
|
+
export {};
|