@celljs/ta-relay 4.20.0 → 4.22.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-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 +78 -0
- package/esm/common/relay-hub-charter.js +152 -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 +15 -15
- package/esm/common/relay-hubs.js +76 -57
- package/esm/common/relay-protocol.d.ts +14 -3
- package/esm/common/relay-protocol.js +1 -1
- package/esm/common/relay-room-app.d.ts +106 -0
- package/esm/common/relay-room-app.js +171 -0
- package/esm/common/relay-room-chat.d.ts +6 -1
- package/esm/common/relay-room-chat.js +1 -0
- package/esm/guest/guest-i18n.d.ts +3 -0
- package/esm/guest/guest-i18n.js +12 -0
- package/esm/guest/guest-style.d.ts +1 -1
- package/esm/guest/guest-style.js +11 -0
- package/esm/guest/guest.js +76 -6
- 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 +2 -0
- package/lib/common/index.js +2 -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 +79 -0
- package/lib/common/relay-hub-charter.js +155 -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 +15 -15
- package/lib/common/relay-hubs.js +82 -63
- package/lib/common/relay-protocol.d.ts +14 -3
- package/lib/common/relay-protocol.js +1 -1
- package/lib/common/relay-room-app.d.ts +107 -0
- package/lib/common/relay-room-app.js +176 -0
- package/lib/common/relay-room-chat.d.ts +6 -1
- package/lib/common/relay-room-chat.js +1 -0
- package/lib/guest/guest-i18n.d.ts +3 -0
- package/lib/guest/guest-i18n.js +12 -0
- package/lib/guest/guest-style.d.ts +1 -1
- package/lib/guest/guest-style.js +11 -0
- package/lib/guest/guest.js +76 -6
- 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/join.html +17 -6
- package/viewer/room.html +26 -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,16 @@ 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 readonly guestsIn: Map<string, number[]>;
|
|
114
|
+
/** One more guest let in without asking fits in the hour of a room (RELAY_GUESTS_PER_HOUR): counted. */
|
|
115
|
+
protected guestsLetIn(room: string): boolean;
|
|
116
|
+
protected foreignSet(live: Live, key: string): void;
|
|
115
117
|
protected heardMembers(members: RelayPublicIdentity[]): void;
|
|
116
118
|
protected offered(live: Live, from: RelayPublicIdentity, link: string): void;
|
|
117
119
|
/** What changes the friends: rooms coming and going, members, the links friends leave to join back. */
|
|
118
120
|
protected after(event: RelayRoomEvent): void;
|
|
119
|
-
protected owned(roomId: string): Live;
|
|
120
|
-
protected member(roomId: string): Live;
|
|
121
121
|
protected info(live: Live): RelayRoomInfo;
|
|
122
122
|
}
|
|
123
123
|
//# 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(),
|
|
@@ -60,6 +65,7 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
60
65
|
getState: (room, prefix) => this.getState(room, prefix),
|
|
61
66
|
setState: (room, key, value) => this.setState(room, key, value),
|
|
62
67
|
}, this.options.store);
|
|
68
|
+
this.guestsIn = new Map();
|
|
63
69
|
}
|
|
64
70
|
/** Connects to the rooms of rooms.json, and keeps connected. */
|
|
65
71
|
start() {
|
|
@@ -73,7 +79,7 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
73
79
|
this.book.start();
|
|
74
80
|
}
|
|
75
81
|
for (const record of this.readRooms()) {
|
|
76
|
-
const live = new
|
|
82
|
+
const live = new relay_hubs_live_1.Live(record);
|
|
77
83
|
this.live.set(record.id, live);
|
|
78
84
|
if (record.status === 'member' || record.status === 'waiting') {
|
|
79
85
|
this.connect(live);
|
|
@@ -126,7 +132,7 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
126
132
|
createdAt: now,
|
|
127
133
|
joinedAt: now,
|
|
128
134
|
};
|
|
129
|
-
const live = new
|
|
135
|
+
const live = new relay_hubs_live_1.Live(record);
|
|
130
136
|
this.live.set(record.id, live);
|
|
131
137
|
this.save();
|
|
132
138
|
this.connect(live);
|
|
@@ -145,14 +151,15 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
145
151
|
async invite(roomId, options = {}) {
|
|
146
152
|
var _a;
|
|
147
153
|
var _b, _c;
|
|
148
|
-
const live = this.
|
|
154
|
+
const live = this.managed(roomId);
|
|
149
155
|
const identity = await this.identityOf(live);
|
|
150
156
|
const linkOf = (invite) => ({
|
|
151
157
|
link: relay_hub_util_1.RelayHubUtil.link({
|
|
152
158
|
relay: live.record.relay,
|
|
153
159
|
room: live.record.id,
|
|
154
160
|
invite: invite.secret,
|
|
155
|
-
owner:
|
|
161
|
+
// The owner's, whoever invites: the one who asks checks the answer against it (an admin's by the charter).
|
|
162
|
+
owner: live.record.owner.id,
|
|
156
163
|
title: live.record.title,
|
|
157
164
|
by: identity.name,
|
|
158
165
|
}),
|
|
@@ -203,7 +210,7 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
203
210
|
if (known) {
|
|
204
211
|
this.disconnect(known);
|
|
205
212
|
}
|
|
206
|
-
const live = new
|
|
213
|
+
const live = new relay_hubs_live_1.Live(record);
|
|
207
214
|
this.live.set(record.id, live);
|
|
208
215
|
this.save();
|
|
209
216
|
this.connect(live);
|
|
@@ -226,9 +233,9 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
226
233
|
}
|
|
227
234
|
/** The user's answer to one asking to join: admitted, it gets the key of the room and is in the roster. */
|
|
228
235
|
async answer(roomId, askId, accept) {
|
|
229
|
-
var _a;
|
|
230
|
-
var
|
|
231
|
-
const live = this.
|
|
236
|
+
var _a, _b;
|
|
237
|
+
var _c;
|
|
238
|
+
const live = this.managed(roomId);
|
|
232
239
|
const asked = live.asks.get(askId);
|
|
233
240
|
if (!asked) {
|
|
234
241
|
throw new Error('Nobody asks that now.');
|
|
@@ -241,17 +248,21 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
241
248
|
const identity = await this.identityOf(live);
|
|
242
249
|
const body = {
|
|
243
250
|
key: live.record.key,
|
|
251
|
+
...(live.record.epochs && Object.keys(live.record.epochs).length ? { epochs: live.record.epochs } : {}),
|
|
244
252
|
kind: live.record.kind,
|
|
245
253
|
title: live.record.title,
|
|
246
254
|
...(live.record.view ? { view: live.record.view } : {}),
|
|
247
255
|
...(live.record.unlisted ? { unlisted: true } : {}),
|
|
248
256
|
};
|
|
249
257
|
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) {
|
|
258
|
+
if (((_c = (_a = live.roster) === null || _a === void 0 ? void 0 : _a.members.length) !== null && _c !== void 0 ? _c : 0) >= this.capacityOf(live)) {
|
|
252
259
|
throw new Error('The room is full.');
|
|
253
260
|
}
|
|
254
|
-
const
|
|
261
|
+
const head = live.record.owner;
|
|
262
|
+
const proof = !live.record.own && ((_b = live.roster) === null || _b === void 0 ? void 0 : _b.charter) && head.sign && head.box
|
|
263
|
+
? relay_hub_charter_1.RelayHubCharterUtil.answerProof({ ...head, sign: head.sign, box: head.box }, live.roster.charter)
|
|
264
|
+
: undefined;
|
|
265
|
+
const answer = await relay_hub_util_1.RelayHubUtil.sealAnswer(identity, live.record.id, ask, body, asked.invite, proof);
|
|
255
266
|
const member = { ...relay_identity_1.RelayIdentityUtil.publicOf(ask), member: ask.member, ...(ask.guest ? { guest: true } : {}), at: Date.now() };
|
|
256
267
|
const roster = await this.nextRoster(live, members => [...members.filter(other => other.member !== ask.member), member]);
|
|
257
268
|
this.request(live, { t: 'admit', ask: askId, answer, roster });
|
|
@@ -259,35 +270,20 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
259
270
|
live.asks.delete(askId);
|
|
260
271
|
this.emit({ type: 'rooms' });
|
|
261
272
|
}
|
|
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. */
|
|
273
|
+
/** 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
274
|
async remove(roomId, member) {
|
|
285
|
-
|
|
275
|
+
var _a, _b;
|
|
276
|
+
const live = this.managed(roomId);
|
|
286
277
|
if (member === live.record.member) {
|
|
287
278
|
throw new Error('The owner leaves by closing the room.');
|
|
288
279
|
}
|
|
280
|
+
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;
|
|
281
|
+
if (!live.record.own && (member === owner || this.isAdmin(live, member))) {
|
|
282
|
+
throw new Error('Only the owner of the room does that.');
|
|
283
|
+
}
|
|
289
284
|
await this.ready(live);
|
|
290
|
-
|
|
285
|
+
// A new key for those left: the one taken out holds those of before alone (docs/design/ta-link.md 8.7).
|
|
286
|
+
const roster = await this.nextRoster(live, members => members.filter(other => other.member !== member), undefined, true);
|
|
291
287
|
this.request(live, { t: 'remove', member, roster });
|
|
292
288
|
}
|
|
293
289
|
/** Leaves the room; the owner closes it, for everyone. A room asked to join is forgotten. */
|
|
@@ -299,7 +295,7 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
299
295
|
}
|
|
300
296
|
if (live.record.status === 'member') {
|
|
301
297
|
await this.ready(live).catch(() => undefined);
|
|
302
|
-
if (((_a = live.socket) === null || _a === void 0 ? void 0 : _a.readyState) ===
|
|
298
|
+
if (((_a = live.socket) === null || _a === void 0 ? void 0 : _a.readyState) === relay_hubs_live_1.OPEN && live.synced) {
|
|
303
299
|
this.request(live, { t: live.record.own ? 'close' : 'leave' });
|
|
304
300
|
}
|
|
305
301
|
}
|
|
@@ -332,20 +328,27 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
332
328
|
await this.ready(live);
|
|
333
329
|
const identity = await this.identityOf(live);
|
|
334
330
|
const keys = live.keys;
|
|
335
|
-
const d = await relay_hub_util_1.RelayHubUtil.
|
|
331
|
+
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
332
|
const k = await relay_hub_util_1.RelayHubUtil.keyId(keys, name);
|
|
337
333
|
const id = this.nextId++;
|
|
338
334
|
const result = await new Promise((resolve, reject) => {
|
|
339
335
|
const timer = setTimeout(() => {
|
|
340
336
|
live.done.delete(id);
|
|
341
337
|
reject(new Error('The relay did not answer.'));
|
|
342
|
-
},
|
|
338
|
+
}, relay_hubs_live_1.READY_MS);
|
|
343
339
|
live.done.set(id, answer => {
|
|
344
340
|
clearTimeout(timer);
|
|
345
341
|
resolve(answer);
|
|
346
342
|
});
|
|
347
343
|
try {
|
|
348
|
-
this.request(live, {
|
|
344
|
+
this.request(live, {
|
|
345
|
+
t: 'set',
|
|
346
|
+
id,
|
|
347
|
+
k,
|
|
348
|
+
d,
|
|
349
|
+
...(version === undefined ? {} : { v: version }),
|
|
350
|
+
...(RelayHubs.owns(live.record, name) ? { own: true } : {}),
|
|
351
|
+
});
|
|
349
352
|
}
|
|
350
353
|
catch (error) {
|
|
351
354
|
clearTimeout(timer);
|
|
@@ -358,7 +361,9 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
358
361
|
? 'The value is too large.'
|
|
359
362
|
: result.error === 'limit'
|
|
360
363
|
? 'The shared state of the room is full.'
|
|
361
|
-
:
|
|
364
|
+
: result.error === 'owned'
|
|
365
|
+
? 'Another member keeps this key: only they or the owner of the room change it.'
|
|
366
|
+
: 'The relay refused it.');
|
|
362
367
|
}
|
|
363
368
|
if (result.ok) {
|
|
364
369
|
live.state.set(name, { value: value !== null && value !== void 0 ? value : null, version: result.v, by: live.record.member });
|
|
@@ -366,6 +371,14 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
366
371
|
}
|
|
367
372
|
return { ok: result.ok, version: result.v };
|
|
368
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* Whether a key of the state is this Ta's own, which no other member may replace or clear at the relay: one that
|
|
376
|
+
* names its member id (`chat:<member>:<n>`, `agents:<member>`, a like of a post), and every key of a room of
|
|
377
|
+
* friends it owns (its posts, what it sends its friends). Any other is shared, as a game's.
|
|
378
|
+
*/
|
|
379
|
+
static owns(record, name) {
|
|
380
|
+
return name.split(':').includes(record.member) || (record.own && relay_friends_1.RelayFriendsUtil.isKind(record.kind));
|
|
381
|
+
}
|
|
369
382
|
/** Friends of the user's other computer, with those of this Ta. */
|
|
370
383
|
mergeFriends(friends) {
|
|
371
384
|
return this.book.merge(friends);
|
|
@@ -430,24 +443,41 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
430
443
|
this.sends.answer(id, keep);
|
|
431
444
|
this.emit({ type: 'rooms' });
|
|
432
445
|
}
|
|
433
|
-
isFriends(live) {
|
|
434
|
-
return live.record.own && live.record.kind === relay_friends_1.RELAY_FRIENDS_KIND;
|
|
435
|
-
}
|
|
436
446
|
friendIds() {
|
|
437
447
|
return this.book.ids();
|
|
438
448
|
}
|
|
439
449
|
heardAsk(live, ask) {
|
|
450
|
+
var _a, _b;
|
|
440
451
|
if (this.isFriends(live)) {
|
|
441
452
|
this.book.asked(ask);
|
|
442
453
|
}
|
|
443
|
-
else if (this.groups.admits(live.record, ask)) {
|
|
454
|
+
else if (!((_a = live.charter) === null || _a === void 0 ? void 0 : _a.rules.approve) && this.groups.admits(live.record, ask)) {
|
|
444
455
|
// A friend the user invited: in at once, as the user chose it; asked as any other should that fail.
|
|
445
456
|
void this.answer(live.record.id, ask.member, true).then(() => this.groups.admitted(live.record, ask.id), () => super.heardAsk(live, ask));
|
|
446
457
|
}
|
|
458
|
+
else if (ask.guest && ((_b = live.charter) === null || _b === void 0 ? void 0 : _b.rules[relay_hub_charter_1.RELAY_GUESTS_RULE]) && this.manages(live) && this.guestsLetIn(live.record.id)) {
|
|
459
|
+
// The owner lets those of a browser in without asking (they only chat), so many an hour; asked past it, or should that fail.
|
|
460
|
+
void this.answer(live.record.id, ask.member, true).catch(() => super.heardAsk(live, ask));
|
|
461
|
+
}
|
|
447
462
|
else {
|
|
448
463
|
super.heardAsk(live, ask);
|
|
449
464
|
}
|
|
450
465
|
}
|
|
466
|
+
/** One more guest let in without asking fits in the hour of a room (RELAY_GUESTS_PER_HOUR): counted. */
|
|
467
|
+
guestsLetIn(room) {
|
|
468
|
+
var _a;
|
|
469
|
+
const now = Date.now();
|
|
470
|
+
const times = ((_a = this.guestsIn.get(room)) !== null && _a !== void 0 ? _a : []).filter(at => now - at < 60 * 60 * 1000);
|
|
471
|
+
if (times.length >= relay_hub_charter_1.RELAY_GUESTS_PER_HOUR) {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
this.guestsIn.set(room, [...times, now]);
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
foreignSet(live, key) {
|
|
478
|
+
// Not awaited: the owner clears what one set under another's name, as soon as it is in the room.
|
|
479
|
+
void this.setState(live.record.id, key, null).catch(() => undefined);
|
|
480
|
+
}
|
|
451
481
|
heardMembers(members) {
|
|
452
482
|
if (!this.options.guest) {
|
|
453
483
|
this.book.heard(members);
|
|
@@ -470,20 +500,6 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
470
500
|
this.emit({ type: 'rooms' });
|
|
471
501
|
}
|
|
472
502
|
}
|
|
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
503
|
info(live) {
|
|
488
504
|
var _a, _b;
|
|
489
505
|
var _c, _d;
|
|
@@ -494,7 +510,8 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
494
510
|
name: member.name,
|
|
495
511
|
...(relay_identity_1.RelayIdentityUtil.isLook(member.look) ? { look: member.look } : {}),
|
|
496
512
|
owner: !!member.owner,
|
|
497
|
-
|
|
513
|
+
...(this.isAdmin(live, member.member) ? { admin: true } : {}),
|
|
514
|
+
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
515
|
self: member.member === record.member,
|
|
499
516
|
...(member.guest ? { guest: true } : {}),
|
|
500
517
|
}); });
|
|
@@ -506,11 +523,13 @@ class RelayHubs extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
506
523
|
...(record.unlisted ? { unlisted: true } : {}),
|
|
507
524
|
relay: record.relay,
|
|
508
525
|
owner: record.own,
|
|
526
|
+
...(!record.own && this.isAdmin(live, record.member) ? { admin: true } : {}),
|
|
509
527
|
...(record.own ? { capacity: (_d = record.capacity) !== null && _d !== void 0 ? _d : relay_protocol_1.RELAY_ROOM_MAX_MEMBERS } : {}),
|
|
528
|
+
...(live.charter && Object.keys(live.charter.rules).length ? { rules: { ...live.charter.rules } } : {}),
|
|
510
529
|
ownerName: record.owner.name,
|
|
511
530
|
status: record.status,
|
|
512
531
|
...(record.reason ? { reason: record.reason } : {}),
|
|
513
|
-
connected: ((_b = live.socket) === null || _b === void 0 ? void 0 : _b.readyState) ===
|
|
532
|
+
connected: ((_b = live.socket) === null || _b === void 0 ? void 0 : _b.readyState) === relay_hubs_live_1.OPEN && (live.synced || record.status === 'waiting'),
|
|
514
533
|
members,
|
|
515
534
|
createdAt: record.createdAt,
|
|
516
535
|
...(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
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { RelayChatLine, RelayChatLineExtra } from './relay-room-chat';
|
|
2
|
+
/**
|
|
3
|
+
* What every app of a group chat that listens and speaks there needs (docs/design/ta-feedback.md 1): what others said
|
|
4
|
+
* since it last read, paced; who speaks for the user (their double or an agent of theirs in the room); what others wrote
|
|
5
|
+
* kept as theirs when a model reads it; and a board of how things go that every member, and those in a browser, see.
|
|
6
|
+
* Feedback is one such app; a vote, a rota or a help desk would be others.
|
|
7
|
+
*/
|
|
8
|
+
/** Under `agents:<member>` of the state of a room, each member lists the agents of theirs they invited to it. */
|
|
9
|
+
export declare const ROOM_AGENTS_KEY = "agents:";
|
|
10
|
+
/** A line older than this when an app reads it is left: Ta was off for days. */
|
|
11
|
+
export declare const ROOM_APP_STALE_MS: number;
|
|
12
|
+
export declare namespace RoomAppUtil {
|
|
13
|
+
/** What others wrote, which a model reads inside tags: no tags of its own. */
|
|
14
|
+
function quote(text: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* What others said to the room since `since`: not by the user, not too long ago, not to someone in particular (@ a
|
|
17
|
+
* person, a double or an agent: theirs to answer), not said by a double or an agent.
|
|
18
|
+
*/
|
|
19
|
+
function fresh(lines: readonly RelayChatLine[], self: string, since: number, now: number, staleMs?: number): RelayChatLine[];
|
|
20
|
+
/** Whether one more fits in the hour before `now`. */
|
|
21
|
+
function within(times: readonly number[], now: number, most: number): boolean;
|
|
22
|
+
/** People named with @, each once. */
|
|
23
|
+
function mentions(names: readonly string[]): string;
|
|
24
|
+
}
|
|
25
|
+
export interface RoomSpeaker {
|
|
26
|
+
name: string;
|
|
27
|
+
/** What the line it says carries (RelayRoomChat.say): the agent, or that it is the double. */
|
|
28
|
+
extra: RelayChatLineExtra;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Who speaks for the user in a room: the agent of theirs they chose, while it is in the room (as `agents:<member>` of
|
|
32
|
+
* its state lists it, written by them), else their double, named `doubleName`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function roomSpeaker(rooms: {
|
|
35
|
+
getState(room: string, prefix?: string): Promise<Record<string, {
|
|
36
|
+
value: unknown;
|
|
37
|
+
by: string;
|
|
38
|
+
}>>;
|
|
39
|
+
}, room: string, self: string, agent: string | undefined, doubleName: string): Promise<RoomSpeaker>;
|
|
40
|
+
/**
|
|
41
|
+
* Paces the work of an app on what is said in rooms: once the room is quiet for `settleMs` (a few lines read as one), one
|
|
42
|
+
* run at a time per room, and no more runs that did something than `hourly` in an hour (past it, again after `laterMs`).
|
|
43
|
+
* `run` says whether it did something (a turn of a model, a line said).
|
|
44
|
+
*/
|
|
45
|
+
export declare class RoomPacer {
|
|
46
|
+
protected readonly run: (room: string) => Promise<boolean>;
|
|
47
|
+
protected readonly options: {
|
|
48
|
+
settleMs: number;
|
|
49
|
+
hourly: number;
|
|
50
|
+
laterMs: number;
|
|
51
|
+
now(): number;
|
|
52
|
+
failed(error: unknown): void;
|
|
53
|
+
};
|
|
54
|
+
protected readonly timers: Map<string, NodeJS.Timeout>;
|
|
55
|
+
protected readonly queues: Map<string, Promise<void>>;
|
|
56
|
+
protected readonly runs: Map<string, number[]>;
|
|
57
|
+
protected disposed: boolean;
|
|
58
|
+
constructor(run: (room: string) => Promise<boolean>, options: {
|
|
59
|
+
settleMs: number;
|
|
60
|
+
hourly: number;
|
|
61
|
+
laterMs: number;
|
|
62
|
+
now(): number;
|
|
63
|
+
failed(error: unknown): void;
|
|
64
|
+
});
|
|
65
|
+
/** Something was said in a room: it is read once it is quiet (`delay`, settleMs by default). */
|
|
66
|
+
heard(room: string, delay?: number): void;
|
|
67
|
+
/** What runs in a room now, done. */
|
|
68
|
+
idle(room: string): Promise<void>;
|
|
69
|
+
dispose(): void;
|
|
70
|
+
protected turn(room: string): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/** Under `board:<app>:<member>` of the state of a room, its owner says how the things of an app go, for all in it. */
|
|
73
|
+
export declare const RELAY_BOARD_KEY = "board:";
|
|
74
|
+
/** Items of a board at most, the latest. */
|
|
75
|
+
export declare const RELAY_BOARD_MAX = 30;
|
|
76
|
+
/**
|
|
77
|
+
* How an item goes, for anyone to draw without knowing the app: being done, waiting (for the owner, or for more from
|
|
78
|
+
* those who said it), done, or closed without it.
|
|
79
|
+
*/
|
|
80
|
+
export type RelayBoardState = 'doing' | 'waiting' | 'done' | 'closed';
|
|
81
|
+
export interface RelayBoardItem {
|
|
82
|
+
/** Its number in the room, as people name it (#n). */
|
|
83
|
+
n: number;
|
|
84
|
+
title: string;
|
|
85
|
+
state: RelayBoardState;
|
|
86
|
+
/** How it goes in words of the owner's language: `Being fixed`, `Waiting for the owner`. */
|
|
87
|
+
label: string;
|
|
88
|
+
/** Who it came from, by name. */
|
|
89
|
+
people: string[];
|
|
90
|
+
at: number;
|
|
91
|
+
}
|
|
92
|
+
/** A board of an app in a room: its name (`Feedback`), and its items, the latest last. */
|
|
93
|
+
export interface RelayRoomBoard {
|
|
94
|
+
title: string;
|
|
95
|
+
items: RelayBoardItem[];
|
|
96
|
+
}
|
|
97
|
+
export declare namespace RelayBoardUtil {
|
|
98
|
+
function key(app: string, member: string): string;
|
|
99
|
+
/** The board under a key of the state, if the owner of the room wrote it under their own name and it is well formed. */
|
|
100
|
+
function read(key: string, value: unknown, by: string, owner: string | undefined): RelayRoomBoard | undefined;
|
|
101
|
+
/** How many are being done or wait, and how many are done: what a line over the chat says. */
|
|
102
|
+
function counts(board: RelayRoomBoard): {
|
|
103
|
+
open: number;
|
|
104
|
+
done: number;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=relay-room-app.d.ts.map
|