@celljs/ta-relay 4.20.0 → 4.21.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-account-client.d.ts +4 -0
- package/esm/common/relay-account-client.js +13 -3
- package/esm/common/relay-account.d.ts +17 -2
- package/esm/common/relay-account.js +15 -6
- package/esm/common/relay-accounts.d.ts +2 -0
- package/esm/common/relay-accounts.js +16 -2
- package/esm/common/relay-group-invites.d.ts +6 -2
- package/esm/common/relay-group-invites.js +6 -5
- package/esm/common/relay-hub-charter.d.ts +74 -0
- package/esm/common/relay-hub-charter.js +149 -0
- package/esm/common/relay-hub-epochs.d.ts +43 -0
- package/esm/common/relay-hub-epochs.js +92 -0
- package/esm/common/relay-hub-util.d.ts +39 -7
- package/esm/common/relay-hub-util.js +46 -15
- package/esm/common/relay-hub.d.ts +13 -0
- package/esm/common/relay-hub.js +81 -18
- package/esm/common/relay-hubs-admins.d.ts +27 -0
- package/esm/common/relay-hubs-admins.js +91 -0
- package/esm/common/relay-hubs-connection.d.ts +19 -63
- package/esm/common/relay-hubs-connection.js +100 -87
- package/esm/common/relay-hubs-identity.d.ts +7 -1
- package/esm/common/relay-hubs-identity.js +28 -1
- package/esm/common/relay-hubs-live.d.ts +58 -0
- package/esm/common/relay-hubs-live.js +27 -0
- package/esm/common/relay-hubs-protocol.d.ts +10 -0
- package/esm/common/relay-hubs-util.d.ts +9 -0
- package/esm/common/relay-hubs-util.js +23 -1
- package/esm/common/relay-hubs.d.ts +12 -15
- package/esm/common/relay-hubs.js +60 -57
- package/esm/common/relay-protocol.d.ts +14 -3
- package/esm/common/relay-protocol.js +1 -1
- package/esm/common/relay-room-chat.d.ts +6 -1
- package/esm/common/relay-room-chat.js +1 -0
- package/esm/node/relay-server-accounts.d.ts +1 -1
- package/esm/node/relay-server-accounts.js +1 -1
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/common/relay-account-client.d.ts +4 -0
- package/lib/common/relay-account-client.js +13 -3
- package/lib/common/relay-account.d.ts +17 -2
- package/lib/common/relay-account.js +15 -6
- package/lib/common/relay-accounts.d.ts +2 -0
- package/lib/common/relay-accounts.js +16 -2
- package/lib/common/relay-group-invites.d.ts +6 -2
- package/lib/common/relay-group-invites.js +6 -5
- package/lib/common/relay-hub-charter.d.ts +75 -0
- package/lib/common/relay-hub-charter.js +152 -0
- package/lib/common/relay-hub-epochs.d.ts +44 -0
- package/lib/common/relay-hub-epochs.js +95 -0
- package/lib/common/relay-hub-util.d.ts +39 -7
- package/lib/common/relay-hub-util.js +46 -15
- package/lib/common/relay-hub.d.ts +13 -0
- package/lib/common/relay-hub.js +81 -18
- package/lib/common/relay-hubs-admins.d.ts +28 -0
- package/lib/common/relay-hubs-admins.js +95 -0
- package/lib/common/relay-hubs-connection.d.ts +19 -63
- package/lib/common/relay-hubs-connection.js +106 -94
- package/lib/common/relay-hubs-identity.d.ts +7 -1
- package/lib/common/relay-hubs-identity.js +28 -1
- package/lib/common/relay-hubs-live.d.ts +59 -0
- package/lib/common/relay-hubs-live.js +31 -0
- package/lib/common/relay-hubs-protocol.d.ts +10 -0
- package/lib/common/relay-hubs-util.d.ts +9 -0
- package/lib/common/relay-hubs-util.js +23 -1
- package/lib/common/relay-hubs.d.ts +12 -15
- package/lib/common/relay-hubs.js +66 -63
- package/lib/common/relay-protocol.d.ts +14 -3
- package/lib/common/relay-protocol.js +1 -1
- package/lib/common/relay-room-chat.d.ts +6 -1
- package/lib/common/relay-room-chat.js +1 -0
- package/lib/node/relay-server-accounts.d.ts +1 -1
- package/lib/node/relay-server-accounts.js +1 -1
- package/package.json +3 -3
- package/viewer/room.html +15 -15
|
@@ -2,9 +2,9 @@ import { RelayFriendSends, type RelayFriendShare } from './relay-friend-sends';
|
|
|
2
2
|
import { RelayFriends } from './relay-friends';
|
|
3
3
|
import { type RelayGroupInvite, RelayGroupInvites } from './relay-group-invites';
|
|
4
4
|
import { type RelayHubAskBody } from './relay-hub-util';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import type { RelayFriend, RelayFriendInfo, RelayFriendRequest, RelayRoomEvent, RelayRoomInfo, RelayRoomRequest, RelayRoomValue } from './relay-hubs-protocol';
|
|
5
|
+
import { RelayHubsAdmins } from './relay-hubs-admins';
|
|
6
|
+
import { Live } from './relay-hubs-live';
|
|
7
|
+
import type { RelayFriend, RelayFriendInfo, RelayFriendRequest, RelayRoomEvent, RelayRoomInfo, RelayRoomRecord, RelayRoomRequest, RelayRoomValue } from './relay-hubs-protocol';
|
|
8
8
|
import { type RelayPublicIdentity } from './relay-identity';
|
|
9
9
|
/**
|
|
10
10
|
* The rooms of this Ta (docs/design/ta-link.md 3): its identity and friends, the rooms it made or asked to join,
|
|
@@ -12,7 +12,7 @@ import { type RelayPublicIdentity } from './relay-identity';
|
|
|
12
12
|
* the others; every message signed by its member and sealed with the key of the room. The friends are a room of
|
|
13
13
|
* their own (RelayFriends).
|
|
14
14
|
*/
|
|
15
|
-
export declare class RelayHubs extends
|
|
15
|
+
export declare class RelayHubs extends RelayHubsAdmins {
|
|
16
16
|
protected readonly book: RelayFriends;
|
|
17
17
|
protected readonly groups: RelayGroupInvites;
|
|
18
18
|
protected readonly sends: RelayFriendSends;
|
|
@@ -49,14 +49,7 @@ export declare class RelayHubs extends RelayHubsIdentity {
|
|
|
49
49
|
requests(): Promise<RelayRoomRequest[]>;
|
|
50
50
|
/** The user's answer to one asking to join: admitted, it gets the key of the room and is in the roster. */
|
|
51
51
|
answer(roomId: string, askId: string, accept: boolean): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* The owner's choices for a room: how many members it lets in at most (RELAY_ROOM_MAX_MEMBERS by default, 2 to
|
|
54
|
-
* RELAY_ROOM_CAPACITY_MAX), for one many come to (feedback from a browser). Those in already stay.
|
|
55
|
-
*/
|
|
56
|
-
configure(roomId: string, options: {
|
|
57
|
-
members?: number;
|
|
58
|
-
}): RelayRoomInfo;
|
|
59
|
-
/** The owner takes a member out: the relay closes it at once. */
|
|
52
|
+
/** The owner or an admin takes a member out: the relay closes it at once. An admin takes out neither the owner nor an admin. */
|
|
60
53
|
remove(roomId: string, member: string): Promise<void>;
|
|
61
54
|
/** Leaves the room; the owner closes it, for everyone. A room asked to join is forgotten. */
|
|
62
55
|
leave(roomId: string): Promise<void>;
|
|
@@ -72,6 +65,12 @@ export declare class RelayHubs extends RelayHubsIdentity {
|
|
|
72
65
|
ok: boolean;
|
|
73
66
|
version: number;
|
|
74
67
|
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Whether a key of the state is this Ta's own, which no other member may replace or clear at the relay: one that
|
|
70
|
+
* names its member id (`chat:<member>:<n>`, `agents:<member>`, a like of a post), and every key of a room of
|
|
71
|
+
* friends it owns (its posts, what it sends its friends). Any other is shared, as a game's.
|
|
72
|
+
*/
|
|
73
|
+
static owns(record: Pick<RelayRoomRecord, 'member' | 'kind' | 'own'>, name: string): boolean;
|
|
75
74
|
/** Friends of the user's other computer, with those of this Ta. */
|
|
76
75
|
mergeFriends(friends: RelayFriend[]): number;
|
|
77
76
|
/** The friends, with their keys: each in the room of the other (shares to friends are sealed for them). */
|
|
@@ -109,15 +108,13 @@ export declare class RelayHubs extends RelayHubsIdentity {
|
|
|
109
108
|
friendShares(): Promise<RelayFriendShare[]>;
|
|
110
109
|
/** The user opened one (`keep`) or let it go. */
|
|
111
110
|
answerFriendShare(id: string, keep: boolean): void;
|
|
112
|
-
protected isFriends(live: Live): boolean;
|
|
113
111
|
protected friendIds(): Set<string>;
|
|
114
112
|
protected heardAsk(live: Live, ask: RelayHubAskBody): void;
|
|
113
|
+
protected foreignSet(live: Live, key: string): void;
|
|
115
114
|
protected heardMembers(members: RelayPublicIdentity[]): void;
|
|
116
115
|
protected offered(live: Live, from: RelayPublicIdentity, link: string): void;
|
|
117
116
|
/** What changes the friends: rooms coming and going, members, the links friends leave to join back. */
|
|
118
117
|
protected after(event: RelayRoomEvent): void;
|
|
119
|
-
protected owned(roomId: string): Live;
|
|
120
|
-
protected member(roomId: string): Live;
|
|
121
118
|
protected info(live: Live): RelayRoomInfo;
|
|
122
119
|
}
|
|
123
120
|
//# sourceMappingURL=relay-hubs.d.ts.map
|
package/lib/common/relay-hubs.js
CHANGED
|
@@ -4,9 +4,10 @@ exports.RelayHubs = void 0;
|
|
|
4
4
|
const relay_friend_sends_1 = require("./relay-friend-sends");
|
|
5
5
|
const relay_friends_1 = require("./relay-friends");
|
|
6
6
|
const relay_group_invites_1 = require("./relay-group-invites");
|
|
7
|
+
const relay_hub_charter_1 = require("./relay-hub-charter");
|
|
7
8
|
const relay_hub_util_1 = require("./relay-hub-util");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
9
|
+
const relay_hubs_admins_1 = require("./relay-hubs-admins");
|
|
10
|
+
const relay_hubs_live_1 = require("./relay-hubs-live");
|
|
10
11
|
const relay_identity_1 = require("./relay-identity");
|
|
11
12
|
const relay_protocol_1 = require("./relay-protocol");
|
|
12
13
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -16,7 +17,7 @@ const DAY_MS = 24 * 60 * 60 * 1000;
|
|
|
16
17
|
* the others; every message signed by its member and sealed with the key of the room. The friends are a room of
|
|
17
18
|
* their own (RelayFriends).
|
|
18
19
|
*/
|
|
19
|
-
class RelayHubs extends
|
|
20
|
+
class RelayHubs extends relay_hubs_admins_1.RelayHubsAdmins {
|
|
20
21
|
constructor() {
|
|
21
22
|
super(...arguments);
|
|
22
23
|
this.book = new relay_friends_1.RelayFriends({
|
|
@@ -43,6 +44,10 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
43
44
|
identity: () => this.identity(),
|
|
44
45
|
list: () => this.list(),
|
|
45
46
|
record: room => { var _a; return (_a = this.live.get(room)) === null || _a === void 0 ? void 0 : _a.record; },
|
|
47
|
+
manages: room => {
|
|
48
|
+
const live = this.live.get(room);
|
|
49
|
+
return !!live && this.manages(live);
|
|
50
|
+
},
|
|
46
51
|
save: () => this.save(),
|
|
47
52
|
friends: () => this.friends(),
|
|
48
53
|
friendRoom: () => this.friendRoom(),
|
|
@@ -73,7 +78,7 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
73
78
|
this.book.start();
|
|
74
79
|
}
|
|
75
80
|
for (const record of this.readRooms()) {
|
|
76
|
-
const live = new
|
|
81
|
+
const live = new relay_hubs_live_1.Live(record);
|
|
77
82
|
this.live.set(record.id, live);
|
|
78
83
|
if (record.status === 'member' || record.status === 'waiting') {
|
|
79
84
|
this.connect(live);
|
|
@@ -126,7 +131,7 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
126
131
|
createdAt: now,
|
|
127
132
|
joinedAt: now,
|
|
128
133
|
};
|
|
129
|
-
const live = new
|
|
134
|
+
const live = new relay_hubs_live_1.Live(record);
|
|
130
135
|
this.live.set(record.id, live);
|
|
131
136
|
this.save();
|
|
132
137
|
this.connect(live);
|
|
@@ -145,14 +150,15 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
145
150
|
async invite(roomId, options = {}) {
|
|
146
151
|
var _a;
|
|
147
152
|
var _b, _c;
|
|
148
|
-
const live = this.
|
|
153
|
+
const live = this.managed(roomId);
|
|
149
154
|
const identity = await this.identityOf(live);
|
|
150
155
|
const linkOf = (invite) => ({
|
|
151
156
|
link: relay_hub_util_1.RelayHubUtil.link({
|
|
152
157
|
relay: live.record.relay,
|
|
153
158
|
room: live.record.id,
|
|
154
159
|
invite: invite.secret,
|
|
155
|
-
owner:
|
|
160
|
+
// The owner's, whoever invites: the one who asks checks the answer against it (an admin's by the charter).
|
|
161
|
+
owner: live.record.owner.id,
|
|
156
162
|
title: live.record.title,
|
|
157
163
|
by: identity.name,
|
|
158
164
|
}),
|
|
@@ -203,7 +209,7 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
203
209
|
if (known) {
|
|
204
210
|
this.disconnect(known);
|
|
205
211
|
}
|
|
206
|
-
const live = new
|
|
212
|
+
const live = new relay_hubs_live_1.Live(record);
|
|
207
213
|
this.live.set(record.id, live);
|
|
208
214
|
this.save();
|
|
209
215
|
this.connect(live);
|
|
@@ -226,9 +232,9 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
226
232
|
}
|
|
227
233
|
/** The user's answer to one asking to join: admitted, it gets the key of the room and is in the roster. */
|
|
228
234
|
async answer(roomId, askId, accept) {
|
|
229
|
-
var _a;
|
|
230
|
-
var
|
|
231
|
-
const live = this.
|
|
235
|
+
var _a, _b;
|
|
236
|
+
var _c;
|
|
237
|
+
const live = this.managed(roomId);
|
|
232
238
|
const asked = live.asks.get(askId);
|
|
233
239
|
if (!asked) {
|
|
234
240
|
throw new Error('Nobody asks that now.');
|
|
@@ -241,17 +247,21 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
241
247
|
const identity = await this.identityOf(live);
|
|
242
248
|
const body = {
|
|
243
249
|
key: live.record.key,
|
|
250
|
+
...(live.record.epochs && Object.keys(live.record.epochs).length ? { epochs: live.record.epochs } : {}),
|
|
244
251
|
kind: live.record.kind,
|
|
245
252
|
title: live.record.title,
|
|
246
253
|
...(live.record.view ? { view: live.record.view } : {}),
|
|
247
254
|
...(live.record.unlisted ? { unlisted: true } : {}),
|
|
248
255
|
};
|
|
249
256
|
const ask = asked.body;
|
|
250
|
-
|
|
251
|
-
if (((_c = (_a = live.roster) === null || _a === void 0 ? void 0 : _a.members.length) !== null && _c !== void 0 ? _c : 0) >= most) {
|
|
257
|
+
if (((_c = (_a = live.roster) === null || _a === void 0 ? void 0 : _a.members.length) !== null && _c !== void 0 ? _c : 0) >= this.capacityOf(live)) {
|
|
252
258
|
throw new Error('The room is full.');
|
|
253
259
|
}
|
|
254
|
-
const
|
|
260
|
+
const head = live.record.owner;
|
|
261
|
+
const proof = !live.record.own && ((_b = live.roster) === null || _b === void 0 ? void 0 : _b.charter) && head.sign && head.box
|
|
262
|
+
? relay_hub_charter_1.RelayHubCharterUtil.answerProof({ ...head, sign: head.sign, box: head.box }, live.roster.charter)
|
|
263
|
+
: undefined;
|
|
264
|
+
const answer = await relay_hub_util_1.RelayHubUtil.sealAnswer(identity, live.record.id, ask, body, asked.invite, proof);
|
|
255
265
|
const member = { ...relay_identity_1.RelayIdentityUtil.publicOf(ask), member: ask.member, ...(ask.guest ? { guest: true } : {}), at: Date.now() };
|
|
256
266
|
const roster = await this.nextRoster(live, members => [...members.filter(other => other.member !== ask.member), member]);
|
|
257
267
|
this.request(live, { t: 'admit', ask: askId, answer, roster });
|
|
@@ -259,35 +269,20 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
259
269
|
live.asks.delete(askId);
|
|
260
270
|
this.emit({ type: 'rooms' });
|
|
261
271
|
}
|
|
262
|
-
/**
|
|
263
|
-
* The owner's choices for a room: how many members it lets in at most (RELAY_ROOM_MAX_MEMBERS by default, 2 to
|
|
264
|
-
* RELAY_ROOM_CAPACITY_MAX), for one many come to (feedback from a browser). Those in already stay.
|
|
265
|
-
*/
|
|
266
|
-
configure(roomId, options) {
|
|
267
|
-
const live = this.owned(roomId);
|
|
268
|
-
if (options.members !== undefined) {
|
|
269
|
-
const members = Math.round(Number(options.members));
|
|
270
|
-
if (!(members >= 2 && members <= relay_protocol_1.RELAY_ROOM_CAPACITY_MAX)) {
|
|
271
|
-
throw new Error(`A room takes 2 to ${relay_protocol_1.RELAY_ROOM_CAPACITY_MAX} members.`);
|
|
272
|
-
}
|
|
273
|
-
if (members === relay_protocol_1.RELAY_ROOM_MAX_MEMBERS) {
|
|
274
|
-
delete live.record.capacity;
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
live.record.capacity = members;
|
|
278
|
-
}
|
|
279
|
-
this.save();
|
|
280
|
-
}
|
|
281
|
-
return this.info(live);
|
|
282
|
-
}
|
|
283
|
-
/** The owner takes a member out: the relay closes it at once. */
|
|
272
|
+
/** The owner or an admin takes a member out: the relay closes it at once. An admin takes out neither the owner nor an admin. */
|
|
284
273
|
async remove(roomId, member) {
|
|
285
|
-
|
|
274
|
+
var _a, _b;
|
|
275
|
+
const live = this.managed(roomId);
|
|
286
276
|
if (member === live.record.member) {
|
|
287
277
|
throw new Error('The owner leaves by closing the room.');
|
|
288
278
|
}
|
|
279
|
+
const owner = (_b = (_a = live.roster) === null || _a === void 0 ? void 0 : _a.members.find(other => other.owner)) === null || _b === void 0 ? void 0 : _b.member;
|
|
280
|
+
if (!live.record.own && (member === owner || this.isAdmin(live, member))) {
|
|
281
|
+
throw new Error('Only the owner of the room does that.');
|
|
282
|
+
}
|
|
289
283
|
await this.ready(live);
|
|
290
|
-
|
|
284
|
+
// A new key for those left: the one taken out holds those of before alone (docs/design/ta-link.md 8.7).
|
|
285
|
+
const roster = await this.nextRoster(live, members => members.filter(other => other.member !== member), undefined, true);
|
|
291
286
|
this.request(live, { t: 'remove', member, roster });
|
|
292
287
|
}
|
|
293
288
|
/** Leaves the room; the owner closes it, for everyone. A room asked to join is forgotten. */
|
|
@@ -299,7 +294,7 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
299
294
|
}
|
|
300
295
|
if (live.record.status === 'member') {
|
|
301
296
|
await this.ready(live).catch(() => undefined);
|
|
302
|
-
if (((_a = live.socket) === null || _a === void 0 ? void 0 : _a.readyState) ===
|
|
297
|
+
if (((_a = live.socket) === null || _a === void 0 ? void 0 : _a.readyState) === relay_hubs_live_1.OPEN && live.synced) {
|
|
303
298
|
this.request(live, { t: live.record.own ? 'close' : 'leave' });
|
|
304
299
|
}
|
|
305
300
|
}
|
|
@@ -332,20 +327,27 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
332
327
|
await this.ready(live);
|
|
333
328
|
const identity = await this.identityOf(live);
|
|
334
329
|
const keys = live.keys;
|
|
335
|
-
const d = await relay_hub_util_1.RelayHubUtil.
|
|
330
|
+
const d = await relay_hub_util_1.RelayHubUtil.sealIn(keys, identity, live.record.member, { key: name, value: value !== null && value !== void 0 ? value : null });
|
|
336
331
|
const k = await relay_hub_util_1.RelayHubUtil.keyId(keys, name);
|
|
337
332
|
const id = this.nextId++;
|
|
338
333
|
const result = await new Promise((resolve, reject) => {
|
|
339
334
|
const timer = setTimeout(() => {
|
|
340
335
|
live.done.delete(id);
|
|
341
336
|
reject(new Error('The relay did not answer.'));
|
|
342
|
-
},
|
|
337
|
+
}, relay_hubs_live_1.READY_MS);
|
|
343
338
|
live.done.set(id, answer => {
|
|
344
339
|
clearTimeout(timer);
|
|
345
340
|
resolve(answer);
|
|
346
341
|
});
|
|
347
342
|
try {
|
|
348
|
-
this.request(live, {
|
|
343
|
+
this.request(live, {
|
|
344
|
+
t: 'set',
|
|
345
|
+
id,
|
|
346
|
+
k,
|
|
347
|
+
d,
|
|
348
|
+
...(version === undefined ? {} : { v: version }),
|
|
349
|
+
...(RelayHubs.owns(live.record, name) ? { own: true } : {}),
|
|
350
|
+
});
|
|
349
351
|
}
|
|
350
352
|
catch (error) {
|
|
351
353
|
clearTimeout(timer);
|
|
@@ -358,7 +360,9 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
358
360
|
? 'The value is too large.'
|
|
359
361
|
: result.error === 'limit'
|
|
360
362
|
? 'The shared state of the room is full.'
|
|
361
|
-
:
|
|
363
|
+
: result.error === 'owned'
|
|
364
|
+
? 'Another member keeps this key: only they or the owner of the room change it.'
|
|
365
|
+
: 'The relay refused it.');
|
|
362
366
|
}
|
|
363
367
|
if (result.ok) {
|
|
364
368
|
live.state.set(name, { value: value !== null && value !== void 0 ? value : null, version: result.v, by: live.record.member });
|
|
@@ -366,6 +370,14 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
366
370
|
}
|
|
367
371
|
return { ok: result.ok, version: result.v };
|
|
368
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Whether a key of the state is this Ta's own, which no other member may replace or clear at the relay: one that
|
|
375
|
+
* names its member id (`chat:<member>:<n>`, `agents:<member>`, a like of a post), and every key of a room of
|
|
376
|
+
* friends it owns (its posts, what it sends its friends). Any other is shared, as a game's.
|
|
377
|
+
*/
|
|
378
|
+
static owns(record, name) {
|
|
379
|
+
return name.split(':').includes(record.member) || (record.own && relay_friends_1.RelayFriendsUtil.isKind(record.kind));
|
|
380
|
+
}
|
|
369
381
|
/** Friends of the user's other computer, with those of this Ta. */
|
|
370
382
|
mergeFriends(friends) {
|
|
371
383
|
return this.book.merge(friends);
|
|
@@ -430,17 +442,15 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
430
442
|
this.sends.answer(id, keep);
|
|
431
443
|
this.emit({ type: 'rooms' });
|
|
432
444
|
}
|
|
433
|
-
isFriends(live) {
|
|
434
|
-
return live.record.own && live.record.kind === relay_friends_1.RELAY_FRIENDS_KIND;
|
|
435
|
-
}
|
|
436
445
|
friendIds() {
|
|
437
446
|
return this.book.ids();
|
|
438
447
|
}
|
|
439
448
|
heardAsk(live, ask) {
|
|
449
|
+
var _a;
|
|
440
450
|
if (this.isFriends(live)) {
|
|
441
451
|
this.book.asked(ask);
|
|
442
452
|
}
|
|
443
|
-
else if (this.groups.admits(live.record, ask)) {
|
|
453
|
+
else if (!((_a = live.charter) === null || _a === void 0 ? void 0 : _a.rules.approve) && this.groups.admits(live.record, ask)) {
|
|
444
454
|
// A friend the user invited: in at once, as the user chose it; asked as any other should that fail.
|
|
445
455
|
void this.answer(live.record.id, ask.member, true).then(() => this.groups.admitted(live.record, ask.id), () => super.heardAsk(live, ask));
|
|
446
456
|
}
|
|
@@ -448,6 +458,10 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
448
458
|
super.heardAsk(live, ask);
|
|
449
459
|
}
|
|
450
460
|
}
|
|
461
|
+
foreignSet(live, key) {
|
|
462
|
+
// Not awaited: the owner clears what one set under another's name, as soon as it is in the room.
|
|
463
|
+
void this.setState(live.record.id, key, null).catch(() => undefined);
|
|
464
|
+
}
|
|
451
465
|
heardMembers(members) {
|
|
452
466
|
if (!this.options.guest) {
|
|
453
467
|
this.book.heard(members);
|
|
@@ -470,20 +484,6 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
470
484
|
this.emit({ type: 'rooms' });
|
|
471
485
|
}
|
|
472
486
|
}
|
|
473
|
-
owned(roomId) {
|
|
474
|
-
const live = this.member(roomId);
|
|
475
|
-
if (!live.record.own) {
|
|
476
|
-
throw new Error('Only the owner of the room does that.');
|
|
477
|
-
}
|
|
478
|
-
return live;
|
|
479
|
-
}
|
|
480
|
-
member(roomId) {
|
|
481
|
-
const live = this.live.get(roomId);
|
|
482
|
-
if ((live === null || live === void 0 ? void 0 : live.record.status) !== 'member') {
|
|
483
|
-
throw new Error('Not in that room.');
|
|
484
|
-
}
|
|
485
|
-
return live;
|
|
486
|
-
}
|
|
487
487
|
info(live) {
|
|
488
488
|
var _a, _b;
|
|
489
489
|
var _c, _d;
|
|
@@ -494,7 +494,8 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
494
494
|
name: member.name,
|
|
495
495
|
...(relay_identity_1.RelayIdentityUtil.isLook(member.look) ? { look: member.look } : {}),
|
|
496
496
|
owner: !!member.owner,
|
|
497
|
-
|
|
497
|
+
...(this.isAdmin(live, member.member) ? { admin: true } : {}),
|
|
498
|
+
online: member.member === record.member ? ((_a = live.socket) === null || _a === void 0 ? void 0 : _a.readyState) === relay_hubs_live_1.OPEN && live.synced : live.online.has(member.member),
|
|
498
499
|
self: member.member === record.member,
|
|
499
500
|
...(member.guest ? { guest: true } : {}),
|
|
500
501
|
}); });
|
|
@@ -506,11 +507,13 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
506
507
|
...(record.unlisted ? { unlisted: true } : {}),
|
|
507
508
|
relay: record.relay,
|
|
508
509
|
owner: record.own,
|
|
510
|
+
...(!record.own && this.isAdmin(live, record.member) ? { admin: true } : {}),
|
|
509
511
|
...(record.own ? { capacity: (_d = record.capacity) !== null && _d !== void 0 ? _d : relay_protocol_1.RELAY_ROOM_MAX_MEMBERS } : {}),
|
|
512
|
+
...(live.charter && Object.keys(live.charter.rules).length ? { rules: { ...live.charter.rules } } : {}),
|
|
510
513
|
ownerName: record.owner.name,
|
|
511
514
|
status: record.status,
|
|
512
515
|
...(record.reason ? { reason: record.reason } : {}),
|
|
513
|
-
connected: ((_b = live.socket) === null || _b === void 0 ? void 0 : _b.readyState) ===
|
|
516
|
+
connected: ((_b = live.socket) === null || _b === void 0 ? void 0 : _b.readyState) === relay_hubs_live_1.OPEN && (live.synced || record.status === 'waiting'),
|
|
514
517
|
members,
|
|
515
518
|
createdAt: record.createdAt,
|
|
516
519
|
...(record.joinedAt ? { joinedAt: record.joinedAt } : {}),
|
|
@@ -186,7 +186,7 @@ export declare const RELAY_HUB_MAX_VALUE: number;
|
|
|
186
186
|
export declare const RELAY_HUB_MAX_KEYS = 4096;
|
|
187
187
|
/** Characters of all of the state, sealed. */
|
|
188
188
|
export declare const RELAY_HUB_MAX_STATE: number;
|
|
189
|
-
/** Asks to join waiting for the owner, and for how long. */
|
|
189
|
+
/** Asks to join waiting for the owner or an admin, and for how long. */
|
|
190
190
|
export declare const RELAY_HUB_MAX_ASKS = 20;
|
|
191
191
|
/**
|
|
192
192
|
* The key of the state of a room a member keeps its picture under (RelayIdentity.picture), its member id after it: each
|
|
@@ -200,10 +200,15 @@ export declare const RELAY_HUB_ASK_DAYS = 7;
|
|
|
200
200
|
export declare const RELAY_HUB_IDLE_DAYS = 90;
|
|
201
201
|
/** Messages of a connection in a second. */
|
|
202
202
|
export declare const RELAY_HUB_RATE = 40;
|
|
203
|
-
/**
|
|
203
|
+
/**
|
|
204
|
+
* The sealed list of the members of a room, signed by its owner (or an admin); `v` grows with each change. After a
|
|
205
|
+
* member was taken out or left, `k` holds the keys of the room's epochs sealed for each member left
|
|
206
|
+
* (docs/design/ta-link.md 8.7), by member id.
|
|
207
|
+
*/
|
|
204
208
|
export interface RelayHubRoster {
|
|
205
209
|
v: number;
|
|
206
210
|
d: string;
|
|
211
|
+
k?: Record<string, string>;
|
|
207
212
|
}
|
|
208
213
|
/** A key of the shared state: `k` the HMAC of its name, `v` its version (from 1), `d` sealed, `by` the member who wrote it last. */
|
|
209
214
|
export interface RelayHubEntry {
|
|
@@ -211,6 +216,8 @@ export interface RelayHubEntry {
|
|
|
211
216
|
v: number;
|
|
212
217
|
d: string;
|
|
213
218
|
by: string;
|
|
219
|
+
/** Its member's own: only they, or the owner of the room, set it again or clear it while they are a member. */
|
|
220
|
+
own?: true;
|
|
214
221
|
}
|
|
215
222
|
/** An ask to join, for the owner: `d` sealed with the key of the invitation. */
|
|
216
223
|
export interface RelayHubAsk {
|
|
@@ -251,10 +258,14 @@ export type RelayHubRequest = {
|
|
|
251
258
|
k: string;
|
|
252
259
|
d: string;
|
|
253
260
|
v?: number;
|
|
261
|
+
own?: true;
|
|
254
262
|
} | {
|
|
255
263
|
t: 'invite';
|
|
256
264
|
hash: string;
|
|
257
265
|
expiresAt: number;
|
|
266
|
+
} | {
|
|
267
|
+
t: 'admins';
|
|
268
|
+
admins: string[];
|
|
258
269
|
} | {
|
|
259
270
|
t: 'admit';
|
|
260
271
|
ask: string;
|
|
@@ -276,7 +287,7 @@ export type RelayHubRequest = {
|
|
|
276
287
|
t: 'close';
|
|
277
288
|
};
|
|
278
289
|
/** Why the hub refused: `auth` not a member, `gone` no such room, `invite` the invitation is wrong or ran out. */
|
|
279
|
-
export type RelayHubFailure = 'auth' | 'gone' | 'invite' | 'full' | 'large' | 'limit' | 'rate' | 'owner' | 'exists' | 'invalid';
|
|
290
|
+
export type RelayHubFailure = 'auth' | 'gone' | 'invite' | 'full' | 'large' | 'limit' | 'rate' | 'owner' | 'exists' | 'invalid' | 'owned';
|
|
280
291
|
/**
|
|
281
292
|
* What a hub sends. A member is first `welcome`d (who is online, the roster, asks for the owner), then given the
|
|
282
293
|
* state in `entries` and `synced`.
|
|
@@ -123,7 +123,7 @@ exports.RELAY_HUB_MAX_VALUE = 96 * 1024;
|
|
|
123
123
|
exports.RELAY_HUB_MAX_KEYS = 4096;
|
|
124
124
|
/** Characters of all of the state, sealed. */
|
|
125
125
|
exports.RELAY_HUB_MAX_STATE = 3 * 1024 * 1024;
|
|
126
|
-
/** Asks to join waiting for the owner, and for how long. */
|
|
126
|
+
/** Asks to join waiting for the owner or an admin, and for how long. */
|
|
127
127
|
exports.RELAY_HUB_MAX_ASKS = 20;
|
|
128
128
|
/**
|
|
129
129
|
* The key of the state of a room a member keeps its picture under (RelayIdentity.picture), its member id after it: each
|
|
@@ -36,6 +36,11 @@ export interface RelayChatLine {
|
|
|
36
36
|
* by `<member>/<agent id>`, their member's Ta answering.
|
|
37
37
|
*/
|
|
38
38
|
to?: string[];
|
|
39
|
+
/**
|
|
40
|
+
* `to` names the members themselves with @, not their doubles (docs/design/ta-link.md 7): each one's Ta tells them, and
|
|
41
|
+
* answers for them as far as they set it to (their double at once, once they are away, a draft for them to send).
|
|
42
|
+
*/
|
|
43
|
+
person?: boolean;
|
|
39
44
|
/** The id of the line it answers. */
|
|
40
45
|
re?: string;
|
|
41
46
|
/**
|
|
@@ -50,7 +55,7 @@ export interface RelayChatAgent {
|
|
|
50
55
|
name: string;
|
|
51
56
|
}
|
|
52
57
|
/** What a line adds to its text: who said it and to whom (RelayRoomChat.say). */
|
|
53
|
-
export type RelayChatLineExtra = Pick<RelayChatLine, 'double' | 'agent' | 'to' | 're' | 'task'>;
|
|
58
|
+
export type RelayChatLineExtra = Pick<RelayChatLine, 'double' | 'agent' | 'to' | 'person' | 're' | 'task'>;
|
|
54
59
|
/** What is kept of a line: `from` is the key's. */
|
|
55
60
|
type StoredLine = Omit<RelayChatLine, 'from'>;
|
|
56
61
|
/** The keys of what is said, `chat:<member>:<n>`: each member writes only its own, so none can write as another. */
|
|
@@ -44,6 +44,7 @@ var RelayRoomChatUtil;
|
|
|
44
44
|
? { agent: { id: agent.id.slice(0, 64), name: agent.name.slice(0, 64) } }
|
|
45
45
|
: {}),
|
|
46
46
|
...(to.length ? { to } : {}),
|
|
47
|
+
...(line.person === true && to.length && line.double !== true && !line.agent ? { person: true } : {}),
|
|
47
48
|
...(typeof line.re === 'string' ? { re: line.re } : {}),
|
|
48
49
|
...(line.task === true && to.length ? { task: true } : {}),
|
|
49
50
|
};
|
|
@@ -7,7 +7,7 @@ import { type RelayAccountProvider, RelayAccounts, type RelayAccountsOptions } f
|
|
|
7
7
|
export declare class RelayServerAccounts {
|
|
8
8
|
protected readonly accounts: RelayAccounts;
|
|
9
9
|
/** `authenticate`: a gateway's, whose sign-in gives the tokens (RelayAccountsOptions.authenticate). */
|
|
10
|
-
constructor(data: string | undefined, options?: Pick<RelayAccountsOptions, 'authenticate'> & {
|
|
10
|
+
constructor(data: string | undefined, options?: Pick<RelayAccountsOptions, 'authenticate' | 'issue'> & {
|
|
11
11
|
providers?: RelayAccountProvider[];
|
|
12
12
|
});
|
|
13
13
|
/** Answers a request of RELAY_ACCOUNT_PATH; never throws, an unhandled rejection would end the relay. */
|
|
@@ -18,7 +18,7 @@ class RelayServerAccounts {
|
|
|
18
18
|
var _a;
|
|
19
19
|
const books = new relay_accounts_1.RelayAccountBooks(account => data ? new relay_file_storage_1.FileRelayStorage((0, node_path_1.join)(data, 'accounts', relay_bytes_1.RelayBytes.toBase64(new TextEncoder().encode(account)))) : new relay_memory_storage_1.MemoryHubStorage());
|
|
20
20
|
const providers = (_a = options.providers) !== null && _a !== void 0 ? _a : (options.authenticate ? [] : [new relay_accounts_1.RelayGitHubAccounts()]);
|
|
21
|
-
this.accounts = new relay_accounts_1.RelayAccounts({ book: account => books.book(account), providers, authenticate: options.authenticate });
|
|
21
|
+
this.accounts = new relay_accounts_1.RelayAccounts({ book: account => books.book(account), providers, authenticate: options.authenticate, issue: options.issue });
|
|
22
22
|
}
|
|
23
23
|
/** Answers a request of RELAY_ACCOUNT_PATH; never throws, an unhandled rejection would end the relay. */
|
|
24
24
|
serve(request, response) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-relay",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.21.0",
|
|
4
4
|
"description": "Ta from anywhere: a relay that only forwards, and end-to-end encryption between a paired device and ta serve",
|
|
5
5
|
"homepage": "https://github.com/cellbang/ta",
|
|
6
6
|
"bugs": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@celljs/rpc": "4.
|
|
34
|
-
"@celljs/ta-protocol": "4.
|
|
33
|
+
"@celljs/rpc": "4.21.0",
|
|
34
|
+
"@celljs/ta-protocol": "4.21.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|