@celljs/ta-relay 4.12.0 → 4.13.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/README.en.md +26 -1
- package/README.md +26 -1
- package/esm/common/index.d.ts +3 -0
- package/esm/common/index.js +3 -0
- package/esm/common/relay-friends.d.ts +154 -0
- package/esm/common/relay-friends.js +482 -0
- package/esm/common/relay-hub-util.d.ts +9 -0
- package/esm/common/relay-hub-util.js +19 -2
- package/esm/common/relay-hubs-connection.d.ts +17 -5
- package/esm/common/relay-hubs-connection.js +40 -37
- package/esm/common/relay-hubs-protocol.d.ts +51 -7
- package/esm/common/relay-hubs.d.ts +67 -5
- package/esm/common/relay-hubs.js +305 -16
- package/esm/common/relay-identity.d.ts +2 -0
- package/esm/common/relay-info.d.ts +44 -0
- package/esm/common/relay-info.js +94 -0
- package/esm/common/relay-protocol.d.ts +7 -3
- package/esm/common/relay-protocol.js +7 -3
- package/esm/common/relay-room-chat.d.ts +6 -1
- package/esm/common/relay-room-chat.js +1 -0
- package/esm/common/relay-spot.d.ts +122 -0
- package/esm/common/relay-spot.js +179 -0
- package/esm/guest/guest-i18n.d.ts +2 -0
- package/esm/guest/guest-i18n.js +4 -0
- package/esm/guest/guest.js +9 -1
- package/esm/node/index.d.ts +2 -0
- package/esm/node/index.js +2 -0
- package/esm/node/relay-file-storage.d.ts +32 -0
- package/esm/node/relay-file-storage.js +101 -0
- package/esm/node/relay-host.d.ts +63 -28
- package/esm/node/relay-host.js +145 -52
- package/esm/node/relay-server.d.ts +37 -3
- package/esm/node/relay-server.js +193 -37
- package/esm/node/relay-store.d.ts +34 -6
- package/esm/node/relay-store.js +54 -22
- package/esm/node/relays-file.d.ts +139 -0
- package/esm/node/relays-file.js +373 -0
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.js +3 -0
- package/lib/common/relay-friends.d.ts +155 -0
- package/lib/common/relay-friends.js +486 -0
- package/lib/common/relay-hub-util.d.ts +9 -0
- package/lib/common/relay-hub-util.js +19 -2
- package/lib/common/relay-hubs-connection.d.ts +17 -5
- package/lib/common/relay-hubs-connection.js +40 -37
- package/lib/common/relay-hubs-protocol.d.ts +51 -7
- package/lib/common/relay-hubs.d.ts +67 -5
- package/lib/common/relay-hubs.js +306 -17
- package/lib/common/relay-identity.d.ts +2 -0
- package/lib/common/relay-info.d.ts +45 -0
- package/lib/common/relay-info.js +97 -0
- package/lib/common/relay-protocol.d.ts +7 -3
- package/lib/common/relay-protocol.js +8 -4
- package/lib/common/relay-room-chat.d.ts +6 -1
- package/lib/common/relay-room-chat.js +1 -0
- package/lib/common/relay-spot.d.ts +123 -0
- package/lib/common/relay-spot.js +183 -0
- package/lib/guest/guest-i18n.d.ts +2 -0
- package/lib/guest/guest-i18n.js +4 -0
- package/lib/guest/guest.js +9 -1
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.js +2 -0
- package/lib/node/relay-file-storage.d.ts +33 -0
- package/lib/node/relay-file-storage.js +105 -0
- package/lib/node/relay-host.d.ts +63 -28
- package/lib/node/relay-host.js +146 -53
- package/lib/node/relay-server.d.ts +37 -3
- package/lib/node/relay-server.js +193 -37
- package/lib/node/relay-store.d.ts +34 -6
- package/lib/node/relay-store.js +54 -22
- package/lib/node/relays-file.d.ts +140 -0
- package/lib/node/relays-file.js +378 -0
- package/package.json +2 -2
- package/viewer/room.html +10 -10
|
@@ -10,9 +10,17 @@ var RelayHubUtil;
|
|
|
10
10
|
/** `https://<relay>/r#v=1&r=<room>&i=<invite>&o=<owner>&n=<title>&by=<name>`. */
|
|
11
11
|
function link(link) {
|
|
12
12
|
const fragment = new URLSearchParams({ v: '1', r: link.room, i: link.invite, o: link.owner, n: link.title, by: link.by });
|
|
13
|
+
if (link.kind) {
|
|
14
|
+
fragment.set('c', link.kind);
|
|
15
|
+
}
|
|
13
16
|
return `${link.relay}${relay_protocol_1.RELAY_ROOM_PATH}#${fragment}`;
|
|
14
17
|
}
|
|
15
18
|
RelayHubUtil.link = link;
|
|
19
|
+
/** The link of a room as a package keeps it for itself (RelayHubLink.kind). */
|
|
20
|
+
function withKind(text, kind) {
|
|
21
|
+
return link({ ...parse(text), kind });
|
|
22
|
+
}
|
|
23
|
+
RelayHubUtil.withKind = withKind;
|
|
16
24
|
function is(text) {
|
|
17
25
|
try {
|
|
18
26
|
parse(text);
|
|
@@ -25,7 +33,7 @@ var RelayHubUtil;
|
|
|
25
33
|
RelayHubUtil.is = is;
|
|
26
34
|
/** Throws on what is not a link of {@link link}. */
|
|
27
35
|
function parse(text) {
|
|
28
|
-
var _a, _b;
|
|
36
|
+
var _a, _b, _c;
|
|
29
37
|
const url = new URL(text.trim());
|
|
30
38
|
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
31
39
|
const [room, invite, owner] = ['r', 'i', 'o'].map(name => { var _a; return (_a = fragment.get(name)) !== null && _a !== void 0 ? _a : ''; });
|
|
@@ -37,7 +45,16 @@ var RelayHubUtil;
|
|
|
37
45
|
!/^[A-Za-z0-9_-]{22}$/.test(owner)) {
|
|
38
46
|
throw new Error('Not a link inviting into a room of Ta.');
|
|
39
47
|
}
|
|
40
|
-
|
|
48
|
+
const kind = (_a = fragment.get('c')) !== null && _a !== void 0 ? _a : '';
|
|
49
|
+
return {
|
|
50
|
+
relay: url.origin,
|
|
51
|
+
room,
|
|
52
|
+
invite,
|
|
53
|
+
owner,
|
|
54
|
+
title: ((_b = fragment.get('n')) !== null && _b !== void 0 ? _b : '').slice(0, 200),
|
|
55
|
+
by: ((_c = fragment.get('by')) !== null && _c !== void 0 ? _c : '').slice(0, 100),
|
|
56
|
+
...(/^[a-z0-9-]{1,40}$/.test(kind) ? { kind } : {}),
|
|
57
|
+
};
|
|
41
58
|
}
|
|
42
59
|
RelayHubUtil.parse = parse;
|
|
43
60
|
function randomId() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RelayHubAskBody, type RelayHubKeys, type RelayHubMember, type RelayHubRosterBody } from './relay-hub-util';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RelayHubsOptions, RelayRoomEvent, RelayRoomRecord, RelayRoomRequest, RelayRoomStatus, RelayRoomValue } from './relay-hubs-protocol';
|
|
3
3
|
import { type RelayIdentity, type RelayPublicIdentity } from './relay-identity';
|
|
4
4
|
import { type RelayHubEntry, type RelayHubFailure, type RelayHubRequest } from './relay-protocol';
|
|
5
5
|
/** What a member sends in a message, signed and sealed: data of an extension, or a word of Ta itself. */
|
|
@@ -7,6 +7,8 @@ export interface MessageBody {
|
|
|
7
7
|
d?: unknown;
|
|
8
8
|
/** A member's new name, for the owner to put in the roster. */
|
|
9
9
|
name?: string;
|
|
10
|
+
/** Asks the one it is sent to to be friends: the link of the sender's room of friends (RelayFriends.offer). */
|
|
11
|
+
friend?: string;
|
|
10
12
|
}
|
|
11
13
|
export interface StateBody {
|
|
12
14
|
key: string;
|
|
@@ -48,7 +50,7 @@ export declare class Live {
|
|
|
48
50
|
/**
|
|
49
51
|
* The half of {@link RelayHubs} that keeps a connection to the hub of each room and reads what comes over it:
|
|
50
52
|
* connecting again, the welcome, the roster, the state and the messages, each opened and checked against the
|
|
51
|
-
* signatures of the roster; what is kept of the rooms
|
|
53
|
+
* signatures of the roster; what is kept of the rooms.
|
|
52
54
|
*/
|
|
53
55
|
export declare abstract class RelayHubsConnection {
|
|
54
56
|
protected readonly options: RelayHubsOptions;
|
|
@@ -62,6 +64,8 @@ export declare abstract class RelayHubsConnection {
|
|
|
62
64
|
constructor(options: RelayHubsOptions);
|
|
63
65
|
/** This Ta's identity, made the first time. */
|
|
64
66
|
identity(): Promise<RelayIdentity>;
|
|
67
|
+
/** Who this Ta is in a room: the identity it joined with when it took on another since (RelayRoomRecord.identity). */
|
|
68
|
+
protected identityOf(live: Live): Promise<RelayIdentity>;
|
|
65
69
|
protected requestOf(live: Live, ask: RelayHubAskBody, friends: Set<string>): RelayRoomRequest;
|
|
66
70
|
/** Resolves once the room is connected and has its state; rejects after a while. */
|
|
67
71
|
protected ready(live: Live): Promise<void>;
|
|
@@ -83,17 +87,25 @@ export declare abstract class RelayHubsConnection {
|
|
|
83
87
|
protected admitted(live: Live, answer: string): Promise<void>;
|
|
84
88
|
/** An ask to join: told as a request the first time this Ta hears it; `fresh` when it came now, not with the welcome. */
|
|
85
89
|
protected asked(live: Live, sealed: string, fresh: boolean): Promise<void>;
|
|
90
|
+
/** One asks to join a room of this Ta, heard the first time. */
|
|
91
|
+
protected heardAsk(live: Live, ask: RelayHubAskBody): void;
|
|
92
|
+
/** The members of a roster, read: those of them the user chose as friends are kept up to date. */
|
|
93
|
+
protected heardMembers(_members: RelayPublicIdentity[]): void;
|
|
94
|
+
/** A member asks the user to be friends, by the link of its room of friends. */
|
|
95
|
+
protected offered(_live: Live, _from: RelayPublicIdentity, _link: string): void;
|
|
86
96
|
protected readRoster(live: Live, sealed: string): Promise<void>;
|
|
87
97
|
protected guestOf(live: Live, member: string): boolean;
|
|
88
98
|
protected signOf(live: Live): (member: string) => string | undefined;
|
|
89
99
|
protected readEntry(live: Live, entry: RelayHubEntry, tell: boolean): Promise<void>;
|
|
90
100
|
protected readMessage(live: Live, from: string, sealed: string): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
protected meet(title: string, members: RelayPublicIdentity[]): void;
|
|
101
|
+
/** Ids of those the user chose as friends. */
|
|
93
102
|
protected friendIds(): Set<string>;
|
|
94
|
-
protected readFriends(): RelayFriend[];
|
|
95
103
|
protected readRooms(): RelayRoomRecord[];
|
|
96
104
|
protected save(): void;
|
|
105
|
+
/** To the listeners, then what follows from it (RelayHubs: the friends settle). */
|
|
97
106
|
protected emit(event: RelayRoomEvent): void;
|
|
107
|
+
protected after(_event: RelayRoomEvent): void;
|
|
108
|
+
/** To the listeners alone. */
|
|
109
|
+
protected notify(event: RelayRoomEvent): void;
|
|
98
110
|
}
|
|
99
111
|
//# sourceMappingURL=relay-hubs-connection.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RelayHubsConnection = exports.Live = exports.OPEN = exports.READY_MS = void 0;
|
|
4
|
+
const relay_friends_1 = require("./relay-friends");
|
|
4
5
|
const relay_hub_1 = require("./relay-hub");
|
|
5
6
|
const relay_hub_util_1 = require("./relay-hub-util");
|
|
6
7
|
const relay_identity_1 = require("./relay-identity");
|
|
@@ -9,7 +10,6 @@ const relay_protocol_1 = require("./relay-protocol");
|
|
|
9
10
|
const relay_room_chat_1 = require("./relay-room-chat");
|
|
10
11
|
const MAX_RECONNECT_MS = 30000;
|
|
11
12
|
const SKEW_MS = 5 * 60 * 1000;
|
|
12
|
-
const MAX_FRIEND_ROOMS = 8;
|
|
13
13
|
/** How long a call waits for the room to be connected, or for the relay to answer. */
|
|
14
14
|
exports.READY_MS = 15000;
|
|
15
15
|
exports.OPEN = 1;
|
|
@@ -36,7 +36,7 @@ exports.Live = Live;
|
|
|
36
36
|
/**
|
|
37
37
|
* The half of {@link RelayHubs} that keeps a connection to the hub of each room and reads what comes over it:
|
|
38
38
|
* connecting again, the welcome, the roster, the state and the messages, each opened and checked against the
|
|
39
|
-
* signatures of the roster; what is kept of the rooms
|
|
39
|
+
* signatures of the roster; what is kept of the rooms.
|
|
40
40
|
*/
|
|
41
41
|
class RelayHubsConnection {
|
|
42
42
|
constructor(options) {
|
|
@@ -64,6 +64,11 @@ class RelayHubsConnection {
|
|
|
64
64
|
this.own = made;
|
|
65
65
|
return made;
|
|
66
66
|
}
|
|
67
|
+
/** Who this Ta is in a room: the identity it joined with when it took on another since (RelayRoomRecord.identity). */
|
|
68
|
+
async identityOf(live) {
|
|
69
|
+
var _a;
|
|
70
|
+
return (_a = live.record.identity) !== null && _a !== void 0 ? _a : this.identity();
|
|
71
|
+
}
|
|
67
72
|
requestOf(live, ask, friends) {
|
|
68
73
|
return {
|
|
69
74
|
room: live.record.id,
|
|
@@ -99,7 +104,7 @@ class RelayHubsConnection {
|
|
|
99
104
|
}
|
|
100
105
|
async sendBody(live, body, to) {
|
|
101
106
|
await this.ready(live);
|
|
102
|
-
const identity = await this.
|
|
107
|
+
const identity = await this.identityOf(live);
|
|
103
108
|
const d = await relay_hub_util_1.RelayHubUtil.seal(live.keys.seal, identity, live.record.member, body);
|
|
104
109
|
this.request(live, { t: 'send', d, ...(to ? { to } : {}) });
|
|
105
110
|
}
|
|
@@ -107,7 +112,7 @@ class RelayHubsConnection {
|
|
|
107
112
|
async nextRoster(live, change) {
|
|
108
113
|
var _a, _b;
|
|
109
114
|
var _c, _d;
|
|
110
|
-
const identity = await this.
|
|
115
|
+
const identity = await this.identityOf(live);
|
|
111
116
|
const body = { v: ((_c = (_a = live.roster) === null || _a === void 0 ? void 0 : _a.v) !== null && _c !== void 0 ? _c : 0) + 1, members: change((_d = (_b = live.roster) === null || _b === void 0 ? void 0 : _b.members) !== null && _d !== void 0 ? _d : []) };
|
|
112
117
|
const d = await relay_hub_util_1.RelayHubUtil.seal(live.keys.seal, identity, live.record.member, body);
|
|
113
118
|
live.roster = body;
|
|
@@ -172,7 +177,7 @@ class RelayHubsConnection {
|
|
|
172
177
|
ask: record.member,
|
|
173
178
|
token: record.token,
|
|
174
179
|
proof: await relay_hub_util_1.RelayHubUtil.inviteProof(record.invite),
|
|
175
|
-
d: await relay_hub_util_1.RelayHubUtil.sealAsk(record.invite, await this.
|
|
180
|
+
d: await relay_hub_util_1.RelayHubUtil.sealAsk(record.invite, await this.identityOf(live), record.member, Date.now(), !!this.options.guest),
|
|
176
181
|
};
|
|
177
182
|
}
|
|
178
183
|
else {
|
|
@@ -338,7 +343,7 @@ class RelayHubsConnection {
|
|
|
338
343
|
async admitted(live, answer) {
|
|
339
344
|
const { record } = live;
|
|
340
345
|
const opened = record.invite
|
|
341
|
-
? await relay_hub_util_1.RelayHubUtil.openAnswer(await this.
|
|
346
|
+
? await relay_hub_util_1.RelayHubUtil.openAnswer(await this.identityOf(live), record.id, record.member, record.owner.id, answer, record.invite)
|
|
342
347
|
: undefined;
|
|
343
348
|
if (!opened) {
|
|
344
349
|
// Not signed by the owner the link named: whoever answered, it is not that room.
|
|
@@ -348,9 +353,10 @@ class RelayHubsConnection {
|
|
|
348
353
|
live.record = {
|
|
349
354
|
...record,
|
|
350
355
|
key: opened.body.key,
|
|
351
|
-
kind: String(opened.body.kind),
|
|
356
|
+
kind: relay_friends_1.RelayFriendsUtil.kindOf(String(opened.body.kind)),
|
|
352
357
|
title: String(opened.body.title).slice(0, 80),
|
|
353
358
|
...(opened.body.view ? { view: String(opened.body.view) } : {}),
|
|
359
|
+
...(opened.body.unlisted === true ? { unlisted: true } : {}),
|
|
354
360
|
owner: opened.owner,
|
|
355
361
|
status: 'member',
|
|
356
362
|
joinedAt: Date.now(),
|
|
@@ -370,13 +376,21 @@ class RelayHubsConnection {
|
|
|
370
376
|
live.asks.set(ask.member, { body: ask, invite: invite.secret });
|
|
371
377
|
if (fresh || !this.told.has(ask.member)) {
|
|
372
378
|
this.told.add(ask.member);
|
|
373
|
-
this.
|
|
374
|
-
this.emit({ type: 'rooms' });
|
|
379
|
+
this.heardAsk(live, ask);
|
|
375
380
|
}
|
|
376
381
|
return;
|
|
377
382
|
}
|
|
378
383
|
}
|
|
379
384
|
}
|
|
385
|
+
/** One asks to join a room of this Ta, heard the first time. */
|
|
386
|
+
heardAsk(live, ask) {
|
|
387
|
+
this.emit({ type: 'request', request: this.requestOf(live, ask, this.friendIds()) });
|
|
388
|
+
this.emit({ type: 'rooms' });
|
|
389
|
+
}
|
|
390
|
+
/** The members of a roster, read: those of them the user chose as friends are kept up to date. */
|
|
391
|
+
heardMembers(_members) { }
|
|
392
|
+
/** A member asks the user to be friends, by the link of its room of friends. */
|
|
393
|
+
offered(_live, _from, _link) { }
|
|
380
394
|
async readRoster(live, sealed) {
|
|
381
395
|
var _a;
|
|
382
396
|
const owner = live.record.owner;
|
|
@@ -399,8 +413,8 @@ class RelayHubsConnection {
|
|
|
399
413
|
return;
|
|
400
414
|
}
|
|
401
415
|
live.roster = { v: signed.b.v, members };
|
|
402
|
-
const own = (await this.
|
|
403
|
-
this.
|
|
416
|
+
const own = (await this.identityOf(live)).id;
|
|
417
|
+
this.heardMembers(members.filter(member => member.id !== own && !member.guest));
|
|
404
418
|
if (!members.some(member => member.member === live.record.member) && !live.record.own && live.record.status === 'member') {
|
|
405
419
|
this.setStatus(live, 'gone', 'removed');
|
|
406
420
|
}
|
|
@@ -450,6 +464,12 @@ class RelayHubsConnection {
|
|
|
450
464
|
// A guest only chats, in the state: the messages of games are not its.
|
|
451
465
|
return;
|
|
452
466
|
}
|
|
467
|
+
if (typeof signed.b.friend === 'string') {
|
|
468
|
+
if (sender && !sender.guest) {
|
|
469
|
+
this.offered(live, sender, signed.b.friend);
|
|
470
|
+
}
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
453
473
|
if (typeof signed.b.name === 'string') {
|
|
454
474
|
if (live.record.own && sender) {
|
|
455
475
|
const name = signed.b.name.trim().slice(0, 40);
|
|
@@ -459,33 +479,9 @@ class RelayHubsConnection {
|
|
|
459
479
|
}
|
|
460
480
|
this.emit({ type: 'message', room: live.record.id, from, name: (_b = sender === null || sender === void 0 ? void 0 : sender.name) !== null && _b !== void 0 ? _b : '', data: signed.b.d });
|
|
461
481
|
}
|
|
462
|
-
/**
|
|
463
|
-
meet(title, members) {
|
|
464
|
-
if (!members.length) {
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
const friends = this.readFriends();
|
|
468
|
-
const now = Date.now();
|
|
469
|
-
for (const member of members) {
|
|
470
|
-
const known = friends.find(friend => friend.id === member.id);
|
|
471
|
-
if (known) {
|
|
472
|
-
known.name = member.name;
|
|
473
|
-
known.seenAt = now;
|
|
474
|
-
known.rooms = [...known.rooms.filter(room => room !== title), title].slice(-MAX_FRIEND_ROOMS);
|
|
475
|
-
}
|
|
476
|
-
else {
|
|
477
|
-
friends.push({ ...relay_identity_1.RelayIdentityUtil.publicOf(member), rooms: [title], metAt: now, seenAt: now });
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
this.options.store.write('friends', { friends });
|
|
481
|
-
}
|
|
482
|
+
/** Ids of those the user chose as friends. */
|
|
482
483
|
friendIds() {
|
|
483
|
-
return new Set(
|
|
484
|
-
}
|
|
485
|
-
readFriends() {
|
|
486
|
-
var _a;
|
|
487
|
-
const friends = (_a = this.options.store.read('friends')) === null || _a === void 0 ? void 0 : _a.friends;
|
|
488
|
-
return Array.isArray(friends) ? friends : [];
|
|
484
|
+
return new Set();
|
|
489
485
|
}
|
|
490
486
|
readRooms() {
|
|
491
487
|
var _a;
|
|
@@ -495,7 +491,14 @@ class RelayHubsConnection {
|
|
|
495
491
|
save() {
|
|
496
492
|
this.options.store.write('rooms', { rooms: [...this.live.values()].map(live => live.record) });
|
|
497
493
|
}
|
|
494
|
+
/** To the listeners, then what follows from it (RelayHubs: the friends settle). */
|
|
498
495
|
emit(event) {
|
|
496
|
+
this.notify(event);
|
|
497
|
+
this.after(event);
|
|
498
|
+
}
|
|
499
|
+
after(_event) { }
|
|
500
|
+
/** To the listeners alone. */
|
|
501
|
+
notify(event) {
|
|
499
502
|
for (const listener of this.listeners) {
|
|
500
503
|
try {
|
|
501
504
|
listener(event);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RelayPublicIdentity } from './relay-identity';
|
|
1
|
+
import type { RelayIdentity, RelayPublicIdentity } from './relay-identity';
|
|
2
2
|
/** `member` in the room; `waiting` for the owner to answer; `refused` by the owner; `gone`: closed, removed, or the invitation no longer works. */
|
|
3
3
|
export type RelayRoomStatus = 'member' | 'waiting' | 'refused' | 'gone';
|
|
4
4
|
/** A room this Ta is in or asked to join, in `rooms.json` of the agent directory (docs/design/ta-link.md 3.5). */
|
|
@@ -8,6 +8,7 @@ export interface RelayRoomRecord {
|
|
|
8
8
|
kind: string;
|
|
9
9
|
title: string;
|
|
10
10
|
view?: string;
|
|
11
|
+
unlisted?: true;
|
|
11
12
|
/** This Ta's id in the room, and what the relay knows it by. */
|
|
12
13
|
member: string;
|
|
13
14
|
token: string;
|
|
@@ -32,6 +33,23 @@ export interface RelayRoomRecord {
|
|
|
32
33
|
asked?: boolean;
|
|
33
34
|
createdAt: number;
|
|
34
35
|
joinedAt?: number;
|
|
36
|
+
/**
|
|
37
|
+
* The identity this Ta is in the room when it is not the one of identity.json: the one it joined with, kept when
|
|
38
|
+
* this Ta took on the identity of the user's other computer (RelayHubs.importIdentity).
|
|
39
|
+
*/
|
|
40
|
+
identity?: RelayIdentity;
|
|
41
|
+
}
|
|
42
|
+
/** What makes a Ta who it is in rooms, private keys and all: for the user's own computers alone (a move, a shared identity). */
|
|
43
|
+
export interface RelayIdentityBundle {
|
|
44
|
+
identity: RelayIdentity;
|
|
45
|
+
rooms: RelayRoomRecord[];
|
|
46
|
+
friends: RelayFriend[];
|
|
47
|
+
}
|
|
48
|
+
/** What {@link RelayIdentityBundle} did here: whether this Ta took on another identity, the rooms and friends it got. */
|
|
49
|
+
export interface RelayIdentityImport {
|
|
50
|
+
switched: boolean;
|
|
51
|
+
rooms: number;
|
|
52
|
+
friends: number;
|
|
35
53
|
}
|
|
36
54
|
export interface RelayRoomMember {
|
|
37
55
|
member: string;
|
|
@@ -49,6 +67,9 @@ export interface RelayRoomInfo {
|
|
|
49
67
|
kind: string;
|
|
50
68
|
title: string;
|
|
51
69
|
view?: string;
|
|
70
|
+
unlisted?: true;
|
|
71
|
+
/** The relay it is on. */
|
|
72
|
+
relay: string;
|
|
52
73
|
owner: boolean;
|
|
53
74
|
ownerName: string;
|
|
54
75
|
status: RelayRoomStatus;
|
|
@@ -73,13 +94,31 @@ export interface RelayRoomRequest {
|
|
|
73
94
|
guest?: boolean;
|
|
74
95
|
at: number;
|
|
75
96
|
}
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
97
|
+
/**
|
|
98
|
+
* One the user chose as a friend (docs/design/ta-link.md 3.1), in `friends.json`: its keys once known (from its link
|
|
99
|
+
* only its id and name), when chosen and last heard of.
|
|
100
|
+
*/
|
|
101
|
+
export interface RelayFriend extends Pick<RelayPublicIdentity, 'id' | 'name'>, Partial<Pick<RelayPublicIdentity, 'sign' | 'box'>> {
|
|
102
|
+
metAt: number;
|
|
103
|
+
seenAt: number;
|
|
104
|
+
}
|
|
105
|
+
/** A friend as the pages show it: `friend` once each is in the room of the other, `adding` till then. */
|
|
106
|
+
export interface RelayFriendInfo {
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
status: 'friend' | 'adding';
|
|
110
|
+
online: boolean;
|
|
80
111
|
metAt: number;
|
|
81
112
|
seenAt: number;
|
|
82
113
|
}
|
|
114
|
+
/** One asking the user to be friends: by the link of the user's room of friends, or in a room the two share (its title). */
|
|
115
|
+
export interface RelayFriendRequest {
|
|
116
|
+
id: string;
|
|
117
|
+
name: string;
|
|
118
|
+
at: number;
|
|
119
|
+
via: 'link' | 'room';
|
|
120
|
+
room?: string;
|
|
121
|
+
}
|
|
83
122
|
export interface RelayRoomValue {
|
|
84
123
|
value: unknown;
|
|
85
124
|
version: number;
|
|
@@ -91,6 +130,11 @@ export type RelayRoomEvent = {
|
|
|
91
130
|
} | {
|
|
92
131
|
type: 'request';
|
|
93
132
|
request: RelayRoomRequest;
|
|
133
|
+
}
|
|
134
|
+
/** One asks the user to be friends. */
|
|
135
|
+
| {
|
|
136
|
+
type: 'friend';
|
|
137
|
+
request: RelayFriendRequest;
|
|
94
138
|
} | {
|
|
95
139
|
type: 'message';
|
|
96
140
|
room: string;
|
|
@@ -122,8 +166,8 @@ export interface RelayHubsOptions {
|
|
|
122
166
|
* others hear only what it says (`chat:` of the state), not its messages or the rest of the state.
|
|
123
167
|
*/
|
|
124
168
|
guest?: boolean;
|
|
125
|
-
/** The relay new rooms are made on. */
|
|
126
|
-
relay(): string;
|
|
169
|
+
/** The relay new rooms are made on; `use` the feature a room is for (relays.json), `rooms` when none is said. */
|
|
170
|
+
relay(use?: string): string;
|
|
127
171
|
/** First wait before connecting again; it doubles up to 30 seconds. */
|
|
128
172
|
reconnectDelayMs?: number;
|
|
129
173
|
pingMs?: number;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { RelayFriends } from './relay-friends';
|
|
2
|
+
import { type RelayHubAskBody } from './relay-hub-util';
|
|
1
3
|
import { Live, RelayHubsConnection } from './relay-hubs-connection';
|
|
2
|
-
import type { RelayFriend, RelayRoomEvent, RelayRoomInfo, RelayRoomRequest, RelayRoomValue } from './relay-hubs-protocol';
|
|
3
|
-
import { type RelayPublicIdentity } from './relay-identity';
|
|
4
|
+
import type { RelayFriend, RelayFriendInfo, RelayFriendRequest, RelayIdentityBundle, RelayIdentityImport, RelayRoomEvent, RelayRoomInfo, RelayRoomRecord, RelayRoomRequest, RelayRoomValue } from './relay-hubs-protocol';
|
|
5
|
+
import { type RelayIdentity, type RelayPublicIdentity } from './relay-identity';
|
|
4
6
|
/**
|
|
5
7
|
* The rooms of this Ta (docs/design/ta-link.md 3): its identity and friends, the rooms it made or asked to join,
|
|
6
8
|
* and a connection to the hub of each while it runs, through which it sends, sets the shared state and hears
|
|
7
|
-
* the others; every message signed by its member and sealed with the key of the room.
|
|
9
|
+
* the others; every message signed by its member and sealed with the key of the room. The friends are a room of
|
|
10
|
+
* their own (RelayFriends).
|
|
8
11
|
*/
|
|
9
12
|
export declare class RelayHubs extends RelayHubsConnection {
|
|
13
|
+
protected readonly book: RelayFriends;
|
|
10
14
|
/** Connects to the rooms of rooms.json, and keeps connected. */
|
|
11
15
|
start(): void;
|
|
12
16
|
stop(): void;
|
|
@@ -19,6 +23,8 @@ export declare class RelayHubs extends RelayHubsConnection {
|
|
|
19
23
|
kind: string;
|
|
20
24
|
title: string;
|
|
21
25
|
view?: string;
|
|
26
|
+
unlisted?: boolean;
|
|
27
|
+
use?: string;
|
|
22
28
|
}): Promise<RelayRoomInfo>;
|
|
23
29
|
/**
|
|
24
30
|
* The link that lets others ask to join: the one of before while it has a day left, else (or with `renew`) a new
|
|
@@ -53,10 +59,66 @@ export declare class RelayHubs extends RelayHubsConnection {
|
|
|
53
59
|
ok: boolean;
|
|
54
60
|
version: number;
|
|
55
61
|
}>;
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
/** What makes this Ta who it is in rooms, private keys and all (RelayIdentityBundle): for the user's own computers alone. */
|
|
63
|
+
exportIdentity(): Promise<RelayIdentityBundle>;
|
|
64
|
+
/**
|
|
65
|
+
* Takes on the identity of the user's other computer, with its rooms and friends (a move, or the identity shared by
|
|
66
|
+
* sync). Another identity than this Ta's: each room this Ta is in keeps the identity it joined with
|
|
67
|
+
* (RelayRoomRecord.identity), new rooms are the other's. A room this Ta is in as another member is left as it is.
|
|
68
|
+
*/
|
|
69
|
+
importIdentity(bundle: RelayIdentityBundle, options?: {
|
|
70
|
+
shared?: boolean;
|
|
71
|
+
}): Promise<RelayIdentityImport>;
|
|
72
|
+
/** Whether the user's other computers are this Ta too (RelayIdentity.shared). */
|
|
73
|
+
setShared(shared: boolean): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* A room as the user's other computer has it: added, or merged with this Ta's record of the same membership
|
|
76
|
+
* (RelayHubsUtil.merge), connected or not as its status says. False when nothing changed, or this Ta is in the room
|
|
77
|
+
* as another member.
|
|
78
|
+
*/
|
|
79
|
+
upsert(record: RelayRoomRecord): boolean;
|
|
80
|
+
/** A room the user's other computer left or forgot: forgotten here, without a word to the relay (that computer said it). */
|
|
81
|
+
forget(roomId: string, member: string): boolean;
|
|
82
|
+
/** Friends of the user's other computer, with those of this Ta. */
|
|
83
|
+
mergeFriends(friends: RelayFriend[]): number;
|
|
84
|
+
/** The friends, with their keys: each in the room of the other (shares to friends are sealed for them). */
|
|
85
|
+
friends(): (RelayFriend & RelayPublicIdentity)[];
|
|
86
|
+
/** The friends and those being added, for the pages. */
|
|
87
|
+
listFriends(): RelayFriendInfo[];
|
|
88
|
+
/** The room of friends of this Ta, made the first time: other features keep there what they give friends. */
|
|
89
|
+
friendRoom(): Promise<RelayRoomInfo>;
|
|
90
|
+
/** The link (and code) that asks to be the user's friend; with `renew`, a new one, the one before no longer working. */
|
|
91
|
+
friendLink(renew?: boolean): Promise<{
|
|
92
|
+
link: string;
|
|
93
|
+
expiresAt: number;
|
|
94
|
+
}>;
|
|
95
|
+
/** Asks the one of a link to be friends, on the user's word. */
|
|
96
|
+
addFriend(link: string): Promise<void>;
|
|
97
|
+
/** Asks a member of a room the user is in to be friends. */
|
|
98
|
+
offerFriend(roomId: string, member: string): Promise<void>;
|
|
99
|
+
friendRequests(): RelayFriendRequest[];
|
|
100
|
+
/** The user's answer to one asking to be friends. */
|
|
101
|
+
answerFriend(id: string, accept: boolean): Promise<void>;
|
|
102
|
+
/** No longer friends, on both sides. */
|
|
103
|
+
removeFriend(id: string): Promise<boolean>;
|
|
104
|
+
protected isFriends(live: Live): boolean;
|
|
105
|
+
protected friendIds(): Set<string>;
|
|
106
|
+
protected heardAsk(live: Live, ask: RelayHubAskBody): void;
|
|
107
|
+
protected heardMembers(members: RelayPublicIdentity[]): void;
|
|
108
|
+
protected offered(live: Live, from: RelayPublicIdentity, link: string): void;
|
|
109
|
+
/** What changes the friends: rooms coming and going, members, the links friends leave to join back. */
|
|
110
|
+
protected after(event: RelayRoomEvent): void;
|
|
58
111
|
protected owned(roomId: string): Live;
|
|
59
112
|
protected member(roomId: string): Live;
|
|
60
113
|
protected info(live: Live): RelayRoomInfo;
|
|
61
114
|
}
|
|
115
|
+
export declare namespace RelayHubsUtil {
|
|
116
|
+
function isPrivate(identity: unknown): identity is RelayIdentity;
|
|
117
|
+
function isRecord(record: unknown): record is RelayRoomRecord;
|
|
118
|
+
/**
|
|
119
|
+
* Two records of one membership, as two computers of the user hold it: the further status (one heard it end), the
|
|
120
|
+
* key and the owner's keys once either has them, the invitations of both, made once either made it.
|
|
121
|
+
*/
|
|
122
|
+
function merge(local: RelayRoomRecord, other: RelayRoomRecord): RelayRoomRecord;
|
|
123
|
+
}
|
|
62
124
|
//# sourceMappingURL=relay-hubs.d.ts.map
|