@celljs/ta-relay 4.19.0 → 4.20.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/relay-hubs-connection.d.ts +2 -0
- package/esm/common/relay-hubs-connection.js +3 -0
- package/esm/common/relay-hubs-identity.d.ts +24 -2
- package/esm/common/relay-hubs-identity.js +81 -0
- package/esm/common/relay-identity.d.ts +7 -0
- package/esm/common/relay-identity.js +8 -0
- package/esm/common/relay-protocol.d.ts +7 -0
- package/esm/common/relay-protocol.js +7 -0
- package/lib/common/relay-hubs-connection.d.ts +2 -0
- package/lib/common/relay-hubs-connection.js +3 -0
- package/lib/common/relay-hubs-identity.d.ts +24 -2
- package/lib/common/relay-hubs-identity.js +81 -0
- package/lib/common/relay-identity.d.ts +7 -0
- package/lib/common/relay-identity.js +8 -0
- package/lib/common/relay-protocol.d.ts +7 -0
- package/lib/common/relay-protocol.js +8 -1
- package/package.json +3 -3
- package/viewer/join.html +6 -6
- package/viewer/page.html +12 -12
- package/viewer/room.html +13 -13
|
@@ -97,6 +97,8 @@ export declare abstract class RelayHubsConnection {
|
|
|
97
97
|
/** A member asks the user to be friends, by the link of its room of friends. */
|
|
98
98
|
protected offered(_live: Live, _from: RelayPublicIdentity, _link: string): void;
|
|
99
99
|
protected readRoster(live: Live, sealed: string): Promise<void>;
|
|
100
|
+
/** The state of the room has this Ta's picture as it is now (RelayHubs). */
|
|
101
|
+
protected keepPicture(_live: Live): Promise<void>;
|
|
100
102
|
/**
|
|
101
103
|
* The roster says this Ta as it is now: its look, set while the room was away or the owner offline. The owner writes it,
|
|
102
104
|
* a member tells the owner, once a connection. A room joined with another identity keeps that one's.
|
|
@@ -418,7 +418,10 @@ export class RelayHubsConnection {
|
|
|
418
418
|
}
|
|
419
419
|
// Not awaited: what it sends waits for the room to be ready, which may wait for this event.
|
|
420
420
|
void this.keepLook(live);
|
|
421
|
+
void this.keepPicture(live).catch(() => undefined);
|
|
421
422
|
}
|
|
423
|
+
/** The state of the room has this Ta's picture as it is now (RelayHubs). */
|
|
424
|
+
async keepPicture(_live) { }
|
|
422
425
|
/**
|
|
423
426
|
* The roster says this Ta as it is now: its look, set while the room was away or the owner offline. The owner writes it,
|
|
424
427
|
* a member tells the owner, once a connection. A room joined with another identity keeps that one's.
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { RelayHubsConnection } from './relay-hubs-connection.js';
|
|
1
|
+
import { type RelayFriends } from './relay-friends.js';
|
|
2
|
+
import { Live, RelayHubsConnection } from './relay-hubs-connection.js';
|
|
3
3
|
import type { RelayIdentityBundle, RelayIdentityImport, RelayRoomRecord } from './relay-hubs-protocol.js';
|
|
4
4
|
import { type RelayIdentity, type RelayPublicIdentity } from './relay-identity.js';
|
|
5
5
|
export declare abstract class RelayHubsIdentity extends RelayHubsConnection {
|
|
6
6
|
protected abstract readonly book: RelayFriends;
|
|
7
|
+
abstract setState(roomId: string, key: string, value: unknown, version?: number): Promise<{
|
|
8
|
+
ok: boolean;
|
|
9
|
+
version: number;
|
|
10
|
+
}>;
|
|
7
11
|
/** The name others see; the owners of rooms this Ta is in hear it. */
|
|
8
12
|
setName(name: string): Promise<RelayPublicIdentity>;
|
|
9
13
|
/**
|
|
@@ -11,6 +15,24 @@ export declare abstract class RelayHubsIdentity extends RelayHubsConnection {
|
|
|
11
15
|
* look that is none. The owners of rooms this Ta is in hear it, as a name.
|
|
12
16
|
*/
|
|
13
17
|
setLook(look: string | undefined): Promise<RelayPublicIdentity>;
|
|
18
|
+
/**
|
|
19
|
+
* The picture others see of the user (RelayIdentity.picture), or with null none, the dinosaur of the look again: put
|
|
20
|
+
* in the rooms this Ta is in now, and in those it connects to later.
|
|
21
|
+
*/
|
|
22
|
+
setPicture(picture: string | null): Promise<RelayIdentity>;
|
|
23
|
+
/**
|
|
24
|
+
* Puts this Ta's picture (RelayIdentity.picture) in the state of a room it is in, or clears it there, once the room is
|
|
25
|
+
* ready: in a room of friends only its own, where its friends read it; not in a room joined with another identity.
|
|
26
|
+
*/
|
|
27
|
+
protected keepPicture(live: Live): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* The pictures of the Ta this one knows from its rooms, by the id of each (RelayIdentity.picture), its own among them:
|
|
30
|
+
* what each member put in a room under its member id, the one a Ta put in a room it owns (its room of friends) first.
|
|
31
|
+
*/
|
|
32
|
+
pictures(): Promise<{
|
|
33
|
+
self: string;
|
|
34
|
+
pictures: Record<string, string>;
|
|
35
|
+
}>;
|
|
14
36
|
/** Keeps the identity with a new name or look, and tells the rooms this Ta is in. */
|
|
15
37
|
protected changeSelf(identity: RelayIdentity): Promise<RelayPublicIdentity>;
|
|
16
38
|
/** What makes this Ta who it is in rooms, private keys and all (RelayIdentityBundle): for the user's own computers alone. */
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { RelayFriendsUtil } from './relay-friends.js';
|
|
1
2
|
import { Live, RelayHubsConnection } from './relay-hubs-connection.js';
|
|
2
3
|
import { RelayHubsUtil } from './relay-hubs-util.js';
|
|
3
4
|
import { RelayIdentityUtil } from './relay-identity.js';
|
|
5
|
+
import { RELAY_PICTURE_KEY } from './relay-protocol.js';
|
|
4
6
|
export class RelayHubsIdentity extends RelayHubsConnection {
|
|
5
7
|
/** The name others see; the owners of rooms this Ta is in hear it. */
|
|
6
8
|
async setName(name) {
|
|
@@ -19,6 +21,85 @@ export class RelayHubsIdentity extends RelayHubsConnection {
|
|
|
19
21
|
const next = RelayIdentityUtil.withLook(identity, look);
|
|
20
22
|
return next.look === identity.look ? RelayIdentityUtil.publicOf(identity) : this.changeSelf(next);
|
|
21
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* The picture others see of the user (RelayIdentity.picture), or with null none, the dinosaur of the look again: put
|
|
26
|
+
* in the rooms this Ta is in now, and in those it connects to later.
|
|
27
|
+
*/
|
|
28
|
+
async setPicture(picture) {
|
|
29
|
+
var _a;
|
|
30
|
+
if (picture !== null && !RelayIdentityUtil.isPicture(picture)) {
|
|
31
|
+
throw new Error('A picture is a data URL of a PNG, JPEG, WebP or SVG, of 16 KB at most.');
|
|
32
|
+
}
|
|
33
|
+
const identity = { ...(await this.identity()) };
|
|
34
|
+
if (((_a = identity.picture) !== null && _a !== void 0 ? _a : null) !== picture) {
|
|
35
|
+
if (picture === null) {
|
|
36
|
+
delete identity.picture;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
identity.picture = picture;
|
|
40
|
+
}
|
|
41
|
+
this.options.store.write('identity', identity);
|
|
42
|
+
this.own = identity;
|
|
43
|
+
// The pages draw the user by it, and read it again.
|
|
44
|
+
this.emit({ type: 'rooms' });
|
|
45
|
+
}
|
|
46
|
+
for (const live of this.live.values()) {
|
|
47
|
+
void this.keepPicture(live).catch(() => undefined);
|
|
48
|
+
}
|
|
49
|
+
return identity;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Puts this Ta's picture (RelayIdentity.picture) in the state of a room it is in, or clears it there, once the room is
|
|
53
|
+
* ready: in a room of friends only its own, where its friends read it; not in a room joined with another identity.
|
|
54
|
+
*/
|
|
55
|
+
async keepPicture(live) {
|
|
56
|
+
var _a, _b, _c;
|
|
57
|
+
const { record } = live;
|
|
58
|
+
if (record.status !== 'member' || record.identity || (RelayFriendsUtil.isKind(record.kind) && !record.own)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
await this.ready(live);
|
|
62
|
+
const picture = (_a = (await this.identity()).picture) !== null && _a !== void 0 ? _a : null;
|
|
63
|
+
const key = RELAY_PICTURE_KEY + record.member;
|
|
64
|
+
const kept = live.state.get(key);
|
|
65
|
+
if (live.record.status !== 'member' || ((_b = kept === null || kept === void 0 ? void 0 : kept.value) !== null && _b !== void 0 ? _b : null) === picture) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
await this.setState(record.id, key, picture, (_c = kept === null || kept === void 0 ? void 0 : kept.version) !== null && _c !== void 0 ? _c : 0);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The pictures of the Ta this one knows from its rooms, by the id of each (RelayIdentity.picture), its own among them:
|
|
72
|
+
* what each member put in a room under its member id, the one a Ta put in a room it owns (its room of friends) first.
|
|
73
|
+
*/
|
|
74
|
+
async pictures() {
|
|
75
|
+
const own = await this.identity();
|
|
76
|
+
const pictures = {};
|
|
77
|
+
const owned = new Set();
|
|
78
|
+
for (const live of this.live.values()) {
|
|
79
|
+
if (live.record.status !== 'member' || !live.roster) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
for (const member of live.roster.members) {
|
|
83
|
+
const kept = live.state.get(RELAY_PICTURE_KEY + member.member);
|
|
84
|
+
if (member.guest || (kept === null || kept === void 0 ? void 0 : kept.by) !== member.member || !RelayIdentityUtil.isPicture(kept.value) || owned.has(member.id)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!(member.id in pictures) || member.owner) {
|
|
88
|
+
pictures[member.id] = kept.value;
|
|
89
|
+
}
|
|
90
|
+
if (member.owner) {
|
|
91
|
+
owned.add(member.id);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (own.picture) {
|
|
96
|
+
pictures[own.id] = own.picture;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
delete pictures[own.id];
|
|
100
|
+
}
|
|
101
|
+
return { self: own.id, pictures };
|
|
102
|
+
}
|
|
22
103
|
/** Keeps the identity with a new name or look, and tells the rooms this Ta is in. */
|
|
23
104
|
async changeSelf(identity) {
|
|
24
105
|
var _a;
|
|
@@ -20,6 +20,11 @@ export interface RelayIdentity extends RelayPublicIdentity {
|
|
|
20
20
|
createdAt: number;
|
|
21
21
|
/** The user's other computers are this Ta too: who answers in a room is agreed first (docs/design/ta-sync.md 9). */
|
|
22
22
|
shared?: true;
|
|
23
|
+
/**
|
|
24
|
+
* The picture others see of the user (RelayIdentityUtil.isPicture), instead of the dinosaur of the look: kept in the
|
|
25
|
+
* state of the rooms this Ta is in (RELAY_PICTURE_KEY), never in what others are given of the identity.
|
|
26
|
+
*/
|
|
27
|
+
picture?: string;
|
|
23
28
|
}
|
|
24
29
|
/** Keys, sealing and signatures of rooms and identities, with WebCrypto only: the same in ta serve, a browser and a Worker. */
|
|
25
30
|
export declare namespace RelayKeys {
|
|
@@ -44,6 +49,8 @@ export declare namespace RelayIdentityUtil {
|
|
|
44
49
|
function publicOf(identity: RelayPublicIdentity): RelayPublicIdentity;
|
|
45
50
|
/** Whether it is a look as a Ta gives it: a short word of letters, digits and dashes. */
|
|
46
51
|
function isLook(look: unknown): look is string;
|
|
52
|
+
/** Whether it is a picture as a Ta keeps it: a data URL of a PNG, JPEG, WebP or SVG, small. */
|
|
53
|
+
function isPicture(picture: unknown): picture is string;
|
|
47
54
|
/** `value` with `look`, or without any for one that is none. */
|
|
48
55
|
function withLook<T extends {
|
|
49
56
|
look?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RelayBytes } from './relay-bytes.js';
|
|
2
|
+
import { RELAY_PICTURE_MAX_CHARS } from './relay-protocol.js';
|
|
2
3
|
const encoder = new TextEncoder();
|
|
3
4
|
const decoder = new TextDecoder();
|
|
4
5
|
const subtle = () => globalThis.crypto.subtle;
|
|
@@ -96,6 +97,13 @@ export var RelayIdentityUtil;
|
|
|
96
97
|
return typeof look === 'string' && /^[a-z][a-z0-9-]{0,31}$/.test(look);
|
|
97
98
|
}
|
|
98
99
|
RelayIdentityUtil.isLook = isLook;
|
|
100
|
+
/** Whether it is a picture as a Ta keeps it: a data URL of a PNG, JPEG, WebP or SVG, small. */
|
|
101
|
+
function isPicture(picture) {
|
|
102
|
+
return (typeof picture === 'string' &&
|
|
103
|
+
picture.length <= RELAY_PICTURE_MAX_CHARS &&
|
|
104
|
+
/^data:image\/(png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/.test(picture));
|
|
105
|
+
}
|
|
106
|
+
RelayIdentityUtil.isPicture = isPicture;
|
|
99
107
|
/** `value` with `look`, or without any for one that is none. */
|
|
100
108
|
function withLook(value, look) {
|
|
101
109
|
const { look: _, ...rest } = value;
|
|
@@ -188,6 +188,13 @@ export declare const RELAY_HUB_MAX_KEYS = 4096;
|
|
|
188
188
|
export declare const RELAY_HUB_MAX_STATE: number;
|
|
189
189
|
/** Asks to join waiting for the owner, and for how long. */
|
|
190
190
|
export declare const RELAY_HUB_MAX_ASKS = 20;
|
|
191
|
+
/**
|
|
192
|
+
* The key of the state of a room a member keeps its picture under (RelayIdentity.picture), its member id after it: each
|
|
193
|
+
* member its own, in the rooms of friends the owner alone (RelayHubs.keepPicture).
|
|
194
|
+
*/
|
|
195
|
+
export declare const RELAY_PICTURE_KEY = "picture:";
|
|
196
|
+
/** Characters of a picture at most, as a data URL: a small square, a few of them in a room. */
|
|
197
|
+
export declare const RELAY_PICTURE_MAX_CHARS: number;
|
|
191
198
|
export declare const RELAY_HUB_ASK_DAYS = 7;
|
|
192
199
|
/** A room nobody used for so long is deleted. */
|
|
193
200
|
export declare const RELAY_HUB_IDLE_DAYS = 90;
|
|
@@ -121,6 +121,13 @@ export const RELAY_HUB_MAX_KEYS = 4096;
|
|
|
121
121
|
export const RELAY_HUB_MAX_STATE = 3 * 1024 * 1024;
|
|
122
122
|
/** Asks to join waiting for the owner, and for how long. */
|
|
123
123
|
export const RELAY_HUB_MAX_ASKS = 20;
|
|
124
|
+
/**
|
|
125
|
+
* The key of the state of a room a member keeps its picture under (RelayIdentity.picture), its member id after it: each
|
|
126
|
+
* member its own, in the rooms of friends the owner alone (RelayHubs.keepPicture).
|
|
127
|
+
*/
|
|
128
|
+
export const RELAY_PICTURE_KEY = 'picture:';
|
|
129
|
+
/** Characters of a picture at most, as a data URL: a small square, a few of them in a room. */
|
|
130
|
+
export const RELAY_PICTURE_MAX_CHARS = 16 * 1024;
|
|
124
131
|
export const RELAY_HUB_ASK_DAYS = 7;
|
|
125
132
|
/** A room nobody used for so long is deleted. */
|
|
126
133
|
export const RELAY_HUB_IDLE_DAYS = 90;
|
|
@@ -97,6 +97,8 @@ export declare abstract class RelayHubsConnection {
|
|
|
97
97
|
/** A member asks the user to be friends, by the link of its room of friends. */
|
|
98
98
|
protected offered(_live: Live, _from: RelayPublicIdentity, _link: string): void;
|
|
99
99
|
protected readRoster(live: Live, sealed: string): Promise<void>;
|
|
100
|
+
/** The state of the room has this Ta's picture as it is now (RelayHubs). */
|
|
101
|
+
protected keepPicture(_live: Live): Promise<void>;
|
|
100
102
|
/**
|
|
101
103
|
* The roster says this Ta as it is now: its look, set while the room was away or the owner offline. The owner writes it,
|
|
102
104
|
* a member tells the owner, once a connection. A room joined with another identity keeps that one's.
|
|
@@ -422,7 +422,10 @@ class RelayHubsConnection {
|
|
|
422
422
|
}
|
|
423
423
|
// Not awaited: what it sends waits for the room to be ready, which may wait for this event.
|
|
424
424
|
void this.keepLook(live);
|
|
425
|
+
void this.keepPicture(live).catch(() => undefined);
|
|
425
426
|
}
|
|
427
|
+
/** The state of the room has this Ta's picture as it is now (RelayHubs). */
|
|
428
|
+
async keepPicture(_live) { }
|
|
426
429
|
/**
|
|
427
430
|
* The roster says this Ta as it is now: its look, set while the room was away or the owner offline. The owner writes it,
|
|
428
431
|
* a member tells the owner, once a connection. A room joined with another identity keeps that one's.
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { RelayHubsConnection } from './relay-hubs-connection';
|
|
1
|
+
import { type RelayFriends } from './relay-friends';
|
|
2
|
+
import { Live, RelayHubsConnection } from './relay-hubs-connection';
|
|
3
3
|
import type { RelayIdentityBundle, RelayIdentityImport, RelayRoomRecord } from './relay-hubs-protocol';
|
|
4
4
|
import { type RelayIdentity, type RelayPublicIdentity } from './relay-identity';
|
|
5
5
|
export declare abstract class RelayHubsIdentity extends RelayHubsConnection {
|
|
6
6
|
protected abstract readonly book: RelayFriends;
|
|
7
|
+
abstract setState(roomId: string, key: string, value: unknown, version?: number): Promise<{
|
|
8
|
+
ok: boolean;
|
|
9
|
+
version: number;
|
|
10
|
+
}>;
|
|
7
11
|
/** The name others see; the owners of rooms this Ta is in hear it. */
|
|
8
12
|
setName(name: string): Promise<RelayPublicIdentity>;
|
|
9
13
|
/**
|
|
@@ -11,6 +15,24 @@ export declare abstract class RelayHubsIdentity extends RelayHubsConnection {
|
|
|
11
15
|
* look that is none. The owners of rooms this Ta is in hear it, as a name.
|
|
12
16
|
*/
|
|
13
17
|
setLook(look: string | undefined): Promise<RelayPublicIdentity>;
|
|
18
|
+
/**
|
|
19
|
+
* The picture others see of the user (RelayIdentity.picture), or with null none, the dinosaur of the look again: put
|
|
20
|
+
* in the rooms this Ta is in now, and in those it connects to later.
|
|
21
|
+
*/
|
|
22
|
+
setPicture(picture: string | null): Promise<RelayIdentity>;
|
|
23
|
+
/**
|
|
24
|
+
* Puts this Ta's picture (RelayIdentity.picture) in the state of a room it is in, or clears it there, once the room is
|
|
25
|
+
* ready: in a room of friends only its own, where its friends read it; not in a room joined with another identity.
|
|
26
|
+
*/
|
|
27
|
+
protected keepPicture(live: Live): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* The pictures of the Ta this one knows from its rooms, by the id of each (RelayIdentity.picture), its own among them:
|
|
30
|
+
* what each member put in a room under its member id, the one a Ta put in a room it owns (its room of friends) first.
|
|
31
|
+
*/
|
|
32
|
+
pictures(): Promise<{
|
|
33
|
+
self: string;
|
|
34
|
+
pictures: Record<string, string>;
|
|
35
|
+
}>;
|
|
14
36
|
/** Keeps the identity with a new name or look, and tells the rooms this Ta is in. */
|
|
15
37
|
protected changeSelf(identity: RelayIdentity): Promise<RelayPublicIdentity>;
|
|
16
38
|
/** What makes this Ta who it is in rooms, private keys and all (RelayIdentityBundle): for the user's own computers alone. */
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RelayHubsIdentity = void 0;
|
|
4
|
+
const relay_friends_1 = require("./relay-friends");
|
|
4
5
|
const relay_hubs_connection_1 = require("./relay-hubs-connection");
|
|
5
6
|
const relay_hubs_util_1 = require("./relay-hubs-util");
|
|
6
7
|
const relay_identity_1 = require("./relay-identity");
|
|
8
|
+
const relay_protocol_1 = require("./relay-protocol");
|
|
7
9
|
class RelayHubsIdentity extends relay_hubs_connection_1.RelayHubsConnection {
|
|
8
10
|
/** The name others see; the owners of rooms this Ta is in hear it. */
|
|
9
11
|
async setName(name) {
|
|
@@ -22,6 +24,85 @@ class RelayHubsIdentity extends relay_hubs_connection_1.RelayHubsConnection {
|
|
|
22
24
|
const next = relay_identity_1.RelayIdentityUtil.withLook(identity, look);
|
|
23
25
|
return next.look === identity.look ? relay_identity_1.RelayIdentityUtil.publicOf(identity) : this.changeSelf(next);
|
|
24
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* The picture others see of the user (RelayIdentity.picture), or with null none, the dinosaur of the look again: put
|
|
29
|
+
* in the rooms this Ta is in now, and in those it connects to later.
|
|
30
|
+
*/
|
|
31
|
+
async setPicture(picture) {
|
|
32
|
+
var _a;
|
|
33
|
+
if (picture !== null && !relay_identity_1.RelayIdentityUtil.isPicture(picture)) {
|
|
34
|
+
throw new Error('A picture is a data URL of a PNG, JPEG, WebP or SVG, of 16 KB at most.');
|
|
35
|
+
}
|
|
36
|
+
const identity = { ...(await this.identity()) };
|
|
37
|
+
if (((_a = identity.picture) !== null && _a !== void 0 ? _a : null) !== picture) {
|
|
38
|
+
if (picture === null) {
|
|
39
|
+
delete identity.picture;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
identity.picture = picture;
|
|
43
|
+
}
|
|
44
|
+
this.options.store.write('identity', identity);
|
|
45
|
+
this.own = identity;
|
|
46
|
+
// The pages draw the user by it, and read it again.
|
|
47
|
+
this.emit({ type: 'rooms' });
|
|
48
|
+
}
|
|
49
|
+
for (const live of this.live.values()) {
|
|
50
|
+
void this.keepPicture(live).catch(() => undefined);
|
|
51
|
+
}
|
|
52
|
+
return identity;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Puts this Ta's picture (RelayIdentity.picture) in the state of a room it is in, or clears it there, once the room is
|
|
56
|
+
* ready: in a room of friends only its own, where its friends read it; not in a room joined with another identity.
|
|
57
|
+
*/
|
|
58
|
+
async keepPicture(live) {
|
|
59
|
+
var _a, _b, _c;
|
|
60
|
+
const { record } = live;
|
|
61
|
+
if (record.status !== 'member' || record.identity || (relay_friends_1.RelayFriendsUtil.isKind(record.kind) && !record.own)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
await this.ready(live);
|
|
65
|
+
const picture = (_a = (await this.identity()).picture) !== null && _a !== void 0 ? _a : null;
|
|
66
|
+
const key = relay_protocol_1.RELAY_PICTURE_KEY + record.member;
|
|
67
|
+
const kept = live.state.get(key);
|
|
68
|
+
if (live.record.status !== 'member' || ((_b = kept === null || kept === void 0 ? void 0 : kept.value) !== null && _b !== void 0 ? _b : null) === picture) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
await this.setState(record.id, key, picture, (_c = kept === null || kept === void 0 ? void 0 : kept.version) !== null && _c !== void 0 ? _c : 0);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The pictures of the Ta this one knows from its rooms, by the id of each (RelayIdentity.picture), its own among them:
|
|
75
|
+
* what each member put in a room under its member id, the one a Ta put in a room it owns (its room of friends) first.
|
|
76
|
+
*/
|
|
77
|
+
async pictures() {
|
|
78
|
+
const own = await this.identity();
|
|
79
|
+
const pictures = {};
|
|
80
|
+
const owned = new Set();
|
|
81
|
+
for (const live of this.live.values()) {
|
|
82
|
+
if (live.record.status !== 'member' || !live.roster) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
for (const member of live.roster.members) {
|
|
86
|
+
const kept = live.state.get(relay_protocol_1.RELAY_PICTURE_KEY + member.member);
|
|
87
|
+
if (member.guest || (kept === null || kept === void 0 ? void 0 : kept.by) !== member.member || !relay_identity_1.RelayIdentityUtil.isPicture(kept.value) || owned.has(member.id)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (!(member.id in pictures) || member.owner) {
|
|
91
|
+
pictures[member.id] = kept.value;
|
|
92
|
+
}
|
|
93
|
+
if (member.owner) {
|
|
94
|
+
owned.add(member.id);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (own.picture) {
|
|
99
|
+
pictures[own.id] = own.picture;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
delete pictures[own.id];
|
|
103
|
+
}
|
|
104
|
+
return { self: own.id, pictures };
|
|
105
|
+
}
|
|
25
106
|
/** Keeps the identity with a new name or look, and tells the rooms this Ta is in. */
|
|
26
107
|
async changeSelf(identity) {
|
|
27
108
|
var _a;
|
|
@@ -20,6 +20,11 @@ export interface RelayIdentity extends RelayPublicIdentity {
|
|
|
20
20
|
createdAt: number;
|
|
21
21
|
/** The user's other computers are this Ta too: who answers in a room is agreed first (docs/design/ta-sync.md 9). */
|
|
22
22
|
shared?: true;
|
|
23
|
+
/**
|
|
24
|
+
* The picture others see of the user (RelayIdentityUtil.isPicture), instead of the dinosaur of the look: kept in the
|
|
25
|
+
* state of the rooms this Ta is in (RELAY_PICTURE_KEY), never in what others are given of the identity.
|
|
26
|
+
*/
|
|
27
|
+
picture?: string;
|
|
23
28
|
}
|
|
24
29
|
/** Keys, sealing and signatures of rooms and identities, with WebCrypto only: the same in ta serve, a browser and a Worker. */
|
|
25
30
|
export declare namespace RelayKeys {
|
|
@@ -44,6 +49,8 @@ export declare namespace RelayIdentityUtil {
|
|
|
44
49
|
function publicOf(identity: RelayPublicIdentity): RelayPublicIdentity;
|
|
45
50
|
/** Whether it is a look as a Ta gives it: a short word of letters, digits and dashes. */
|
|
46
51
|
function isLook(look: unknown): look is string;
|
|
52
|
+
/** Whether it is a picture as a Ta keeps it: a data URL of a PNG, JPEG, WebP or SVG, small. */
|
|
53
|
+
function isPicture(picture: unknown): picture is string;
|
|
47
54
|
/** `value` with `look`, or without any for one that is none. */
|
|
48
55
|
function withLook<T extends {
|
|
49
56
|
look?: string;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RelayIdentityUtil = exports.RelayKeys = void 0;
|
|
4
4
|
const relay_bytes_1 = require("./relay-bytes");
|
|
5
|
+
const relay_protocol_1 = require("./relay-protocol");
|
|
5
6
|
const encoder = new TextEncoder();
|
|
6
7
|
const decoder = new TextDecoder();
|
|
7
8
|
const subtle = () => globalThis.crypto.subtle;
|
|
@@ -99,6 +100,13 @@ var RelayIdentityUtil;
|
|
|
99
100
|
return typeof look === 'string' && /^[a-z][a-z0-9-]{0,31}$/.test(look);
|
|
100
101
|
}
|
|
101
102
|
RelayIdentityUtil.isLook = isLook;
|
|
103
|
+
/** Whether it is a picture as a Ta keeps it: a data URL of a PNG, JPEG, WebP or SVG, small. */
|
|
104
|
+
function isPicture(picture) {
|
|
105
|
+
return (typeof picture === 'string' &&
|
|
106
|
+
picture.length <= relay_protocol_1.RELAY_PICTURE_MAX_CHARS &&
|
|
107
|
+
/^data:image\/(png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/.test(picture));
|
|
108
|
+
}
|
|
109
|
+
RelayIdentityUtil.isPicture = isPicture;
|
|
102
110
|
/** `value` with `look`, or without any for one that is none. */
|
|
103
111
|
function withLook(value, look) {
|
|
104
112
|
const { look: _, ...rest } = value;
|
|
@@ -188,6 +188,13 @@ export declare const RELAY_HUB_MAX_KEYS = 4096;
|
|
|
188
188
|
export declare const RELAY_HUB_MAX_STATE: number;
|
|
189
189
|
/** Asks to join waiting for the owner, and for how long. */
|
|
190
190
|
export declare const RELAY_HUB_MAX_ASKS = 20;
|
|
191
|
+
/**
|
|
192
|
+
* The key of the state of a room a member keeps its picture under (RelayIdentity.picture), its member id after it: each
|
|
193
|
+
* member its own, in the rooms of friends the owner alone (RelayHubs.keepPicture).
|
|
194
|
+
*/
|
|
195
|
+
export declare const RELAY_PICTURE_KEY = "picture:";
|
|
196
|
+
/** Characters of a picture at most, as a data URL: a small square, a few of them in a room. */
|
|
197
|
+
export declare const RELAY_PICTURE_MAX_CHARS: number;
|
|
191
198
|
export declare const RELAY_HUB_ASK_DAYS = 7;
|
|
192
199
|
/** A room nobody used for so long is deleted. */
|
|
193
200
|
export declare const RELAY_HUB_IDLE_DAYS = 90;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RELAY_HUB_RATE = exports.RELAY_HUB_IDLE_DAYS = exports.RELAY_HUB_ASK_DAYS = exports.RELAY_HUB_MAX_ASKS = exports.RELAY_HUB_MAX_STATE = exports.RELAY_HUB_MAX_KEYS = exports.RELAY_HUB_MAX_VALUE = exports.RELAY_FRIENDS_MAX = exports.RELAY_INVITE_MAX_DAYS = exports.RELAY_ROOM_CAPACITY_MAX = exports.RELAY_ROOM_MAX_MEMBERS = exports.RELAY_HUB_MAX_MEMBERS = exports.RELAY_ROOM_PATH = exports.RELAY_HUB_PATH = exports.RELAY_PROOF = exports.RELAY_STALE_MS = exports.RELAY_PING_MS = exports.RELAY_PONG = exports.RELAY_PING = exports.RelayCloseCode = exports.RELAY_ID = exports.RELAY_BLOB_MAX_DAYS = exports.RELAY_CONTENT_MAX_BYTES = exports.RELAY_SHARE_DAYS = exports.RELAY_SHARE_CHUNK_BYTES = exports.RELAY_SHARE_MAX_BYTES = exports.RELAY_SHARE_PAGE = exports.RELAY_PAIR_PAGE = exports.RELAY_BLOB_PATH = exports.RELAY_VIEWER_HEADERS = exports.RELAY_FRAME_HEADER_CSP = exports.RELAY_FRAME_CSP = exports.RELAY_FRAME_PATH = exports.RELAY_CONTENT_PATH = exports.RELAY_SHARE_PATH = exports.RELAY_PAIR_PATH = exports.RELAY_CONNECT_PATH = exports.RELAY_HOST_PATH = exports.RELAY_DEFAULT_URL = void 0;
|
|
3
|
+
exports.RELAY_HUB_RATE = exports.RELAY_HUB_IDLE_DAYS = exports.RELAY_HUB_ASK_DAYS = exports.RELAY_PICTURE_MAX_CHARS = exports.RELAY_PICTURE_KEY = exports.RELAY_HUB_MAX_ASKS = exports.RELAY_HUB_MAX_STATE = exports.RELAY_HUB_MAX_KEYS = exports.RELAY_HUB_MAX_VALUE = exports.RELAY_FRIENDS_MAX = exports.RELAY_INVITE_MAX_DAYS = exports.RELAY_ROOM_CAPACITY_MAX = exports.RELAY_ROOM_MAX_MEMBERS = exports.RELAY_HUB_MAX_MEMBERS = exports.RELAY_ROOM_PATH = exports.RELAY_HUB_PATH = exports.RELAY_PROOF = exports.RELAY_STALE_MS = exports.RELAY_PING_MS = exports.RELAY_PONG = exports.RELAY_PING = exports.RelayCloseCode = exports.RELAY_ID = exports.RELAY_BLOB_MAX_DAYS = exports.RELAY_CONTENT_MAX_BYTES = exports.RELAY_SHARE_DAYS = exports.RELAY_SHARE_CHUNK_BYTES = exports.RELAY_SHARE_MAX_BYTES = exports.RELAY_SHARE_PAGE = exports.RELAY_PAIR_PAGE = exports.RELAY_BLOB_PATH = exports.RELAY_VIEWER_HEADERS = exports.RELAY_FRAME_HEADER_CSP = exports.RELAY_FRAME_CSP = exports.RELAY_FRAME_PATH = exports.RELAY_CONTENT_PATH = exports.RELAY_SHARE_PATH = exports.RELAY_PAIR_PATH = exports.RELAY_CONNECT_PATH = exports.RELAY_HOST_PATH = exports.RELAY_DEFAULT_URL = void 0;
|
|
4
4
|
exports.relayDefaultUrl = relayDefaultUrl;
|
|
5
5
|
/** The relay of Ta, on Cloudflare Workers (apps/ta-relay), when the user names none. */
|
|
6
6
|
exports.RELAY_DEFAULT_URL = 'https://relay.cellbang.com';
|
|
@@ -125,6 +125,13 @@ exports.RELAY_HUB_MAX_KEYS = 4096;
|
|
|
125
125
|
exports.RELAY_HUB_MAX_STATE = 3 * 1024 * 1024;
|
|
126
126
|
/** Asks to join waiting for the owner, and for how long. */
|
|
127
127
|
exports.RELAY_HUB_MAX_ASKS = 20;
|
|
128
|
+
/**
|
|
129
|
+
* The key of the state of a room a member keeps its picture under (RelayIdentity.picture), its member id after it: each
|
|
130
|
+
* member its own, in the rooms of friends the owner alone (RelayHubs.keepPicture).
|
|
131
|
+
*/
|
|
132
|
+
exports.RELAY_PICTURE_KEY = 'picture:';
|
|
133
|
+
/** Characters of a picture at most, as a data URL: a small square, a few of them in a room. */
|
|
134
|
+
exports.RELAY_PICTURE_MAX_CHARS = 16 * 1024;
|
|
128
135
|
exports.RELAY_HUB_ASK_DAYS = 7;
|
|
129
136
|
/** A room nobody used for so long is deleted. */
|
|
130
137
|
exports.RELAY_HUB_IDLE_DAYS = 90;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-relay",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.20.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.20.0",
|
|
34
|
+
"@celljs/ta-protocol": "4.20.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|